1 /* +-----------------------------------------------------------------------------+
2 * OpenEMR - Open Source Electronic Medical Record
3 * Copyright (C) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * @author Jacob T.Paul <jacob@zhservices.com>
18 * @author Basil P T <basil@zhservices.com>
19 * +------------------------------------------------------------------------------+
23 var selected_user = '';
24 var selected_component = '';
25 var allowed_array = new Array();
26 var denied_array = new Array();
29 function createtree() {
30 $("#td_componets,#td_users,#td_allowed_users,#td_denied_users").treeview({
33 control: "#control_div"
37 $(document).mouseup(function(e) {
38 var container = $(".popup_items");
39 if (!container.is(e.target) && container.has(e.target).length === 0) {
40 $(".popup_items").css("display", "none");
44 $(window).load(function() {
45 $(".scrollable").customScrollbar();
48 $(document).one("mouseover", function() {
49 $(".scrollable").customScrollbar("resize");
50 $("#expand_tree").click();
53 $(document).ready(function() {
54 $(".popup_items").draggable();
56 $(".draggable2").draggable({
57 containment: "#outer_table",
61 selected_user = this.id;
64 $(".draggable3").draggable({
65 containment: "#outer_table",
69 selected_user = this.id;
72 $(".draggable4").draggable({
73 containment: "#outer_table",
77 selected_user = this.id;
80 $(".delete_droppable").droppable({
81 accept: ".draggable3,.draggable4",
82 activeClass: "deleted",
83 over: function(event, ui) {
84 $(".delete_droppable").addClass("red");
85 setTimeout(function() {
86 $(".delete_droppable").removeClass("red");
89 drop: function(event, ui) {
90 var user_delete = false;
91 var invalid_group = false;
92 var arr_id = selected_user.split("-");
94 if($("#" + selected_user).css("opacity") == "1"){
95 $("#li_" + selected_user).css("display", "none");
96 $("#li_" + selected_user).find('li').css("display", "none");
105 if (selected_user.indexOf("user_group_allowed_") != -1) {
106 if (arr_id[1] == 0 && !user_delete && !invalid_group) {
107 index = allowed_array.indexOf("li_" + selected_user);
108 if (index != -1) allowed_array.splice(index, 1);
110 $("#li_" + selected_user).find("li").each(function() {
111 index_1 = allowed_array.indexOf($(this).attr("id"));
112 if (index_1 != -1) allowed_array.splice(index_1, 1);
118 } else if (selected_user.indexOf("user_group_denied_") != -1) {
119 if (arr_id[1] == 0 && !user_delete && !invalid_group) {
120 index = denied_array.indexOf("li_" + selected_user);
121 if (index != -1) denied_array.splice(index, 1);
123 $("#li_" + selected_user).find("li").each(function() {
124 index_1 = denied_array.indexOf($(this).attr("id"));
125 if (index_1 != -1) denied_array.splice(index_1, 1);
131 var resultTranslated = js_xl('User Cannot be Deleted');
132 $("#messages").html(resultTranslated.msg);
133 setTimeout(function() {
134 $("#messages").html("");
136 } else if(invalid_group) {
137 var resultTranslated = js_xl('Please Select an Active Group');
138 $("#messages").html(resultTranslated.msg);
139 setTimeout(function() {
140 $("#messages").html("");
148 $(".droppableAllowed").droppable({
149 accept: ".draggable2,.draggable4",
151 var dragged_from_denied = false;
152 if (selected_user.indexOf("user_group_denied_") != -1) {
153 dragged_from_denied = true;
154 new_id = selected_user.replace("user_group_denied_", "user_group_allowed_");
155 denied_id = selected_user;
156 var arr_id = selected_user.split("-");
157 if (arr_id[1] != 0) {
159 $($($("#li_" + selected_user).parent().get(0)).parent().get(0)).find("li").each(function() {
160 if ($(this).css("display") == "list-item") li_cout++;
162 $("#li_" + selected_user).css("display", "none");
165 new_id = selected_user.replace("user_group_", "user_group_allowed_");
166 denied_id = selected_user.replace("user_group_", "user_group_denied_");
168 target_visibility = $("#li_" + new_id).css("display");
169 $("#li_" + new_id).css("display", "");
170 var arr_id = selected_user.split("-");
171 if (arr_id[1] == 0) {
172 // Add to array -- allowed
173 if (dragged_from_denied) {
174 source_opacity = $("#"+selected_user).css("opacity");
175 target_opacity = $("#" + new_id).css("opacity");
176 new_opacity = (target_opacity == "1" && target_visibility != "none") ? "1" : source_opacity;
177 $("#" + new_id).css("opacity",new_opacity);
178 index = denied_array.indexOf("li_" + selected_user);
180 if (allowed_array.indexOf(new_id) == -1) allowed_array.push("li_" + new_id);
181 $("#li_" + new_id).find("li").each(function() {
182 child_id = $(this).attr("id");
183 index = allowed_array.indexOf(child_id);
184 if (index != -1) allowed_array.splice(index, 1);
187 if (allowed_array.indexOf(new_id) == -1) {
188 $("#li_" + selected_user).find("li").each(function() {
189 if ($(this).css("display") == "list-item") {
190 id = $(this).attr("id").replace("user_group_denied_", "user_group_allowed_");
191 if (allowed_array.indexOf(id) == -1) {
192 allowed_array.push(id);
199 if (allowed_array.indexOf(new_id) == -1) allowed_array.push("li_" + new_id);
200 $("#li_" + new_id).find("li").each(function() {
201 child_id = $(this).attr("id");
202 index = allowed_array.indexOf(child_id);
203 if (index != -1) allowed_array.splice(index, 1);
207 // Remove From Denied Array
208 index = denied_array.indexOf("li_" + denied_id);
209 if (index != -1) denied_array.splice(index, 1);
210 parent_id = $($($("#li_" + denied_id).parent().get(0)).parent().get(0)).attr("id");
211 $("#li_" + denied_id).find("li").each(function() {
212 child_id = $(this).attr("id");
213 index = denied_array.indexOf(child_id);
214 if (index != -1) denied_array.splice(index, 1);
217 if (dragged_from_denied) {
218 index = denied_array.indexOf("li_" + selected_user);
219 if (index != -1) $("#li_" + new_id).find('li').css("display", "");
221 $("#li_" + selected_user).find("li").each(function() {
222 if ($(this).css("display") == "list-item") {
223 id = $(this).attr("id").replace("user_group_denied_", "user_group_allowed_");
224 $("#" + id).css("display", "");
225 $("#" + id).find("div:eq(1)").css("opacity", "1");
230 $("#li_" + new_id).find('li').css("display", "");
231 $("#li_" + new_id).find("div:eq(1)").css("opacity", "1");
233 $("#li_" + denied_id).find('li').css("display", "none");
234 $("#li_" + denied_id).css("display", "none");
237 // Add to array -- allowed
238 parent_id = $($($("#li_" + new_id).parent().get(0)).parent().get(0)).attr("id");
239 if (allowed_array.indexOf("li_" + new_id) == -1 && allowed_array.indexOf(parent_id) == -1) allowed_array.push("li_" + new_id);
241 $($($("#li_" + new_id).parent().get(0)).parent().get(0)).css("display", "");
242 if (new_id.substr(-2) != "-0" && (allowed_array.indexOf(parent_id) == -1 || !dragged_from_denied)) {
243 $($($("#li_" + new_id).parent().get(0)).parent().get(0)).find("div:eq(1)").css("opacity", "0.5");
246 $("#li_" + denied_id).css("display", "none");
247 $($($("#li_" + denied_id).parent().get(0)).parent().get(0)).find("li").each(function() {
248 if ($(this).css("display") == "list-item") li_cout++;
250 if (li_cout == 0 && $("#"+parent_id.replace("li_","").replace("allowed","denied")).css("opacity") != "1") {
251 $($($("#li_" + denied_id).parent().get(0)).parent().get(0)).css("display", "none");
254 index = denied_array.indexOf("li_" + denied_id);
255 if (index != -1) denied_array.splice(index, 1);
260 $(".droppableDenied").droppable({
261 accept: ".draggable2,.draggable3",
263 var dragged_from_allowed = false;
264 if (selected_user.indexOf("user_group_allowed_") != -1) {
265 dragged_from_allowed = true;
266 new_id = selected_user.replace("user_group_allowed_", "user_group_denied_");
267 denied_id = selected_user;
268 var arr_id = selected_user.split("-");
269 if (arr_id[1] != 0) {
271 $($($("#li_" + selected_user).parent().get(0)).parent().get(0)).find("li").each(function() {
272 if ($(this).css("display") == "list-item") li_cout++;
274 $("#li_" + selected_user).css("display", "none");
277 new_id = selected_user.replace("user_group_", "user_group_denied_");
278 denied_id = selected_user.replace("user_group_", "user_group_allowed_");
281 target_visibility = $("#li_" + new_id).css("display");
282 $("#li_" + new_id).css("display", "");
283 var arr_id = selected_user.split("-");
284 if (arr_id[1] == 0) {
285 source_opacity = $("#"+selected_user).css("opacity");
286 target_opacity = $("#" + new_id).css("opacity");
287 new_opacity = (target_opacity == "1" && target_visibility != "none") ? "1" : source_opacity;
288 $("#" + new_id).css("opacity",new_opacity);
289 // Add to array -- denied
290 if (dragged_from_allowed) {
291 index = allowed_array.indexOf("li_" + selected_user);
293 if (denied_array.indexOf(new_id) == -1) denied_array.push("li_" + new_id);
294 $("#li_" + new_id).find("li").each(function() {
295 child_id = $(this).attr("id");
296 index = denied_array.indexOf(child_id);
297 if (index != -1) denied_array.splice(index, 1);
300 if (denied_array.indexOf(new_id) == -1) {
301 $("#li_" + selected_user).find("li").each(function() {
302 if ($(this).css("display") == "list-item") {
303 id = $(this).attr("id").replace("user_group_allowed_", "user_group_denied_");
304 if (denied_array.indexOf(id) == -1) {
305 denied_array.push(id);
312 if (denied_array.indexOf(new_id) == -1) denied_array.push("li_" + new_id);
313 $("#li_" + new_id).find("li").each(function() {
314 child_id = $(this).attr("id");
315 index = denied_array.indexOf(child_id);
316 if (index != -1) denied_array.splice(index, 1);
320 // Remove From Allowed Array
321 index = allowed_array.indexOf("li_" + denied_id);
322 if (index != -1) allowed_array.splice(index, 1);
323 parent_id = $($($("#li_" + denied_id).parent().get(0)).parent().get(0)).attr("id");
324 $("#li_" + denied_id).find("li").each(function() {
325 child_id = $(this).attr("id");
326 index = allowed_array.indexOf(child_id);
327 if (index != -1) allowed_array.splice(index, 1);
329 if (dragged_from_allowed) {
330 index = allowed_array.indexOf("li_" + selected_user);
331 if (index != -1) $("#li_" + new_id).find('li').css("display", "");
333 $("#li_" + selected_user).find("li").each(function() {
334 if ($(this).css("display") == "list-item") {
335 id = $(this).attr("id").replace("user_group_allowed_", "user_group_denied_");
336 $("#" + id).css("display", "");
337 $("#" + id).find("div:eq(1)").css("opacity", "1");
342 $("#li_" + new_id).find('li').css("display", "");
343 $("#li_" + new_id).find("div:eq(1)").css("opacity", "1");
345 $("#li_" + denied_id).find('li').css("display", "none");
346 $("#li_" + denied_id).css("display", "none");
350 // Add to array -- denied
351 parent_id = $($($("#li_" + new_id).parent().get(0)).parent().get(0)).attr("id");
352 if (denied_array.indexOf("li_" + new_id) == -1 && denied_array.indexOf(parent_id) == -1) denied_array.push("li_" + new_id);
354 $($($("#li_" + new_id).parent().get(0)).parent().get(0)).css("display", "");
355 if (new_id.substr(-2) != "-0" && (denied_array.indexOf(parent_id) == -1 || !dragged_from_allowed)) {
356 $($($("#li_" + new_id).parent().get(0)).parent().get(0)).find("div:eq(1)").css("opacity", "0.5");
358 $("#li_" + denied_id).css("display", "none");
361 $($($("#li_" + denied_id).parent().get(0)).parent().get(0)).find("li").each(function() {
362 if ($(this).css("display") == "list-item") li_cout++;
364 if (li_cout == 0 && $("#"+parent_id.replace("li_","").replace("denied","allowed")).css("opacity") != "1") {
365 $($($("#li_" + denied_id).parent().get(0)).parent().get(0)).css("display", "none");
368 index = allowed_array.indexOf("li_" + denied_id);
369 if (index != -1) allowed_array.splice(index, 1);
374 $(".module_check").click(function() {
375 var clicked_id = $(this).attr("id");
376 var clicked_arr = clicked_id.split("_");
377 if ($(this).is(":checked"))
378 $(".group_" + clicked_arr[1]).attr("checked", true);
380 $(".group_" + clicked_arr[1]).removeAttr("checked");
383 $(".component_check").click(function() {
388 function selectThis(id) {
389 $(".selected_componet").removeClass("selected_componet");
390 $("#" + id).addClass("selected_componet");
391 selected_component = id;
395 if (selected_component == '') {
396 var resultTranslated = js_xl('Select a Component');
397 alert(resultTranslated.msg);
400 $(".scrollable").customScrollbar("resize");
401 var selected_module = selected_component;
402 var allowed_users = JSON.stringify(allowed_array);
403 var denied_users = JSON.stringify(denied_array);
409 ajax_mode: 'save_acl',
410 selected_module: selected_module,
411 allowed_users: allowed_users,
412 denied_users: denied_users
415 success: function(thedata) {
416 var resultTranslated = js_xl('ACL Updated Successfully');
417 $("#messages").html(resultTranslated.msg);
418 setTimeout(function() {
419 $("#messages").html("");
433 ajax_mode: 'rebuild',
434 selected_module: selected_component,
437 success: function(thedata) {
438 $(".class_li").css("display", "none");
439 obj = JSON.parse(thedata);
442 for (var index in obj['group_allowed']) {
443 $("#li_user_group_allowed_" + obj['group_allowed'][index] + "-0").css("display", "");
444 $("#li_user_group_allowed_" + obj['group_allowed'][index] + "-0").find("li").css("display", "");
445 allowed_array.push("li_user_group_allowed_" + obj['group_allowed'][index] + "-0");
449 for (var index in obj['group_denied']) {
450 $("#li_user_group_denied_" + obj['group_denied'][index] + "-0").css("display", "");
451 $("#li_user_group_denied_" + obj['group_denied'][index] + "-0").find("li").css("display", "");
452 denied_array.push("li_user_group_denied_" + obj['group_denied'][index] + "-0");
456 for (var index in obj['user_allowed']) {
457 if ($("#li_user_group_allowed_" + index + "-0").css("display") == "none") {
458 $("#li_user_group_allowed_" + index + "-0").css("display", "");
459 $("#li_user_group_allowed_" + index + "-0").find("div:eq(1)").css("opacity", "0.5");
461 for (var k in obj['user_allowed'][index]) {
462 $("#li_user_group_allowed_" + index + "-" + obj['user_allowed'][index][k]).css("display", "");
463 $("#li_user_group_denied_" + index + "-" + obj['user_allowed'][index][k]).css("display", "none");
464 allowed_array.push("li_user_group_allowed_" + index + "-" + obj['user_allowed'][index][k]);
468 for (var index in obj['user_denied']) {
469 if ($("#li_user_group_denied_" + index + "-0").css("display") == "none") {
470 $("#li_user_group_denied_" + index + "-0").find("div:eq(1)").css("opacity", "0.5");
471 $("#li_user_group_denied_" + index + "-0").css("display", "");
473 for (var k in obj['user_denied'][index]) {
474 $("#li_user_group_denied_" + index + "-" + obj['user_denied'][index][k]).css("display", "");
475 $("#li_user_group_allowed_" + index + "-" + obj['user_denied'][index][k]).css("display", "none");
476 denied_array.push("li_user_group_denied_" + index + "-" + obj['user_denied'][index][k]);
484 function saveGroupAcl() {
486 ACL_DATA['allowed'] = {};
487 ACL_DATA['denied'] = {};
489 $("#table_acl").find("input:checkbox").each(function() {
490 var id = $(this).attr("id");
491 id_arr = id.split("_");
493 if ($(this).is(":checked")) {
495 if (!ACL_DATA['allowed'][id_arr[0]]) ACL_DATA['allowed'][id_arr[0]] = {};
496 ACL_DATA['allowed'][id_arr[0]][i] = id_arr[1];
499 if (!ACL_DATA['denied'][id_arr[0]]) ACL_DATA['denied'][id_arr[0]] = {};
500 ACL_DATA['denied'][id_arr[0]][i] = id_arr[1];
508 ajax_mode: 'save_acl_advanced',
509 acl_data: JSON.stringify(ACL_DATA),
513 success: function(thedata) {
514 var resultTranslated = js_xl('ACL Updated Successfully');
515 $("#messages_div").html(resultTranslated.msg);
516 setTimeout(function() {
517 $("#messages_div").html("");
523 function addNewItem(section) {
524 $(".popup_items").css('display', 'none');
525 $("#add_new_" + section).slideDown();
528 function getSectionById(mod_id) {
529 $("#add_component_section_identifier").val("");
530 $("#add_component_section_name").val("");
532 $("#add_component_section_id").html("");
541 ajax_mode: 'get_sections_by_module',
545 success: function(thedata) {
546 obj = JSON.parse(thedata);
547 out = "<option value=''></option>";
548 for (var index in obj) {
549 out += "<option value='" + index + "'>" + obj[index] + "</option>";
551 $("#add_component_section_id").html(out);
556 function addSectionSave() {
557 mod_id = $("#add_component_mod_id").val();
558 parent_id = $("#add_component_section_id").val();
559 section_identifier = $("#add_component_section_identifier").val();
560 section_name = $("#add_component_section_name").val();
561 if ($.trim(section_identifier) == '' || $.trim(section_name) == '') {
562 var resultTranslated = js_xl('Section ID and Name Cannot be Empty');
563 alert(resultTranslated.msg);
571 ajax_mode: 'save_sections_by_module',
573 parent_id: parent_id,
574 section_identifier: section_identifier,
575 section_name: section_name,
578 success: function(thedata) {
579 var resultTranslated = js_xl('Section saved successfully');
580 $("#add_component_section_message").html(resultTranslated.msg);
581 setTimeout(function() {
582 $("#add_component_section_message").html("");