From 9b59894309bab703119532164c78aeabbb27ea51 Mon Sep 17 00:00:00 2001
From: ElenaMetelitsa <ami96@list.ru>
Date: Fri, 3 Jul 2015 13:17:10 +0300
Subject: [PATCH] Fixed bug with loading elements

---
 media/js/button_groups.js                     | 12 +++++++
 ~dev_rating/application/bootstrap.php         |  9 +++++-
 .../classes/Controller/StudyGroups.php        | 16 ++++++++++
 .../application/views/main_studygroups.twig   | 32 +++++++++++++++++++
 ~dev_rating/application/views/studygroups     |  7 ++++
 5 files changed, 75 insertions(+), 1 deletion(-)
 create mode 100644 media/js/button_groups.js
 create mode 100644 ~dev_rating/application/classes/Controller/StudyGroups.php
 create mode 100644 ~dev_rating/application/views/main_studygroups.twig
 create mode 100644 ~dev_rating/application/views/studygroups

diff --git a/media/js/button_groups.js b/media/js/button_groups.js
new file mode 100644
index 000000000..d229f996c
--- /dev/null
+++ b/media/js/button_groups.js
@@ -0,0 +1,12 @@
+$(function () {
+    var button = $('#button');
+    button.click(function () {
+        var num = ($('input').first().val());
+
+        // grade/~dev_rating
+        $.get(URLdir + '/studygroups/' + num, function (res) {
+            $('#container').html(res);
+        });
+    });
+
+});
\ No newline at end of file
diff --git a/~dev_rating/application/bootstrap.php b/~dev_rating/application/bootstrap.php
index 0e176b17d..9e2068010 100644
--- a/~dev_rating/application/bootstrap.php
+++ b/~dev_rating/application/bootstrap.php
@@ -288,4 +288,11 @@ Route::set('departments:main', 'departments(/<id>)', ['id' => '[0-9]+'])
     ]);
 
 // bars.com/departments
-// bars.com/departments/78
\ No newline at end of file
+// bars.com/departments/78
+
+Route::set('groups:main','studygroups(/<id>)', ['id' => '[0-9]+'])
+    ->defaults([
+        'controller' => 'StudyGroups',
+        'action'     => 'index',
+        'id'         => 1,
+    ]);
\ No newline at end of file
diff --git a/~dev_rating/application/classes/Controller/StudyGroups.php b/~dev_rating/application/classes/Controller/StudyGroups.php
new file mode 100644
index 000000000..aefd447e2
--- /dev/null
+++ b/~dev_rating/application/classes/Controller/StudyGroups.php
@@ -0,0 +1,16 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Controller_StudyGroups extends Controller
+{
+    public function action_index() {
+        $id = (int) $this->request->param('id');
+
+        $name = $this->request->is_ajax() ? 'studygroups' : 'main_studygroups';
+
+        $twig = Twig::factory($name, [
+            'Groups' => Model_Students::ofGroup($id, 2)
+        ]);
+
+        $this->response->body($twig);
+    }
+}
diff --git a/~dev_rating/application/views/main_studygroups.twig b/~dev_rating/application/views/main_studygroups.twig
new file mode 100644
index 000000000..40b28d58b
--- /dev/null
+++ b/~dev_rating/application/views/main_studygroups.twig
@@ -0,0 +1,32 @@
+<html>
+<head>
+    {{ HTML.script('static/js/libs/jquery-1.11.1.min.js') |raw }}
+    {{ HTML.script('static/js/button_groups.js')|raw }}
+    {{ HTML.script('static/js/config.js')|raw }}
+</head>
+<body>
+
+<p>РЎРїРёСЃРѕРє РіСЂСѓРїРї:</p>
+
+<div>
+    <select>
+        {% for g in Groups %}
+            {% if g.Name != '' %}
+                <option value="{{ g.ID }}">{{ g.Name }}</option>
+            {% endif %}
+        {% endfor %}
+    </select>
+</div>
+
+<div>
+    <ul>
+        {% for s in Students %}
+            {% if s.Name != '' %}
+                <li value="{{ s.ID }}">{{ s.Name }}</li>
+            {% endif %}
+        {% endfor %}
+    </ul>
+</div>
+
+</body>
+</html>
diff --git a/~dev_rating/application/views/studygroups b/~dev_rating/application/views/studygroups
new file mode 100644
index 000000000..32e3d0f1d
--- /dev/null
+++ b/~dev_rating/application/views/studygroups
@@ -0,0 +1,7 @@
+<select>
+    {% for s in Students %}
+        {% if s.Name != '' %}
+            <option value="{{ s.ID }}">{{ s.Name }}</option>
+        {% endif %}
+    {% endfor %}
+</select>
\ No newline at end of file
-- 
GitLab