From dcdc615d69437e25c6899283189b78913e4557d6 Mon Sep 17 00:00:00 2001 From: ElenaMetelitsa <ami96@list.ru> Date: Fri, 3 Jul 2015 10:56:29 +0300 Subject: [PATCH] Done task #29 Add page for departments --- media/css/test.css | 3 ++ media/js/button.js | 13 ++++++ media/js/testik.js | 11 +++++ ~dev_rating/application/bootstrap.php | 9 ++++ .../classes/Controller/Departments.php | 16 +++++++ .../application/views/departments.twig | 7 +++ .../application/views/main_departments.twig | 45 +++++++++++++++++++ 7 files changed, 104 insertions(+) create mode 100644 media/css/test.css create mode 100644 media/js/button.js create mode 100644 media/js/testik.js create mode 100644 ~dev_rating/application/classes/Controller/Departments.php create mode 100644 ~dev_rating/application/views/departments.twig create mode 100644 ~dev_rating/application/views/main_departments.twig diff --git a/media/css/test.css b/media/css/test.css new file mode 100644 index 000000000..3ffd17aeb --- /dev/null +++ b/media/css/test.css @@ -0,0 +1,3 @@ +p{ + color: #0000cc; +} \ No newline at end of file diff --git a/media/js/button.js b/media/js/button.js new file mode 100644 index 000000000..734184e39 --- /dev/null +++ b/media/js/button.js @@ -0,0 +1,13 @@ + +$(function () { + var button = $('#button'); + button.click(function () { + var num = ($('input').first().val()); + + // grade/~dev_rating + $.get(URLdir + '/departments/' + num, function (res) { + $('#container').html(res); + }); + }); + +}); \ No newline at end of file diff --git a/media/js/testik.js b/media/js/testik.js new file mode 100644 index 000000000..5badcd440 --- /dev/null +++ b/media/js/testik.js @@ -0,0 +1,11 @@ +/** + * Created by ami96_000 on 02.07.2015. + */ +$(function(){ + var faculty=$('#faculty'); + faculty.change(function () { + alert( + faculty.find('option:selected').val()); + }); + +}); \ No newline at end of file diff --git a/~dev_rating/application/bootstrap.php b/~dev_rating/application/bootstrap.php index f4552773a..0e176b17d 100644 --- a/~dev_rating/application/bootstrap.php +++ b/~dev_rating/application/bootstrap.php @@ -280,3 +280,12 @@ Route::set('javaSessionProvider', 'java_authentication') 'controller' => 'JavaAuthentication', 'action' => 'authentication' ]); + +Route::set('departments:main', 'departments(/<id>)', ['id' => '[0-9]+']) + ->defaults([ + 'controller' => 'Departments', // classes/Controller/Departments.php + 'id' => 1, + ]); + +// bars.com/departments +// bars.com/departments/78 \ No newline at end of file diff --git a/~dev_rating/application/classes/Controller/Departments.php b/~dev_rating/application/classes/Controller/Departments.php new file mode 100644 index 000000000..043968fa9 --- /dev/null +++ b/~dev_rating/application/classes/Controller/Departments.php @@ -0,0 +1,16 @@ +<?php defined('SYSPATH') or die('No direct script access.'); + +class Controller_Departments extends Controller +{ + public function action_index() { + $id = (int) $this->request->param('id'); + + $name = $this->request->is_ajax() ? 'departments' : 'main_departments'; + + $twig = Twig::factory($name, [ + 'Departments' => Model_Faculty::with($id)->getDepartments() + ]); + + $this->response->body($twig); + } +} diff --git a/~dev_rating/application/views/departments.twig b/~dev_rating/application/views/departments.twig new file mode 100644 index 000000000..c2fa90483 --- /dev/null +++ b/~dev_rating/application/views/departments.twig @@ -0,0 +1,7 @@ +<ul> + {% for d in Departments %} + {% if d.Name != '' %} + <li value="{{ d.ID }}">{{ d.Name }}</li> + {% endif %} + {% endfor %} +</ul> \ No newline at end of file diff --git a/~dev_rating/application/views/main_departments.twig b/~dev_rating/application/views/main_departments.twig new file mode 100644 index 000000000..253fc2894 --- /dev/null +++ b/~dev_rating/application/views/main_departments.twig @@ -0,0 +1,45 @@ +<html> +<head> + {{ HTML.script('static/js/libs/jquery-1.11.1.min.js') |raw }} + {{ HTML.script('static/js/button.js')|raw }} + {{ HTML.script('static/js/config.js')|raw }} +</head> +<body> + <p>Введите id факультета:</p> + + <input type="text" size="3" name="num" min="1" max="10" value="0"> + <button id="button">OK</button> + + <p>Список кафедр:</p> + + <div id="container"> + <ul> + {% for d in Departments %} + {% if d.Name != '' %} + <li value="{{ d.ID }}">{{ d.Name }}</li> + {% endif %} + {% endfor %} + </ul> + </div> +</body> +</html> + + +{#<select> + {% for f in Faculties %} + <option value="{{ f.ID }}"> + {{ f.Name }} + </option> + {% endfor %} +</select>#} +{# <select id="faculty"> + <option value="1">мимими</option> + <option value="2">урурру</option> + <option value="3" class="mytext">:3</option> + <option>ROOOOOAAAR</option> + </select> + +<p> + meow +</p> +<p class="mytext">ROAR</p>#} \ No newline at end of file -- GitLab