| 1 | {% extends "layout_admin.html" %} |
|---|
| 2 | {% comment %} |
|---|
| 3 | # Copyright 2008 Domogik project |
|---|
| 4 | |
|---|
| 5 | # This file is part of Domogik. |
|---|
| 6 | # Domogik is free software: you can redistribute it and/or modify |
|---|
| 7 | # it under the terms of the GNU General Public License as published by |
|---|
| 8 | # the Free Software Foundation, either version 3 of the License, or |
|---|
| 9 | # (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | # Domogik is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | # GNU General Public License for more details. |
|---|
| 15 | |
|---|
| 16 | # You should have received a copy of the GNU General Public License |
|---|
| 17 | # along with Domogik. If not, see |
|---|
| 18 | <http://www.gnu.org/licenses/> |
|---|
| 19 | . |
|---|
| 20 | |
|---|
| 21 | # Author : Cédric Trévisan <cedric@domogik.org> {% endcomment %} |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | {% load i18n %} |
|---|
| 25 | {% block css %} |
|---|
| 26 | <link href="/design/{{ request.session.user.skin_used|default:'skins/default' }}/css/page-admin-organization.css" rel="stylesheet" type="text/css" /> |
|---|
| 27 | {% endblock %} |
|---|
| 28 | {% block js_include %} |
|---|
| 29 | {% endblock %} |
|---|
| 30 | {% block js_script %} |
|---|
| 31 | $(function(){ |
|---|
| 32 | // Accordion |
|---|
| 33 | $("#nav2").accordion({ autoHeight: false, header: ".subnav2", active:0}); |
|---|
| 34 | |
|---|
| 35 | $("#tabs").tabs().domogik_tabs({ |
|---|
| 36 | addTitle: "{% trans "Add new room" %}", |
|---|
| 37 | addId: "addDialogButton" |
|---|
| 38 | }); |
|---|
| 39 | |
|---|
| 40 | /* Tooltips */ |
|---|
| 41 | $('.buttonside[title], .add').tooltip_left(); |
|---|
| 42 | $('#help_dragdrop').tooltip_content_right({ |
|---|
| 43 | content: '<h3>Mouse usage</h3><h3>Keyboard usage</h3><ul><li>Use the <kbd>Tab</kbd> to move to the room you want to organize.</li><li>Select the room you want to move with the <kbd>Spacebar</kbd>.</li><li>Use the <kbd>Up</kbd> and <kbd>Down</kbd> cursor keys to select a area in the context menu.</li><li>Press <kbd>Enter</kbd> to move the room to the area.</li></ul>' |
|---|
| 44 | }); |
|---|
| 45 | |
|---|
| 46 | /* Drag & Drop */ |
|---|
| 47 | $('#dragdroprooms').dragdrop({ |
|---|
| 48 | dropcallback: function(self, element, target) { |
|---|
| 49 | getREST('/base/room/update/id/' + element + '/area_id/' + target, |
|---|
| 50 | function(data) { |
|---|
| 51 | var status = (data.status).toLowerCase(); |
|---|
| 52 | if (status == 'ok') { |
|---|
| 53 | self.valid(); |
|---|
| 54 | } else { |
|---|
| 55 | self.cancel(); |
|---|
| 56 | display_message('error', data.description); |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | ) |
|---|
| 60 | } |
|---|
| 61 | }); |
|---|
| 62 | |
|---|
| 63 | /* Dialogs */ |
|---|
| 64 | $('#delete_confirmation').dialog_confirmation({ |
|---|
| 65 | title: "{% trans 'Delete' %}", |
|---|
| 66 | content: "{% trans "Please confirm to delete" %}" |
|---|
| 67 | }); |
|---|
| 68 | |
|---|
| 69 | $('#roomdialog').dialog_form({ |
|---|
| 70 | tips: "{% trans "All fields are required." %}", |
|---|
| 71 | tipsid: 'tipsRoom', |
|---|
| 72 | fields: [ |
|---|
| 73 | {name : 'roomname', type:'text', label:'Name', required: true, option: {min: 1, max: 80}}, |
|---|
| 74 | {name : 'roomdescription', type:'text', label:'Description', required: true, option: {min: 1, max: 80}} |
|---|
| 75 | ] |
|---|
| 76 | }); |
|---|
| 77 | |
|---|
| 78 | /* Add a function to create an room */ |
|---|
| 79 | $('#roomdialog').dialog_form('addbutton', { |
|---|
| 80 | title: "{% trans "Create new room" %}", |
|---|
| 81 | button: "#addDialogButton", |
|---|
| 82 | onok: function(values) { |
|---|
| 83 | // Submit form |
|---|
| 84 | getREST('/base/room/add/name/' + values.roomname + '/description/' + values.roomdescription, |
|---|
| 85 | function(data) { |
|---|
| 86 | var status = (data.status).toLowerCase(); |
|---|
| 87 | if (status == 'ok') { |
|---|
| 88 | $.reloadPage({'status': 'ok', 'msg': '{% trans "Success" %} : {% trans "New room added" %} \'' + data.room[0].name + '\''}); |
|---|
| 89 | } else { |
|---|
| 90 | $.reloadPage({'status': 'error', 'msg': '{% trans "Error" %} : {% trans "Room not created" %} (' + data.description + ')'}); |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | ); |
|---|
| 94 | } |
|---|
| 95 | }); |
|---|
| 96 | }); |
|---|
| 97 | |
|---|
| 98 | {% endblock %} |
|---|
| 99 | |
|---|
| 100 | {% block title %}{% trans page_title %}{% endblock %} |
|---|
| 101 | |
|---|
| 102 | {% block banner %} |
|---|
| 103 | <div class="section"> |
|---|
| 104 | <h1 class="ident"><span class="title">{% trans "Rooms" %}</span></h1> |
|---|
| 105 | {% ifnotequal status "" %} |
|---|
| 106 | <div id='messages' class='{{status}}'>{{msg}}</div> |
|---|
| 107 | {% endifnotequal %} |
|---|
| 108 | <ul class="actions"></ul> |
|---|
| 109 | </div> |
|---|
| 110 | {% endblock %} |
|---|
| 111 | |
|---|
| 112 | {% block right %} |
|---|
| 113 | <div class="subsection"> |
|---|
| 114 | <h2>{% trans "Rooms list" %}</h2> |
|---|
| 115 | <div id="tabs"> |
|---|
| 116 | {% spaceless %} |
|---|
| 117 | <ul> |
|---|
| 118 | {% for room in rooms_list %} |
|---|
| 119 | <li><a id="tab{{ room.id }}" href="#element{{ room.id }}" class="icon16-room-{{ room.config.icon }}">{{ room.name }}</a></li> |
|---|
| 120 | {% endfor %} |
|---|
| 121 | </ul> |
|---|
| 122 | {% endspaceless %} |
|---|
| 123 | {% for room in rooms_list %} |
|---|
| 124 | <div id="element{{ room.id }}" class="tabelement"> |
|---|
| 125 | <script type="text/javascript"> |
|---|
| 126 | // <![CDATA[ |
|---|
| 127 | $(function(){ |
|---|
| 128 | /* Add a function to delete the current room */ |
|---|
| 129 | $('#delete_confirmation').dialog_confirmation('addbutton', { |
|---|
| 130 | button: "#del{{ room.id }}", |
|---|
| 131 | name: "'{{ room.name }}'", |
|---|
| 132 | onok: function() { |
|---|
| 133 | getREST('/base/room/del/{{ room.id }}', |
|---|
| 134 | function(data) { |
|---|
| 135 | var status = (data.status).toLowerCase(); |
|---|
| 136 | if (status == 'ok') { |
|---|
| 137 | $.reloadPage({'status': 'ok', 'msg': '{% trans "Success" %} : {% trans "Room" %} \'' + data.room[0].name + '\' {% trans "successfully deleted" %}'}); |
|---|
| 138 | } else { |
|---|
| 139 | $.reloadPage({'status': 'error', 'msg': '{% trans "Error" %} : {% trans "Room not deleted" %} (' + data.description + ')'}); |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | ); |
|---|
| 143 | } |
|---|
| 144 | }); |
|---|
| 145 | |
|---|
| 146 | $('#icon{{ room.id }}').editable_icon({ |
|---|
| 147 | type: "room", |
|---|
| 148 | list: room_icons, |
|---|
| 149 | icon: "{{ room.config.icon }}", |
|---|
| 150 | validCallback: function(self, icon) { |
|---|
| 151 | $('#icon{{ room.id }}').processing('start'); |
|---|
| 152 | getREST('/base/ui_config/set/name/room/reference/{{ room.id }}/key/icon/value/' + icon, |
|---|
| 153 | function(data) { |
|---|
| 154 | $('#icon{{ room.id }}').processing('stop'); |
|---|
| 155 | var status = (data.status).toLowerCase(); |
|---|
| 156 | if (status == 'ok') { |
|---|
| 157 | self.valid(); |
|---|
| 158 | $("#tab{{ room.id }}").removeClass(); |
|---|
| 159 | $("#tab{{ room.id }}").addClass("icon16-room-" + icon); |
|---|
| 160 | } else { |
|---|
| 161 | self.cancel(); |
|---|
| 162 | display_message('error', data.description); |
|---|
| 163 | } |
|---|
| 164 | } |
|---|
| 165 | ) |
|---|
| 166 | } |
|---|
| 167 | }); |
|---|
| 168 | |
|---|
| 169 | $( "#icon{{ room.id }}").processing(); |
|---|
| 170 | |
|---|
| 171 | /* Add a function to update an room */ |
|---|
| 172 | $('#roomdialog').dialog_form('updbutton', { |
|---|
| 173 | title: "{% trans "Update room" %} '{{ room.name }}'", |
|---|
| 174 | button: "#update{{ room.id }}", |
|---|
| 175 | values: {roomname : '{{ room.name }}', roomdescription : '{{ room.description }}'}, |
|---|
| 176 | onok: function(values) { |
|---|
| 177 | // Submit form |
|---|
| 178 | getREST('/base/room/update/id/' + {{ area.id }} + '/name/' + values.areaname + '/description/' + values.areadescription, |
|---|
| 179 | function(data) { |
|---|
| 180 | var status = (data.status).toLowerCase(); |
|---|
| 181 | if (status == 'ok') { |
|---|
| 182 | $.reloadPage({'status': 'ok', 'msg': '{% trans "Success" %} : {% trans "Room" %} \'' + data.room[0].name + '\' {% trans "successfully updated" %}'}); |
|---|
| 183 | } else { |
|---|
| 184 | $.reloadPage({'status': 'error', 'msg': '{% trans "Error" %} : {% trans "Room not updated" %} (' + data.description + ')'}); |
|---|
| 185 | } |
|---|
| 186 | } |
|---|
| 187 | ); |
|---|
| 188 | } |
|---|
| 189 | }); |
|---|
| 190 | |
|---|
| 191 | }); |
|---|
| 192 | // ]]> |
|---|
| 193 | </script> |
|---|
| 194 | <ul class="actions"> |
|---|
| 195 | <li><button id='del{{ room.id }}' class='icon16-action-del buttonside' title="{% trans "Delete" %} '{{ room.name }}'"><span class='offscreen'>{% trans "Delete" %} {{ room.name }}</span></button></li> |
|---|
| 196 | <li><button id="update{{ room.id }}" class="icon16-action-update buttonside" title="{% trans "Modify" %} '{{ room.name }}'"><span class='offscreen'>{% trans "Modify" %} {{ room.name }}</span></button></li> |
|---|
| 197 | </ul> |
|---|
| 198 | <div class="content"> |
|---|
| 199 | <div id="icon{{ room.id }}"></div> |
|---|
| 200 | <h2 id="zone{{ room.id }}h">{{ room.name }}</h2> |
|---|
| 201 | <p>{{ room.description }}</p> |
|---|
| 202 | |
|---|
| 203 | </div> |
|---|
| 204 | </div> |
|---|
| 205 | {% endfor %} |
|---|
| 206 | </div> |
|---|
| 207 | </div> |
|---|
| 208 | <div id="roomdialog"></div> |
|---|
| 209 | <div id="delete_confirmation"></div> |
|---|
| 210 | |
|---|
| 211 | <div class="subsection" id="dragdroprooms"> |
|---|
| 212 | <h2 class='help' id='help_dragdrop'>{% trans "Rooms organisation" %} <span class='offscreen'>{% trans "Drag & Drop instructions" %}</span></h2> |
|---|
| 213 | <fieldset class="targetdrop"> |
|---|
| 214 | <legend class="choice">{% trans "Unattributed rooms" %}</legend> |
|---|
| 215 | <ul class="draggables" value="None"> |
|---|
| 216 | {% for room in unattribued_rooms %} |
|---|
| 217 | <li class="draggable icon32-room-{{ room.config.icon }}" value="{{ room.id }}">{{ room.name }}<span class="description">{{ room.description }}</span></li> |
|---|
| 218 | {% empty %} |
|---|
| 219 | <li class="empty">{% trans "Empty" %}</li> |
|---|
| 220 | {% endfor %} |
|---|
| 221 | </ul> |
|---|
| 222 | </fieldset> |
|---|
| 223 | {% for area in areas_list %} |
|---|
| 224 | <fieldset class="targetdrop"> |
|---|
| 225 | <legend class="choice icon16-area-{{ area.config.icon }}">{{ area.name }}</legend> |
|---|
| 226 | <ul class="draggables" value='{{ area.id }}'> |
|---|
| 227 | {% for room in area.room %} |
|---|
| 228 | <li class="draggable icon32-room-{{ room.config.icon }}" value="{{ room.id }}">{{ room.name }}<span class="description">{{ room.description }}</span></li> |
|---|
| 229 | {% empty %} |
|---|
| 230 | <li class="empty">{% trans "Empty" %}</li> |
|---|
| 231 | {% endfor %} |
|---|
| 232 | </ul> |
|---|
| 233 | </fieldset> |
|---|
| 234 | {% endfor %} |
|---|
| 235 | </div> |
|---|
| 236 | {% endblock %} |
|---|