Best JavaScript code snippet using qawolf
operator.js
Source:operator.js
1"use strict";2//#region Globals3let cookie = undefined;4let socket = undefined;5let discord_users = undefined;6//#endregion7function load_discord_user_details(details = undefined) {8 const operator_area = document.getElementById("operator-area");9 const operator_body = operator_area.getElementsByClassName("operator-body")[0];10 while (operator_body.lastChild) {11 operator_body.removeChild(operator_body.lastChild);12 }13 // #region Access Rights14 const access_rights_header = document.createElement("div");15 access_rights_header.className = "discord-user-header";16 access_rights_header.style.marginTop = "10px";17 access_rights_header.style.marginBottom = "5px";18 access_rights_header.style.background = "#333333";19 access_rights_header.innerHTML = "Access Rights";20 operator_body.appendChild(access_rights_header);21 // #endregion22 // #region Dashboard (View)23 const access_right_1 = document.createElement("div");24 access_right_1.id = "access-right-1";25 access_right_1.className = "flex-row flex-dynamic discord-user-option";26 access_right_1.title = "This operator can visit the 'Dashboard' page.";27 access_right_1.addEventListener(28 "click",29 function () {30 if (this.getAttribute("data-checked") === "no") {31 this.setAttribute("data-checked", "yes");32 this.childNodes[1].style.color = "#00FF00";33 this.childNodes[1].style.borderColor = "#00FF00";34 this.childNodes[1].innerHTML = "YES";35 }36 else if (this.getAttribute("data-checked") === "yes") {37 this.setAttribute("data-checked", "no");38 this.childNodes[1].style.color = "#FF0000";39 this.childNodes[1].style.borderColor = "#FF0000";40 this.childNodes[1].innerHTML = "NO";41 }42 },43 false44 );45 const access_right_1_description = document.createElement("span");46 access_right_1_description.className = "discord-user-option-description";47 access_right_1_description.innerHTML = "Dashboard (View)";48 const access_right_1_checkbox = document.createElement("div");49 access_right_1_checkbox.className = "discord-user-option-checkbox";50 if (details) {51 if (details["access_right_1"] === "yes") {52 access_right_1.setAttribute("data-checked", "yes");53 access_right_1_checkbox.style.color = "#00FF00";54 access_right_1_checkbox.style.borderColor = "#00FF00";55 access_right_1_checkbox.innerHTML = "YES";56 }57 else {58 access_right_1.setAttribute("data-checked", "no");59 access_right_1_checkbox.style.color = "#FF0000";60 access_right_1_checkbox.style.borderColor = "#FF0000";61 access_right_1_checkbox.innerHTML = "NO";62 }63 }64 else {65 access_right_1.setAttribute("data-checked", "yes");66 access_right_1_checkbox.style.color = "#00FF00";67 access_right_1_checkbox.style.borderColor = "#00FF00";68 access_right_1_checkbox.innerHTML = "YES";69 }70 access_right_1.appendChild(access_right_1_description);71 access_right_1.appendChild(access_right_1_checkbox);72 operator_body.appendChild(access_right_1);73 // #endregion74 // #region Payments (View)75 const access_right_2 = document.createElement("div");76 access_right_2.id = "access-right-2";77 access_right_2.className = "flex-row flex-dynamic discord-user-option";78 access_right_2.title = "This operator can visit the 'Payments' page.";79 access_right_2.addEventListener(80 "click",81 function () {82 if (this.getAttribute("data-checked") === "no") {83 this.setAttribute("data-checked", "yes");84 this.childNodes[1].style.color = "#00FF00";85 this.childNodes[1].style.borderColor = "#00FF00";86 this.childNodes[1].innerHTML = "YES";87 }88 else if (this.getAttribute("data-checked") === "yes") {89 this.setAttribute("data-checked", "no");90 this.childNodes[1].style.color = "#FF0000";91 this.childNodes[1].style.borderColor = "#FF0000";92 this.childNodes[1].innerHTML = "NO";93 }94 },95 false96 );97 const access_right_2_description = document.createElement("span");98 access_right_2_description.className = "discord-user-option-description";99 access_right_2_description.innerHTML = "Payments (View)";100 const access_right_2_checkbox = document.createElement("div");101 access_right_2_checkbox.className = "discord-user-option-checkbox";102 if (details) {103 if (details["access_right_2"] === "yes") {104 access_right_2.setAttribute("data-checked", "yes");105 access_right_2_checkbox.style.color = "#00FF00";106 access_right_2_checkbox.style.borderColor = "#00FF00";107 access_right_2_checkbox.innerHTML = "YES";108 }109 else {110 access_right_2.setAttribute("data-checked", "no");111 access_right_2_checkbox.style.color = "#FF0000";112 access_right_2_checkbox.style.borderColor = "#FF0000";113 access_right_2_checkbox.innerHTML = "NO";114 }115 }116 else {117 access_right_2.setAttribute("data-checked", "yes");118 access_right_2_checkbox.style.color = "#00FF00";119 access_right_2_checkbox.style.borderColor = "#00FF00";120 access_right_2_checkbox.innerHTML = "YES";121 }122 access_right_2.appendChild(access_right_2_description);123 access_right_2.appendChild(access_right_2_checkbox);124 operator_body.appendChild(access_right_2);125 // #endregion126 // #region Problems (View)127 const access_right_3 = document.createElement("div");128 access_right_3.id = "access-right-3";129 access_right_3.className = "flex-row flex-dynamic discord-user-option";130 access_right_3.title = "This operator can visit the 'Problems' page.";131 access_right_3.addEventListener(132 "click",133 function () {134 if (this.getAttribute("data-checked") === "no") {135 this.setAttribute("data-checked", "yes");136 this.childNodes[1].style.color = "#00FF00";137 this.childNodes[1].style.borderColor = "#00FF00";138 this.childNodes[1].innerHTML = "YES";139 }140 else if (this.getAttribute("data-checked") === "yes") {141 this.setAttribute("data-checked", "no");142 this.childNodes[1].style.color = "#FF0000";143 this.childNodes[1].style.borderColor = "#FF0000";144 this.childNodes[1].innerHTML = "NO";145 }146 },147 false148 );149 const access_right_3_description = document.createElement("span");150 access_right_3_description.className = "discord-user-option-description";151 access_right_3_description.innerHTML = "Problems (View)";152 const access_right_3_checkbox = document.createElement("div");153 access_right_3_checkbox.className = "discord-user-option-checkbox";154 if (details) {155 if (details["access_right_3"] === "yes") {156 access_right_3.setAttribute("data-checked", "yes");157 access_right_3_checkbox.style.color = "#00FF00";158 access_right_3_checkbox.style.borderColor = "#00FF00";159 access_right_3_checkbox.innerHTML = "YES";160 }161 else {162 access_right_3.setAttribute("data-checked", "no");163 access_right_3_checkbox.style.color = "#FF0000";164 access_right_3_checkbox.style.borderColor = "#FF0000";165 access_right_3_checkbox.innerHTML = "NO";166 }167 }168 else {169 access_right_3.setAttribute("data-checked", "yes");170 access_right_3_checkbox.style.color = "#00FF00";171 access_right_3_checkbox.style.borderColor = "#00FF00";172 access_right_3_checkbox.innerHTML = "YES";173 }174 access_right_3.appendChild(access_right_3_description);175 access_right_3.appendChild(access_right_3_checkbox);176 operator_body.appendChild(access_right_3);177 // #endregion178 // #region Modules (View)179 const access_right_4 = document.createElement("div");180 access_right_4.id = "access-right-4";181 access_right_4.className = "flex-row flex-dynamic discord-user-option";182 access_right_4.title = "This operator can visit the 'Modules' page.";183 access_right_4.addEventListener(184 "click",185 function () {186 if (this.getAttribute("data-checked") === "no") {187 this.setAttribute("data-checked", "yes");188 this.childNodes[1].style.color = "#00FF00";189 this.childNodes[1].style.borderColor = "#00FF00";190 this.childNodes[1].innerHTML = "YES";191 }192 else if (this.getAttribute("data-checked") === "yes") {193 this.setAttribute("data-checked", "no");194 this.childNodes[1].style.color = "#FF0000";195 this.childNodes[1].style.borderColor = "#FF0000";196 this.childNodes[1].innerHTML = "NO";197 document.getElementById("access-right-5").setAttribute("data-checked", "no");198 document.getElementById("access-right-5").childNodes[1].style.color = "#FF0000";199 document.getElementById("access-right-5").childNodes[1].style.borderColor = "#FF0000";200 document.getElementById("access-right-5").childNodes[1].innerHTML = "NO";201 }202 },203 false204 );205 const access_right_4_description = document.createElement("span");206 access_right_4_description.className = "discord-user-option-description";207 access_right_4_description.innerHTML = "Modules (View)";208 const access_right_4_checkbox = document.createElement("div");209 access_right_4_checkbox.className = "discord-user-option-checkbox";210 if (details) {211 if (details["access_right_4"] === "yes") {212 access_right_4.setAttribute("data-checked", "yes");213 access_right_4_checkbox.style.color = "#00FF00";214 access_right_4_checkbox.style.borderColor = "#00FF00";215 access_right_4_checkbox.innerHTML = "YES";216 }217 else {218 access_right_4.setAttribute("data-checked", "no");219 access_right_4_checkbox.style.color = "#FF0000";220 access_right_4_checkbox.style.borderColor = "#FF0000";221 access_right_4_checkbox.innerHTML = "NO";222 }223 }224 else {225 access_right_4.setAttribute("data-checked", "yes");226 access_right_4_checkbox.style.color = "#00FF00";227 access_right_4_checkbox.style.borderColor = "#00FF00";228 access_right_4_checkbox.innerHTML = "YES";229 }230 access_right_4.appendChild(access_right_4_description);231 access_right_4.appendChild(access_right_4_checkbox);232 operator_body.appendChild(access_right_4);233 // #endregion234 // #region Modules (Manage)235 const access_right_5 = document.createElement("div");236 access_right_5.id = "access-right-5";237 access_right_5.className = "flex-row flex-dynamic discord-user-option";238 access_right_5.title = "This operator can install and uninstall modules on the 'Modules' page.";239 access_right_5.addEventListener(240 "click",241 function () {242 if (this.getAttribute("data-checked") === "no") {243 this.setAttribute("data-checked", "yes");244 this.childNodes[1].style.color = "#00FF00";245 this.childNodes[1].style.borderColor = "#00FF00";246 this.childNodes[1].innerHTML = "YES";247 document.getElementById("access-right-4").setAttribute("data-checked", "yes");248 document.getElementById("access-right-4").childNodes[1].style.color = "#00FF00";249 document.getElementById("access-right-4").childNodes[1].style.borderColor = "#00FF00";250 document.getElementById("access-right-4").childNodes[1].innerHTML = "YES";251 }252 else if (this.getAttribute("data-checked") === "yes") {253 this.setAttribute("data-checked", "no");254 this.childNodes[1].style.color = "#FF0000";255 this.childNodes[1].style.borderColor = "#FF0000";256 this.childNodes[1].innerHTML = "NO";257 }258 },259 false260 );261 const access_right_5_description = document.createElement("span");262 access_right_5_description.className = "discord-user-option-description";263 access_right_5_description.innerHTML = "Modules (Manage)";264 const access_right_5_checkbox = document.createElement("div");265 access_right_5_checkbox.className = "discord-user-option-checkbox";266 if (details) {267 if (details["access_right_5"] === "yes") {268 access_right_5.setAttribute("data-checked", "yes");269 access_right_5_checkbox.style.color = "#00FF00";270 access_right_5_checkbox.style.borderColor = "#00FF00";271 access_right_5_checkbox.innerHTML = "YES";272 }273 else {274 access_right_5.setAttribute("data-checked", "no");275 access_right_5_checkbox.style.color = "#FF0000";276 access_right_5_checkbox.style.borderColor = "#FF0000";277 access_right_5_checkbox.innerHTML = "NO";278 }279 }280 else {281 access_right_5.setAttribute("data-checked", "yes");282 access_right_5_checkbox.style.color = "#00FF00";283 access_right_5_checkbox.style.borderColor = "#00FF00";284 access_right_5_checkbox.innerHTML = "YES";285 }286 access_right_5.appendChild(access_right_5_description);287 access_right_5.appendChild(access_right_5_checkbox);288 operator_body.appendChild(access_right_5);289 // #endregion290 // #region Operators (View)291 const access_right_6 = document.createElement("div");292 access_right_6.id = "access-right-6";293 access_right_6.className = "flex-row flex-dynamic discord-user-option";294 access_right_6.title = "This operator can visit the 'Operators' page.";295 access_right_6.addEventListener(296 "click",297 function () {298 if (this.getAttribute("data-checked") === "no") {299 this.setAttribute("data-checked", "yes");300 this.childNodes[1].style.color = "#00FF00";301 this.childNodes[1].style.borderColor = "#00FF00";302 this.childNodes[1].innerHTML = "YES";303 }304 else if (this.getAttribute("data-checked") === "yes") {305 this.setAttribute("data-checked", "no");306 this.childNodes[1].style.color = "#FF0000";307 this.childNodes[1].style.borderColor = "#FF0000";308 this.childNodes[1].innerHTML = "NO";309 document.getElementById("access-right-7").setAttribute("data-checked", "no");310 document.getElementById("access-right-7").childNodes[1].style.color = "#FF0000";311 document.getElementById("access-right-7").childNodes[1].style.borderColor = "#FF0000";312 document.getElementById("access-right-7").childNodes[1].innerHTML = "NO";313 }314 },315 false316 );317 const access_right_6_description = document.createElement("span");318 access_right_6_description.className = "discord-user-option-description";319 access_right_6_description.innerHTML = "Operators (View)";320 const access_right_6_checkbox = document.createElement("div");321 access_right_6_checkbox.className = "discord-user-option-checkbox";322 if (details) {323 if (details["access_right_6"] === "yes") {324 access_right_6.setAttribute("data-checked", "yes");325 access_right_6_checkbox.style.color = "#00FF00";326 access_right_6_checkbox.style.borderColor = "#00FF00";327 access_right_6_checkbox.innerHTML = "YES";328 }329 else {330 access_right_6.setAttribute("data-checked", "no");331 access_right_6_checkbox.style.color = "#FF0000";332 access_right_6_checkbox.style.borderColor = "#FF0000";333 access_right_6_checkbox.innerHTML = "NO";334 }335 }336 else {337 access_right_6.setAttribute("data-checked", "yes");338 access_right_6_checkbox.style.color = "#00FF00";339 access_right_6_checkbox.style.borderColor = "#00FF00";340 access_right_6_checkbox.innerHTML = "YES";341 }342 access_right_6.appendChild(access_right_6_description);343 access_right_6.appendChild(access_right_6_checkbox);344 operator_body.appendChild(access_right_6);345 // #endregion346 // #region Operators (Manage)347 const access_right_7 = document.createElement("div");348 access_right_7.id = "access-right-7";349 access_right_7.className = "flex-row flex-dynamic discord-user-option";350 access_right_7.title = "This operator can add, edit and delete operators on the 'Operators' page. Be careful with this!";351 access_right_7.addEventListener(352 "click",353 function () {354 if (this.getAttribute("data-checked") === "no") {355 this.setAttribute("data-checked", "yes");356 this.childNodes[1].style.color = "#00FF00";357 this.childNodes[1].style.borderColor = "#00FF00";358 this.childNodes[1].innerHTML = "YES";359 document.getElementById("access-right-6").setAttribute("data-checked", "yes");360 document.getElementById("access-right-6").childNodes[1].style.color = "#00FF00";361 document.getElementById("access-right-6").childNodes[1].style.borderColor = "#00FF00";362 document.getElementById("access-right-6").childNodes[1].innerHTML = "YES";363 }364 else if (this.getAttribute("data-checked") === "yes") {365 this.setAttribute("data-checked", "no");366 this.childNodes[1].style.color = "#FF0000";367 this.childNodes[1].style.borderColor = "#FF0000";368 this.childNodes[1].innerHTML = "NO";369 }370 },371 false372 );373 const access_right_7_description = document.createElement("span");374 access_right_7_description.className = "discord-user-option-description";375 access_right_7_description.innerHTML = "Operators (Manage)";376 const access_right_7_checkbox = document.createElement("div");377 access_right_7_checkbox.className = "discord-user-option-checkbox";378 if (details) {379 if (details["access_right_7"] === "yes") {380 access_right_7.setAttribute("data-checked", "yes");381 access_right_7_checkbox.style.color = "#00FF00";382 access_right_7_checkbox.style.borderColor = "#00FF00";383 access_right_7_checkbox.innerHTML = "YES";384 }385 else {386 access_right_7.setAttribute("data-checked", "no");387 access_right_7_checkbox.style.color = "#FF0000";388 access_right_7_checkbox.style.borderColor = "#FF0000";389 access_right_7_checkbox.innerHTML = "NO";390 }391 }392 else {393 access_right_7.setAttribute("data-checked", "no");394 access_right_7_checkbox.style.color = "#FF0000";395 access_right_7_checkbox.style.borderColor = "#FF0000";396 access_right_7_checkbox.innerHTML = "NO";397 }398 access_right_7.appendChild(access_right_7_description);399 access_right_7.appendChild(access_right_7_checkbox);400 operator_body.appendChild(access_right_7);401 // #endregion402 // #region Keywords (View)403 const access_right_8 = document.createElement("div");404 access_right_8.id = "access-right-8";405 access_right_8.className = "flex-row flex-dynamic discord-user-option";406 access_right_8.title = "This operator can visit the 'Keywords' page.";407 access_right_8.addEventListener(408 "click",409 function () {410 if (this.getAttribute("data-checked") === "no") {411 this.setAttribute("data-checked", "yes");412 this.childNodes[1].style.color = "#00FF00";413 this.childNodes[1].style.borderColor = "#00FF00";414 this.childNodes[1].innerHTML = "YES";415 }416 else if (this.getAttribute("data-checked") === "yes") {417 this.setAttribute("data-checked", "no");418 this.childNodes[1].style.color = "#FF0000";419 this.childNodes[1].style.borderColor = "#FF0000";420 this.childNodes[1].innerHTML = "NO";421 document.getElementById("access-right-9").setAttribute("data-checked", "no");422 document.getElementById("access-right-9").childNodes[1].style.color = "#FF0000";423 document.getElementById("access-right-9").childNodes[1].style.borderColor = "#FF0000";424 document.getElementById("access-right-9").childNodes[1].innerHTML = "NO";425 }426 },427 false428 );429 const access_right_8_description = document.createElement("span");430 access_right_8_description.className = "discord-user-option-description";431 access_right_8_description.innerHTML = "Keywords (View)";432 const access_right_8_checkbox = document.createElement("div");433 access_right_8_checkbox.className = "discord-user-option-checkbox";434 if (details) {435 if (details["access_right_8"] === "yes") {436 access_right_8.setAttribute("data-checked", "yes");437 access_right_8_checkbox.style.color = "#00FF00";438 access_right_8_checkbox.style.borderColor = "#00FF00";439 access_right_8_checkbox.innerHTML = "YES";440 }441 else {442 access_right_8.setAttribute("data-checked", "no");443 access_right_8_checkbox.style.color = "#FF0000";444 access_right_8_checkbox.style.borderColor = "#FF0000";445 access_right_8_checkbox.innerHTML = "NO";446 }447 }448 else {449 access_right_8.setAttribute("data-checked", "yes");450 access_right_8_checkbox.style.color = "#00FF00";451 access_right_8_checkbox.style.borderColor = "#00FF00";452 access_right_8_checkbox.innerHTML = "YES";453 }454 access_right_8.appendChild(access_right_8_description);455 access_right_8.appendChild(access_right_8_checkbox);456 operator_body.appendChild(access_right_8);457 // #endregion458 // #region Keywords (Manage)459 const access_right_9 = document.createElement("div");460 access_right_9.id = "access-right-9";461 access_right_9.className = "flex-row flex-dynamic discord-user-option";462 access_right_9.title = "This operator can add, edit and delete keywords on the 'Keywords' page.";463 access_right_9.addEventListener(464 "click",465 function () {466 if (this.getAttribute("data-checked") === "no") {467 this.setAttribute("data-checked", "yes");468 this.childNodes[1].style.color = "#00FF00";469 this.childNodes[1].style.borderColor = "#00FF00";470 this.childNodes[1].innerHTML = "YES";471 document.getElementById("access-right-8").setAttribute("data-checked", "yes");472 document.getElementById("access-right-8").childNodes[1].style.color = "#00FF00";473 document.getElementById("access-right-8").childNodes[1].style.borderColor = "#00FF00";474 document.getElementById("access-right-8").childNodes[1].innerHTML = "YES";475 }476 else if (this.getAttribute("data-checked") === "yes") {477 this.setAttribute("data-checked", "no");478 this.childNodes[1].style.color = "#FF0000";479 this.childNodes[1].style.borderColor = "#FF0000";480 this.childNodes[1].innerHTML = "NO";481 }482 },483 false484 );485 const access_right_9_description = document.createElement("span");486 access_right_9_description.className = "discord-user-option-description";487 access_right_9_description.innerHTML = "Keywords (Manage)";488 const access_right_9_checkbox = document.createElement("div");489 access_right_9_checkbox.className = "discord-user-option-checkbox";490 if (details) {491 if (details["access_right_9"] === "yes") {492 access_right_9.setAttribute("data-checked", "yes");493 access_right_9_checkbox.style.color = "#00FF00";494 access_right_9_checkbox.style.borderColor = "#00FF00";495 access_right_9_checkbox.innerHTML = "YES";496 }497 else {498 access_right_9.setAttribute("data-checked", "no");499 access_right_9_checkbox.style.color = "#FF0000";500 access_right_9_checkbox.style.borderColor = "#FF0000";501 access_right_9_checkbox.innerHTML = "NO";502 }503 }504 else {505 access_right_9.setAttribute("data-checked", "yes");506 access_right_9_checkbox.style.color = "#00FF00";507 access_right_9_checkbox.style.borderColor = "#00FF00";508 access_right_9_checkbox.innerHTML = "YES";509 }510 access_right_9.appendChild(access_right_9_description);511 access_right_9.appendChild(access_right_9_checkbox);512 operator_body.appendChild(access_right_9);513 // #endregion514 // #region Conditions (View)515 const access_right_10 = document.createElement("div");516 access_right_10.id = "access-right-10";517 access_right_10.className = "flex-row flex-dynamic discord-user-option";518 access_right_10.title = "This operator can visit the 'Conditions' page.";519 access_right_10.addEventListener(520 "click",521 function () {522 if (this.getAttribute("data-checked") === "no") {523 this.setAttribute("data-checked", "yes");524 this.childNodes[1].style.color = "#00FF00";525 this.childNodes[1].style.borderColor = "#00FF00";526 this.childNodes[1].innerHTML = "YES";527 }528 else if (this.getAttribute("data-checked") === "yes") {529 this.setAttribute("data-checked", "no");530 this.childNodes[1].style.color = "#FF0000";531 this.childNodes[1].style.borderColor = "#FF0000";532 this.childNodes[1].innerHTML = "NO";533 document.getElementById("access-right-11").setAttribute("data-checked", "no");534 document.getElementById("access-right-11").childNodes[1].style.color = "#FF0000";535 document.getElementById("access-right-11").childNodes[1].style.borderColor = "#FF0000";536 document.getElementById("access-right-11").childNodes[1].innerHTML = "NO";537 }538 },539 false540 );541 const access_right_10_description = document.createElement("span");542 access_right_10_description.className = "discord-user-option-description";543 access_right_10_description.innerHTML = "Conditions (View)";544 const access_right_10_checkbox = document.createElement("div");545 access_right_10_checkbox.className = "discord-user-option-checkbox";546 if (details) {547 if (details["access_right_10"] === "yes") {548 access_right_10.setAttribute("data-checked", "yes");549 access_right_10_checkbox.style.color = "#00FF00";550 access_right_10_checkbox.style.borderColor = "#00FF00";551 access_right_10_checkbox.innerHTML = "YES";552 }553 else {554 access_right_10.setAttribute("data-checked", "no");555 access_right_10_checkbox.style.color = "#FF0000";556 access_right_10_checkbox.style.borderColor = "#FF0000";557 access_right_10_checkbox.innerHTML = "NO";558 }559 }560 else {561 access_right_10.setAttribute("data-checked", "yes");562 access_right_10_checkbox.style.color = "#00FF00";563 access_right_10_checkbox.style.borderColor = "#00FF00";564 access_right_10_checkbox.innerHTML = "YES";565 }566 access_right_10.appendChild(access_right_10_description);567 access_right_10.appendChild(access_right_10_checkbox);568 operator_body.appendChild(access_right_10);569 // #endregion570 // #region Conditions (Manage)571 const access_right_11 = document.createElement("div");572 access_right_11.id = "access-right-11";573 access_right_11.className = "flex-row flex-dynamic discord-user-option";574 access_right_11.title = "This operator can add, edit and delete conditions on the 'Conditions' page. He can not edit or delete conditions that are already used in rules, unless he does have the 'Rules (Manage)' access right.";575 access_right_11.addEventListener(576 "click",577 function () {578 if (this.getAttribute("data-checked") === "no") {579 this.setAttribute("data-checked", "yes");580 this.childNodes[1].style.color = "#00FF00";581 this.childNodes[1].style.borderColor = "#00FF00";582 this.childNodes[1].innerHTML = "YES";583 document.getElementById("access-right-10").setAttribute("data-checked", "yes");584 document.getElementById("access-right-10").childNodes[1].style.color = "#00FF00";585 document.getElementById("access-right-10").childNodes[1].style.borderColor = "#00FF00";586 document.getElementById("access-right-10").childNodes[1].innerHTML = "YES";587 }588 else if (this.getAttribute("data-checked") === "yes") {589 this.setAttribute("data-checked", "no");590 this.childNodes[1].style.color = "#FF0000";591 this.childNodes[1].style.borderColor = "#FF0000";592 this.childNodes[1].innerHTML = "NO";593 }594 },595 false596 );597 const access_right_11_description = document.createElement("span");598 access_right_11_description.className = "discord-user-option-description";599 access_right_11_description.innerHTML = "Conditions (Manage)";600 const access_right_11_checkbox = document.createElement("div");601 access_right_11_checkbox.className = "discord-user-option-checkbox";602 if (details) {603 if (details["access_right_11"] === "yes") {604 access_right_11.setAttribute("data-checked", "yes");605 access_right_11_checkbox.style.color = "#00FF00";606 access_right_11_checkbox.style.borderColor = "#00FF00";607 access_right_11_checkbox.innerHTML = "YES";608 }609 else {610 access_right_11.setAttribute("data-checked", "no");611 access_right_11_checkbox.style.color = "#FF0000";612 access_right_11_checkbox.style.borderColor = "#FF0000";613 access_right_11_checkbox.innerHTML = "NO";614 }615 }616 else {617 access_right_11.setAttribute("data-checked", "yes");618 access_right_11_checkbox.style.color = "#00FF00";619 access_right_11_checkbox.style.borderColor = "#00FF00";620 access_right_11_checkbox.innerHTML = "YES";621 }622 access_right_11.appendChild(access_right_11_description);623 access_right_11.appendChild(access_right_11_checkbox);624 operator_body.appendChild(access_right_11);625 // #endregion626 // #region Rules (View)627 const access_right_12 = document.createElement("div");628 access_right_12.id = "access-right-12";629 access_right_12.className = "flex-row flex-dynamic discord-user-option";630 access_right_12.title = "This operator can visit the 'Rules' page.";631 access_right_12.addEventListener(632 "click",633 function () {634 if (this.getAttribute("data-checked") === "no") {635 this.setAttribute("data-checked", "yes");636 this.childNodes[1].style.color = "#00FF00";637 this.childNodes[1].style.borderColor = "#00FF00";638 this.childNodes[1].innerHTML = "YES";639 }640 else if (this.getAttribute("data-checked") === "yes") {641 this.setAttribute("data-checked", "no");642 this.childNodes[1].style.color = "#FF0000";643 this.childNodes[1].style.borderColor = "#FF0000";644 this.childNodes[1].innerHTML = "NO";645 document.getElementById("access-right-13").setAttribute("data-checked", "no");646 document.getElementById("access-right-13").childNodes[1].style.color = "#FF0000";647 document.getElementById("access-right-13").childNodes[1].style.borderColor = "#FF0000";648 document.getElementById("access-right-13").childNodes[1].innerHTML = "NO";649 }650 },651 false652 );653 const access_right_12_description = document.createElement("span");654 access_right_12_description.className = "discord-user-option-description";655 access_right_12_description.innerHTML = "Rules (View)";656 const access_right_12_checkbox = document.createElement("div");657 access_right_12_checkbox.className = "discord-user-option-checkbox";658 if (details) {659 if (details["access_right_12"] === "yes") {660 access_right_12.setAttribute("data-checked", "yes");661 access_right_12_checkbox.style.color = "#00FF00";662 access_right_12_checkbox.style.borderColor = "#00FF00";663 access_right_12_checkbox.innerHTML = "YES";664 }665 else {666 access_right_12.setAttribute("data-checked", "no");667 access_right_12_checkbox.style.color = "#FF0000";668 access_right_12_checkbox.style.borderColor = "#FF0000";669 access_right_12_checkbox.innerHTML = "NO";670 }671 }672 else {673 access_right_12.setAttribute("data-checked", "yes");674 access_right_12_checkbox.style.color = "#00FF00";675 access_right_12_checkbox.style.borderColor = "#00FF00";676 access_right_12_checkbox.innerHTML = "YES";677 }678 access_right_12.appendChild(access_right_12_description);679 access_right_12.appendChild(access_right_12_checkbox);680 operator_body.appendChild(access_right_12);681 // #endregion682 // #region Rules (Manage)683 const access_right_13 = document.createElement("div");684 access_right_13.id = "access-right-13";685 access_right_13.className = "flex-row flex-dynamic discord-user-option";686 access_right_13.title = "This operator can add, edit and delete rules on the 'Rules' page.";687 access_right_13.addEventListener(688 "click",689 function () {690 if (this.getAttribute("data-checked") === "no") {691 this.setAttribute("data-checked", "yes");692 this.childNodes[1].style.color = "#00FF00";693 this.childNodes[1].style.borderColor = "#00FF00";694 this.childNodes[1].innerHTML = "YES";695 document.getElementById("access-right-12").setAttribute("data-checked", "yes");696 document.getElementById("access-right-12").childNodes[1].style.color = "#00FF00";697 document.getElementById("access-right-12").childNodes[1].style.borderColor = "#00FF00";698 document.getElementById("access-right-12").childNodes[1].innerHTML = "YES";699 }700 else if (this.getAttribute("data-checked") === "yes") {701 this.setAttribute("data-checked", "no");702 this.childNodes[1].style.color = "#FF0000";703 this.childNodes[1].style.borderColor = "#FF0000";704 this.childNodes[1].innerHTML = "NO";705 }706 },707 false708 );709 const access_right_13_description = document.createElement("span");710 access_right_13_description.className = "discord-user-option-description";711 access_right_13_description.innerHTML = "Rules (Manage)";712 const access_right_13_checkbox = document.createElement("div");713 access_right_13_checkbox.className = "discord-user-option-checkbox";714 if (details) {715 if (details["access_right_13"] === "yes") {716 access_right_13.setAttribute("data-checked", "yes");717 access_right_13_checkbox.style.color = "#00FF00";718 access_right_13_checkbox.style.borderColor = "#00FF00";719 access_right_13_checkbox.innerHTML = "YES";720 }721 else {722 access_right_13.setAttribute("data-checked", "no");723 access_right_13_checkbox.style.color = "#FF0000";724 access_right_13_checkbox.style.borderColor = "#FF0000";725 access_right_13_checkbox.innerHTML = "NO";726 }727 }728 else {729 access_right_13.setAttribute("data-checked", "yes");730 access_right_13_checkbox.style.color = "#00FF00";731 access_right_13_checkbox.style.borderColor = "#00FF00";732 access_right_13_checkbox.innerHTML = "YES";733 }734 access_right_13.appendChild(access_right_13_description);735 access_right_13.appendChild(access_right_13_checkbox);736 operator_body.appendChild(access_right_13);737 // #endregion738 // #region Bot Control (View)739 const access_right_14 = document.createElement("div");740 access_right_14.id = "access-right-14";741 access_right_14.className = "flex-row flex-dynamic discord-user-option";742 access_right_14.title = "This operator can visit the 'Bot Control' page.";743 access_right_14.addEventListener(744 "click",745 function () {746 if (this.getAttribute("data-checked") === "no") {747 this.setAttribute("data-checked", "yes");748 this.childNodes[1].style.color = "#00FF00";749 this.childNodes[1].style.borderColor = "#00FF00";750 this.childNodes[1].innerHTML = "YES";751 }752 else if (this.getAttribute("data-checked") === "yes") {753 this.setAttribute("data-checked", "no");754 this.childNodes[1].style.color = "#FF0000";755 this.childNodes[1].style.borderColor = "#FF0000";756 this.childNodes[1].innerHTML = "NO";757 document.getElementById("access-right-15").setAttribute("data-checked", "no");758 document.getElementById("access-right-15").childNodes[1].style.color = "#FF0000";759 document.getElementById("access-right-15").childNodes[1].style.borderColor = "#FF0000";760 761 document.getElementById("access-right-15").childNodes[1].innerHTML = "NO";762 }763 },764 false765 );766 const access_right_14_description = document.createElement("span");767 access_right_14_description.className = "discord-user-option-description";768 access_right_14_description.innerHTML = "Bot Control (View)";769 const access_right_14_checkbox = document.createElement("div");770 access_right_14_checkbox.className = "discord-user-option-checkbox";771 if (details) {772 if (details["access_right_14"] === "yes") {773 access_right_14.setAttribute("data-checked", "yes");774 access_right_14_checkbox.style.color = "#00FF00";775 access_right_14_checkbox.style.borderColor = "#00FF00";776 access_right_14_checkbox.innerHTML = "YES";777 }778 else {779 access_right_14.setAttribute("data-checked", "no");780 access_right_14_checkbox.style.color = "#FF0000";781 access_right_14_checkbox.style.borderColor = "#FF0000";782 access_right_14_checkbox.innerHTML = "NO";783 }784 }785 else {786 access_right_14.setAttribute("data-checked", "yes");787 access_right_14_checkbox.style.color = "#00FF00";788 access_right_14_checkbox.style.borderColor = "#00FF00";789 access_right_14_checkbox.innerHTML = "YES";790 }791 access_right_14.appendChild(access_right_14_description);792 access_right_14.appendChild(access_right_14_checkbox);793 operator_body.appendChild(access_right_14);794 // #endregion795 // #region Bot Control (Manage)796 const access_right_15 = document.createElement("div");797 access_right_15.id = "access-right-15";798 access_right_15.className = "flex-row flex-dynamic discord-user-option";799 access_right_15.title = "This operator can use the bot controls on the 'Bot Control' page.";800 access_right_15.addEventListener(801 "click",802 function () {803 if (this.getAttribute("data-checked") === "no") {804 this.setAttribute("data-checked", "yes");805 this.childNodes[1].style.color = "#00FF00";806 this.childNodes[1].style.borderColor = "#00FF00";807 this.childNodes[1].innerHTML = "YES";808 document.getElementById("access-right-14").setAttribute("data-checked", "yes");809 document.getElementById("access-right-14").childNodes[1].style.color = "#00FF00";810 document.getElementById("access-right-14").childNodes[1].style.borderColor = "#00FF00";811 document.getElementById("access-right-14").childNodes[1].innerHTML = "YES";812 }813 else if (this.getAttribute("data-checked") === "yes") {814 this.setAttribute("data-checked", "no");815 this.childNodes[1].style.color = "#FF0000";816 this.childNodes[1].style.borderColor = "#FF0000";817 this.childNodes[1].innerHTML = "NO";818 }819 },820 false821 );822 const access_right_15_description = document.createElement("span");823 access_right_15_description.className = "discord-user-option-description";824 access_right_15_description.innerHTML = "Bot Control (Manage)";825 const access_right_15_checkbox = document.createElement("div");826 access_right_15_checkbox.className = "discord-user-option-checkbox";827 if (details) {828 if (details["access_right_15"] === "yes") {829 access_right_15.setAttribute("data-checked", "yes");830 access_right_15_checkbox.style.color = "#00FF00";831 access_right_15_checkbox.style.borderColor = "#00FF00";832 access_right_15_checkbox.innerHTML = "YES";833 }834 else {835 access_right_15.setAttribute("data-checked", "no");836 access_right_15_checkbox.style.color = "#FF0000";837 access_right_15_checkbox.style.borderColor = "#FF0000";838 access_right_15_checkbox.innerHTML = "NO";839 }840 }841 else {842 access_right_15.setAttribute("data-checked", "yes");843 access_right_15_checkbox.style.color = "#00FF00";844 access_right_15_checkbox.style.borderColor = "#00FF00";845 access_right_15_checkbox.innerHTML = "YES";846 }847 access_right_15.appendChild(access_right_15_description);848 access_right_15.appendChild(access_right_15_checkbox);849 operator_body.appendChild(access_right_15);850 // #endregion851 operator_body.style.display = null;852}853function close_discord_user_dialog() {854 const discord_user_dialog = document.getElementById("discord-user-selection").parentNode;855 discord_user_dialog.parentNode.removeChild(discord_user_dialog);856};857function selected_discord_user(discord_user_wrapper, discord_user_element) {858 const discord_user_id = discord_user_element.getAttribute("data-id");859 const discord_user_header = discord_user_element.getElementsByClassName("discord-user-header")[0].innerHTML;860 const discord_user_description = discord_user_element.getElementsByClassName("discord-user-description")[0].innerHTML;861 discord_user_wrapper.setAttribute("data-id", discord_user_id);862 discord_user_wrapper.getElementsByClassName("discord-user-header")[0].innerHTML = discord_user_header;863 discord_user_wrapper.getElementsByClassName("discord-user-description")[0].innerHTML = discord_user_description;864 discord_user_wrapper.style.borderColor = "#00FF00";865 load_discord_user_details();866};867async function show_discord_user_dialog(event) {868 event.stopPropagation();869 if (document.getElementById("discord-user-selection")) {870 return;871 }872 873 const discord_user_wrapper = this.parentNode.parentNode;874 const x_coord = discord_user_wrapper.offsetLeft + 10;875 const y_coord = discord_user_wrapper.offsetTop + 10;876 const dialog_width = discord_user_wrapper.offsetWidth - 20;877 const discord_user_dialog = document.createElement("div");878 discord_user_dialog.style.position = "absolute";879 discord_user_dialog.style.top = y_coord + "px";880 discord_user_dialog.style.left = x_coord + "px";881 discord_user_dialog.style.width = dialog_width + "px";882 discord_user_dialog.style.maxHeight = "500px";883 discord_user_dialog.style.overflow = "auto";884 const discord_user_area = document.createElement("div");885 discord_user_area.id = "discord-user-selection";886 discord_user_area.className = "flex-column flex-dynamic area with-border";887 discord_user_area.style.marginBottom = "10px";888 discord_user_area.style.background = "#555555";889 const discord_user_keys = Object.keys(discord_users);890 for (let i = 0; i < discord_user_keys.length; i++) {891 const discord_user_id = discord_user_keys[i];892 const data_row = discord_users[discord_user_id];893 const discord_user_selection = document.createElement("div");894 discord_user_selection.className = "flex-column flex-static area with-border";895 discord_user_selection.setAttribute("data-id", discord_user_id);896 discord_user_selection.style.marginBottom = "5px";897 discord_user_selection.style.background = "#222222";898 discord_user_selection.style.cursor = "pointer";899 discord_user_selection.addEventListener(900 "click",901 function () {902 selected_discord_user(discord_user_wrapper, this);903 close_discord_user_dialog();904 },905 false906 );907 const discord_user_header = document.createElement("div");908 discord_user_header.className = "discord-user-header";909 discord_user_header.innerHTML = data_row["display_name"];910 const discord_user_operation_area = document.createElement("div");911 discord_user_operation_area.className = "flex-row flex-dynamic area";912 discord_user_operation_area.style.background = "#222222";913 const discord_user_description = document.createElement("div");914 discord_user_description.className = "discord-user-description area";915 discord_user_description.innerHTML = "Joined on " + new Date(data_row["joined_at"]).toLocaleDateString() + " with username " + data_row["user_name"] + ".";916 discord_user_selection.appendChild(discord_user_header);917 discord_user_selection.appendChild(discord_user_description);918 discord_user_area.appendChild(discord_user_selection);919 }920 discord_user_dialog.appendChild(discord_user_area);921 document.body.appendChild(discord_user_dialog);922};923async function initialize_operator(data) {924 discord_users = data["discord_users"];925 if (get_url_parameter("id") === "new") {926 return;927 }928 const operator = data["operator"];929 const discord_user_header = operator["display_name"];930 const discord_user_information = operator["information"];931 const details = operator["details"];932 const discord_user_wrapper = document.getElementById("operator-discord-user");933 discord_user_wrapper.setAttribute("data-id", get_url_parameter("id"));934 discord_user_wrapper.getElementsByClassName("discord-user-header")[0].innerHTML = discord_user_header;935 discord_user_wrapper.getElementsByClassName("discord-user-description")[0].innerHTML = discord_user_information;936 discord_user_wrapper.style.borderColor = "#00FF00";937 if (operator["note"] !== "No note.") {938 document.getElementById("operator-description").getElementsByTagName("textarea")[0].value = operator["note"];939 }940 load_discord_user_details(details);941};942function initialize_operator_area() {943 /* Wrapper */944 const operator_area = document.getElementById("operator-area");945 946 /* Discord User Selection */947 const discord_user_selection = document.createElement("div");948 discord_user_selection.id = "operator-discord-user";949 discord_user_selection.className = "flex-column flex-static area with-border";950 discord_user_selection.style.marginBottom = "10px";951 discord_user_selection.style.background = "#222222";952 discord_user_selection.style.borderColor = "#FF0000";953 const discord_user_header = document.createElement("div");954 discord_user_header.className = "discord-user-header";955 const discord_user_operation_area = document.createElement("div");956 discord_user_operation_area.className = "flex-row flex-dynamic area";957 discord_user_operation_area.style.background = "#222222";958 const discord_user_description = document.createElement("span");959 discord_user_description.className = "discord-user-description";960 const discord_user_select = document.createElement("button");961 discord_user_select.setAttribute("edit", true);962 discord_user_select.style.marginLeft = "auto";963 discord_user_select.style.marginTop = "auto";964 discord_user_select.style.marginBottom = "auto";965 discord_user_select.style.whiteSpace = "nowrap";966 discord_user_select.innerHTML = "Select Discord User";967 discord_user_select.addEventListener("click", show_discord_user_dialog, false);968 discord_user_selection.appendChild(discord_user_header);969 discord_user_operation_area.appendChild(discord_user_description);970 discord_user_operation_area.appendChild(discord_user_select);971 discord_user_selection.appendChild(discord_user_operation_area);972 /* Discord User Details */973 const operator_body = document.createElement("div");974 operator_body.id = "operator-discord-user-details";975 operator_body.className = "flex-row flex-static operator-body with-border";976 operator_body.style.borderColor = "#FFFFFF";977 operator_body.style.display = "none";978 979 operator_area.appendChild(discord_user_selection);980 operator_area.appendChild(operator_body);981 get_data();982};983function validate_operator() {984 let valid = true;985 986 const operator_discord_user = document.getElementById("operator-discord-user");987 988 if (!operator_discord_user.hasAttribute("data-id")) {989 valid = false;990 operator_discord_user.scrollIntoView({ behavior: "smooth" });991 alert("Please select a discord user.");992 }993 994 return valid;995};996function save_operator() {997 if (!validate_operator()) {998 return;999 }1000 1001 const operator_discord_user = document.getElementById("operator-discord-user").getAttribute("data-id");1002 const operator_display_name = document.getElementById("operator-discord-user").childNodes[0].innerHTML;1003 const operator_information = document.getElementById("operator-discord-user").childNodes[1].childNodes[0].innerHTML;1004 let operator_discord_user_details = undefined;1005 operator_discord_user_details = {1006 "access_right_1": document.getElementById("access-right-1").getAttribute("data-checked"),1007 "access_right_2": document.getElementById("access-right-2").getAttribute("data-checked"),1008 "access_right_3": document.getElementById("access-right-3").getAttribute("data-checked"),1009 "access_right_4": document.getElementById("access-right-4").getAttribute("data-checked"),1010 "access_right_5": document.getElementById("access-right-5").getAttribute("data-checked"),1011 "access_right_6": document.getElementById("access-right-6").getAttribute("data-checked"),1012 "access_right_7": document.getElementById("access-right-7").getAttribute("data-checked"),1013 "access_right_8": document.getElementById("access-right-8").getAttribute("data-checked"),1014 "access_right_9": document.getElementById("access-right-9").getAttribute("data-checked"),1015 "access_right_10": document.getElementById("access-right-10").getAttribute("data-checked"),1016 "access_right_11": document.getElementById("access-right-11").getAttribute("data-checked"),1017 "access_right_12": document.getElementById("access-right-12").getAttribute("data-checked"),1018 "access_right_13": document.getElementById("access-right-13").getAttribute("data-checked"),1019 "access_right_14": document.getElementById("access-right-14").getAttribute("data-checked"),1020 "access_right_15": document.getElementById("access-right-15").getAttribute("data-checked")1021 };1022 const operator_description = document.getElementById("operator-description").getElementsByTagName("textarea")[0].value;1023 post_data({1024 "operator": operator_discord_user,1025 "display_name": operator_display_name,1026 "information": operator_information,1027 "details": operator_discord_user_details,1028 "note": operator_description,1029 });1030};1031function get_url_parameter(key) {1032 key = key.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");1033 var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");1034 var results = regex.exec(location.search);1035 return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));1036};1037function get_data() {1038 socket.emit(1039 "config_operator",1040 {1041 "method": "get",1042 "data_id": get_url_parameter("id")1043 }1044 );1045}1046function post_data(data) {1047 socket.emit(1048 "config_operator",1049 {1050 "method": "post",1051 "data": data1052 }1053 );1054}1055function load_cookie() {1056 const name = "spectrum_module_default_config" + "=";1057 const decodedCookie = decodeURIComponent(document.cookie);1058 const ca = decodedCookie.split(";");1059 for (let i = 0; i < ca.length; i++) {1060 let c = ca[i];1061 while (c.charAt(0) == " ") {1062 c = c.substring(1);1063 }1064 if (c.indexOf(name) == 0) {1065 cookie = JSON.parse(c.substring(name.length, c.length).substring(2));1066 return true;1067 }1068 }1069 return false;1070}1071function open_socket() {1072 socket = io(1073 "https://" + cookie["host"] + ":" + cookie["port"] + "/" + cookie["server_id"],1074 {1075 query: "user_id=" + cookie["user_id"] + "&access_code=" + cookie["access_code"]1076 }1077 );1078 socket.on("data_ready", function (data) {1079 initialize_operator(data);1080 });1081 socket.on("data_posted", function () {1082 window.location = "/module/default/html/config/operators.html";1083 });1084 socket.on("data_error", function (error) {1085 alert(error);1086 });1087}1088function init() {1089 if (!load_cookie()) {1090 alert("Session expired!\n\nPlease request a new configuration link in Discord and make sure your browser accepts cookies, in case it doesn't.");1091 return;1092 }1093 open_socket();1094 initialize_operator_area();1095}1096//#region Wait for DOM1097const ready = function (callback) {1098 if (document.readyState === "complete") {1099 return callback();1100 }1101 document.addEventListener("DOMContentLoaded", callback, false);1102};1103ready(function () {1104 init();1105});...
DialogAccessGroups_Operations.js
Source:DialogAccessGroups_Operations.js
12var CurrentPageState_AccessGroups = 'View';3var ConfirmState_AccessGroups = null;4var ObjAccessGroup_AccessGroups = null;5function GetBoxesHeaders_AccessGroups() {6 parent.document.getElementById('Title_DialogAccessGroups').innerHTML = document.getElementById('hfTitle_DialogAccessGroups').value; 7 document.getElementById('header_AccessGroupsBox_AccessGroups').innerHTML = document.getElementById('hfheader_AccessGroupsBox_AccessGroups').value;8 document.getElementById('header_AccessGroupsDetailsBox_AccessGroups').innerHTML = document.getElementById('hfheader_AccessGroupsDetailsBox_AccessGroups').value;9 document.getElementById('header_AccessLevelBox_AccessGroups').innerHTML = document.getElementById('hfheader_AccessLevelBox_AccessGroups').value;10}11function GridAccessGroups_AccessGroups_onItemSelect(sender, e) {12 if (CurrentPageState_AccessGroups != 'Add')13 NavigateAccessGroup_AccessGroups(e.get_item());14 document.getElementById('hfAccessLevelsList_AccessGroups').value = 'null';15}16function NavigateAccessGroup_AccessGroups(selectedAccessGroupItem) {17 if (selectedAccessGroupItem != undefined) {18 document.getElementById('txtAccessGroupName_AccessGroups').value = selectedAccessGroupItem.getMember('Name').get_text();19 document.getElementById('txtDescription_AccessGroups').value = selectedAccessGroupItem.getMember('Description').get_text();20 }21}22function tlbItemNew_TlbAccessGroups_onClick() {23 ChangePageState_AccessGroups('Add');24 ClearList_AccessGroups();25 FocusOnFirstElement_AccessGroups();26}27function tlbItemEdit_TlbAccessGroups_onClick() {28 ChangePageState_AccessGroups('Edit');29 FocusOnFirstElement_AccessGroups();30}31function tlbItemDelete_TlbAccessGroups_onClick() {32 ChangePageState_AccessGroups('Delete');33}34function tlbItemSave_TlbAccessGroups_onClick() {35 AccessGroup_onSave();36}37function tlbItemCancel_TlbAccessGroups_onClick() {38 ChangePageState_AccessGroups('View');39 ClearList_AccessGroups();40}41function tlbItemExit_TlbAccessGroups_onClick() {42 ShowDialogConfirm('Exit');43}44function AccessGroup_onSave() {45 if (CurrentPageState_AccessGroups != 'Delete')46 UpdateAccessGroup_AccessGroups();47 else48 ShowDialogConfirm('Delete');49}50function CharToKeyCode_AccessGroups(str) {51 var OutStr = '';52 if (str != null && str != undefined) {53 for (var i = 0; i < str.length; i++) {54 var KeyCode = str.charCodeAt(i);55 var CharKeyCode = '//' + KeyCode;56 OutStr += CharKeyCode;57 }58 }59 return OutStr;60}61function ClearList_AccessGroups() {62 if (CurrentPageState_AccessGroups != 'Edit') {63 document.getElementById('txtAccessGroupName_AccessGroups').value = '';64 document.getElementById('txtDescription_AccessGroups').value = '';65 GridAccessGroups_AccessGroups.unSelectAll();66 }67}68function FocusOnFirstElement_AccessGroups() {69 document.getElementById('txtAccessGroupName_AccessGroups').focus();70}71function ChangePageState_AccessGroups(state) {72 CurrentPageState_AccessGroups = state;73 SetActionMode_AccessGroups(state);74 if (state == 'Add' || state == 'Edit' || state == 'Delete') {75 if (TlbAccessGroups.get_items().getItemById('tlbItemNew_TlbAccessGroups') != null) {76 TlbAccessGroups.get_items().getItemById('tlbItemNew_TlbAccessGroups').set_enabled(false);77 TlbAccessGroups.get_items().getItemById('tlbItemNew_TlbAccessGroups').set_imageUrl('add_silver.png');78 }79 if (TlbAccessGroups.get_items().getItemById('tlbItemEdit_TlbAccessGroups') != null) {80 TlbAccessGroups.get_items().getItemById('tlbItemEdit_TlbAccessGroups').set_enabled(false);81 TlbAccessGroups.get_items().getItemById('tlbItemEdit_TlbAccessGroups').set_imageUrl('edit_silver.png');82 }83 if (TlbAccessGroups.get_items().getItemById('tlbItemDelete_TlbAccessGroups') != null) {84 TlbAccessGroups.get_items().getItemById('tlbItemDelete_TlbAccessGroups').set_enabled(false);85 TlbAccessGroups.get_items().getItemById('tlbItemDelete_TlbAccessGroups').set_imageUrl('remove_silver.png');86 }87 TlbAccessGroups.get_items().getItemById('tlbItemSave_TlbAccessGroups').set_enabled(true);88 TlbAccessGroups.get_items().getItemById('tlbItemSave_TlbAccessGroups').set_imageUrl('save.png');89 TlbAccessGroups.get_items().getItemById('tlbItemCancel_TlbAccessGroups').set_enabled(true);90 TlbAccessGroups.get_items().getItemById('tlbItemCancel_TlbAccessGroups').set_imageUrl('cancel.png');91 if (state != 'Delete' && TlbAccessLevel_AccessGroups.get_items().getItemById('tlbItemAccessLevel_TlbAccessLevel_AccessGroups') != null) {92 TlbAccessLevel_AccessGroups.get_items().getItemById('tlbItemAccessLevel_TlbAccessLevel_AccessGroups').set_enabled(true);93 TlbAccessLevel_AccessGroups.get_items().getItemById('tlbItemAccessLevel_TlbAccessLevel_AccessGroups').set_imageUrl('access.png')94 }95 document.getElementById('txtAccessGroupName_AccessGroups').disabled = '';96 document.getElementById('txtDescription_AccessGroups').disabled = '';97 if (state == 'Edit')98 NavigateAccessGroup_AccessGroups(GridAccessGroups_AccessGroups.getSelectedItems()[0]);99 if (state == 'Delete')100 AccessGroup_onSave();101 }102 if (state == 'View') {103 if (TlbAccessGroups.get_items().getItemById('tlbItemNew_TlbAccessGroups') != null) {104 TlbAccessGroups.get_items().getItemById('tlbItemNew_TlbAccessGroups').set_enabled(true);105 TlbAccessGroups.get_items().getItemById('tlbItemNew_TlbAccessGroups').set_imageUrl('add.png');106 }107 if (TlbAccessGroups.get_items().getItemById('tlbItemEdit_TlbAccessGroups') != null) {108 TlbAccessGroups.get_items().getItemById('tlbItemEdit_TlbAccessGroups').set_enabled(true);109 TlbAccessGroups.get_items().getItemById('tlbItemEdit_TlbAccessGroups').set_imageUrl('edit.png');110 }111 if (TlbAccessGroups.get_items().getItemById('tlbItemDelete_TlbAccessGroups') != null) {112 TlbAccessGroups.get_items().getItemById('tlbItemDelete_TlbAccessGroups').set_enabled(true);113 TlbAccessGroups.get_items().getItemById('tlbItemDelete_TlbAccessGroups').set_imageUrl('remove.png');114 }115 TlbAccessGroups.get_items().getItemById('tlbItemSave_TlbAccessGroups').set_enabled(false);116 TlbAccessGroups.get_items().getItemById('tlbItemSave_TlbAccessGroups').set_imageUrl('save_silver.png');117 TlbAccessGroups.get_items().getItemById('tlbItemCancel_TlbAccessGroups').set_enabled(false);118 TlbAccessGroups.get_items().getItemById('tlbItemCancel_TlbAccessGroups').set_imageUrl('cancel_silver.png');119 if (TlbAccessLevel_AccessGroups.get_items().getItemById('tlbItemAccessLevel_TlbAccessLevel_AccessGroups') != null) {120 TlbAccessLevel_AccessGroups.get_items().getItemById('tlbItemAccessLevel_TlbAccessLevel_AccessGroups').set_enabled(false);121 TlbAccessLevel_AccessGroups.get_items().getItemById('tlbItemAccessLevel_TlbAccessLevel_AccessGroups').set_imageUrl('access_silver.png')122 }123 document.getElementById('txtAccessGroupName_AccessGroups').disabled = 'disabled';124 document.getElementById('txtDescription_AccessGroups').disabled = 'disabled';125 }126}127function SetActionMode_AccessGroups(state) {128 document.getElementById('ActionMode_AccessLevel').innerHTML = document.getElementById('ActionMode_AccessGroups').innerHTML = document.getElementById("hf" + state + "_AccessGroups").value;129}130function Fill_GridAccessGroups_AccessGroups() {131 document.getElementById('loadingPanel_GridAccessGroups_AccessGroups').innerHTML = document.getElementById('hfloadingPanel_GridAccessGroups_AccessGroups').value;132 CallBack_GridAccessGroups_AccessGroups.callback();133}134function Refresh_GridAccessGroups_AccessGroups() {135 Fill_GridAccessGroups_AccessGroups();136}137function ShowDialogConfirm(confirmState) {138 ConfirmState_AccessGroups = confirmState;139 if (CurrentPageState_AccessGroups == 'Delete')140 document.getElementById('lblConfirm').innerHTML = document.getElementById('hfDeleteMessage_AccessGroups').value;141 else {142 if (DialogAccessLevel.get_isShowing())143 document.getElementById('lblConfirm').innerHTML = document.getElementById('hfCloseMessage_AccessLevels').value;144 else145 document.getElementById('lblConfirm').innerHTML = document.getElementById('hfCloseMessage_AccessGroups').value;146 }147 DialogConfirm.Show();148}149function tlbItemOk_TlbOkConfirm_onClick() {150 switch (ConfirmState_AccessGroups) {151 case 'Delete':152 DialogConfirm.Close();153 UpdateAccessGroup_AccessGroups();154 break;155 case 'Exit':156 if (DialogAccessLevel.get_isShowing()) {157 DialogConfirm.Close();158 CloseDialogAccessLevel();159 }160 else {161 ClearList_AccessGroups();162 CloseDialogAccessGroups();163 }164 break;165 default:166 }167}168function CloseDialogAccessGroups() {169 parent.document.getElementById('DialogAccessGroups_IFrame').src = 'WhitePage.aspx';170 parent.parent.document.getElementById('DialogUnderManagementPersonnel_IFrame').contentWindow.UpdateAccessGroups_onAfterAccessGroupsChange();171 parent.DialogAccessGroups.Close();172}173function tlbItemCancel_TlbCancelConfirm_onClick() {174 DialogConfirm.Close();175 if (!DialogAccessLevel.get_isShowing())176 ChangePageState_AccessGroups('View');177}178function UpdateAccessGroup_AccessGroups() {179 ObjAccessGroup_AccessGroups = new Object();180 ObjAccessGroup_AccessGroups.Name = null;181 ObjAccessGroup_AccessGroups.Description = null;182 ObjAccessGroup_AccessGroups.AccessLevelsList = null;183 ObjAccessGroup_AccessGroups.ID = '0';184 var SelectedItems_GridAccessGroups_AccessGroups = GridAccessGroups_AccessGroups.getSelectedItems();185 if (SelectedItems_GridAccessGroups_AccessGroups.length > 0)186 ObjAccessGroup_AccessGroups.ID = SelectedItems_GridAccessGroups_AccessGroups[0].getMember("ID").get_text();187 if (CurrentPageState_AccessGroups != 'Delete') {188 ObjAccessGroup_AccessGroups.Name = document.getElementById('txtAccessGroupName_AccessGroups').value;189 ObjAccessGroup_AccessGroups.Description = document.getElementById('txtDescription_AccessGroups').value;190 ObjAccessGroup_AccessGroups.AccessLevelsList = document.getElementById('hfAccessLevelsList_AccessGroups').value;191 }192 UpdateAccessGroup_AccessGroupsPage(CharToKeyCode_AccessGroups(CurrentPageState_AccessGroups), CharToKeyCode_AccessGroups(ObjAccessGroup_AccessGroups.ID), CharToKeyCode_AccessGroups(ObjAccessGroup_AccessGroups.Name), CharToKeyCode_AccessGroups(ObjAccessGroup_AccessGroups.Description), CharToKeyCode_AccessGroups(ObjAccessGroup_AccessGroups.AccessLevelsList));193}194function UpdateAccessGroup_AccessGroupsPage_onCallBack(Response) {195 var RetMessage = Response;196 if (RetMessage != null && RetMessage.length > 0) {197 if (Response[1] == "ConnectionError") {198 Response[0] = document.getElementById('hfErrorType_AccessLevels').value;199 Response[1] = document.getElementById('hfConnectionError_AccessLevels').value;200 }201 showDialog(RetMessage[0], Response[1], RetMessage[2]);202 if (RetMessage[2] == 'success') {203 ClearList_AccessGroups();204 AccessGroup_OnAfterUpdate(Response);205 ChangePageState_AccessGroups('View');206 }207 else {208 if (CurrentPageState_AccessGroups == 'Delete')209 ChangePageState_AccessGroups('View');210 }211 }212}213function AccessGroup_OnAfterUpdate(Response) {214 if (ObjAccessGroup_AccessGroups != null) {215 var AccessGroupName = ObjAccessGroup_AccessGroups.Name;216 var AccessGroupDescription = ObjAccessGroup_AccessGroups.Description;217 var AccessGroupItem = null;218 GridAccessGroups_AccessGroups.beginUpdate();219 switch (CurrentPageState_AccessGroups) {220 case 'Add':221 AccessGroupItem = GridAccessGroups_AccessGroups.get_table().addEmptyRow(GridAccessGroups_AccessGroups.get_recordCount());222 AccessGroupItem.setValue(0, Response[3], false);223 GridAccessGroups_AccessGroups.selectByKey(Response[3], 0, false);224 break;225 case 'Edit':226 GridAccessGroups_AccessGroups.selectByKey(Response[3], 0, false);227 AccessGroupItem = GridAccessGroups_AccessGroups.getItemFromKey(0, Response[3]);228 break;229 case 'Delete':230 GridAccessGroups_AccessGroups.selectByKey(ObjAccessGroup_AccessGroups.ID, 0, false);231 GridAccessGroups_AccessGroups.deleteSelected();232 break;233 }234 if (CurrentPageState_AccessGroups != 'Delete') {235 AccessGroupItem.setValue(1, AccessGroupName, false);236 AccessGroupItem.setValue(2, AccessGroupDescription, false);237 }238 GridAccessGroups_AccessGroups.endUpdate();239 }240}241function CallBack_GridAccessGroups_AccessGroups_onCallbackComplete(sender, e) {242 var error = document.getElementById('ErrorHiddenField_AccessGroups').value;243 if (error != "") {244 var errorParts = eval('(' + error + ')');245 showDialog(errorParts[0], errorParts[1], errorParts[2]);246 if (errorParts[3] == 'Reload')247 Fill_GridAccessGroups_AccessGroups();248 }249}250function GridAccessGroups_AccessGroups_onLoad(sender, e) {251 document.getElementById('loadingPanel_GridAccessGroups_AccessGroups').innerHTML = '';252}253function tlbItemSave_TlbAccessLevel_onClick() {254 CloseDialogAccessLevel();255}256function CloseDialogAccessLevel() {257 ClearList_AccessLevel_AccessGroups();258 DialogAccessLevel.Close();259}260function ClearList_AccessLevel_AccessGroups() {261 document.getElementById('txtAccessGroupName_AccessLevel_AccessGroups').value = '';262 trvAccessLevel_AccessGroups.unCheckAll();263}264function tlbItemExit_TlbAccessLevel_onClick() {265 document.getElementById('hfAccessLevelsList_AccessGroups').value = 'null';266 ShowDialogConfirm('Exit');267}268function Refresh_trvAccessLevel_AccessGroups() {269 Fill_trvAccessLevel_AccessGroups();270}271function trvAccessLevel_AccessGroups_onNodeCheckChange(sender, e) {272 var currentNode_trvAccessLevel_AccessGroups = e.get_node();273 var checked = false;274 if (currentNode_trvAccessLevel_AccessGroups.get_checked())275 checked = true;276 if (currentNode_trvAccessLevel_AccessGroups.get_parentNode() == undefined || currentNode_trvAccessLevel_AccessGroups.get_parentNode() == null) {277 trvAccessLevel_AccessGroups.beginUpdate();278 switch (checked) {279 case true:280 currentNode_trvAccessLevel_AccessGroups.checkAll();281 break;282 case false:283 currentNode_trvAccessLevel_AccessGroups.unCheckAll();284 break;285 }286 trvAccessLevel_AccessGroups.endUpdate();287 }288 CreateAccessLevelsList_AccessGroups(currentNode_trvAccessLevel_AccessGroups, checked); 289}290function CreateAccessLevelsList_AccessGroups(accessLevelNode, checkeState) {291 var AccessLevelsList_AccessGroups = document.getElementById('hfAccessLevelsList_AccessGroups').value;292 var parentID = undefined;293 if (accessLevelNode.get_parentNode() != undefined)294 parentID = accessLevelNode.get_parentNode().get_id();295 var CurrentListPart = 'ID=' + accessLevelNode.get_id() + '%Ch=' + checkeState.toString() + '%P=' + parentID;296 var BeforeListPart = 'ID=' + accessLevelNode.get_id() + '%Ch=' + (!checkeState).toString() + '%P=' + parentID;297 if (parentID == undefined) {298 switch (checkeState) {299 case true:300 AccessLevelsList_AccessGroups = AccessLevelsList_AccessGroups.replace(new RegExp('P=' + accessLevelNode.get_id(), 'g'), 'Delete');301 AccessLevelsList_AccessGroups += CurrentListPart + '#';302 break;303 case false:304 AccessLevelsList_AccessGroups = AccessLevelsList_AccessGroups.replace(BeforeListPart + '#', '');305 AccessLevelsList_AccessGroups = AccessLevelsList_AccessGroups.replace(new RegExp('P=' + accessLevelNode.get_id(), 'g'), 'Delete');306 break;307 }308 }309 else {310 var NodeChecked = accessLevelNode.get_parentNode().get_checked();311 if (NodeChecked == true || NodeChecked == 1) {312 switch (checkeState) {313 case true:314 AccessLevelsList_AccessGroups = AccessLevelsList_AccessGroups.replace(BeforeListPart + '#', '');315 break;316 case false:317 AccessLevelsList_AccessGroups += CurrentListPart + '#';318 break;319 }320 }321 else {322 if (NodeChecked == false || NodeChecked == 0) {323 switch (checkeState) {324 case true:325 AccessLevelsList_AccessGroups = AccessLevelsList_AccessGroups.replace('ID=' + accessLevelNode.get_id() + '%Ch=' + true.toString() + '%Delete', '');326 AccessLevelsList_AccessGroups += CurrentListPart + '#';327 break;328 case false:329 AccessLevelsList_AccessGroups = AccessLevelsList_AccessGroups.replace(BeforeListPart + '#', '');330 break;331 }332 }333 else {334 if (NodeChecked == undefined) {335 switch (checkeState) {336 case true:337 AccessLevelsList_AccessGroups += CurrentListPart + '#';338 break;339 case false:340 AccessLevelsList_AccessGroups = AccessLevelsList_AccessGroups.replace(BeforeListPart + '#', '');341 break;342 }343 }344 }345 }346 }347 document.getElementById('hfAccessLevelsList_AccessGroups').value = AccessLevelsList_AccessGroups;348}349function trvAccessLevel_AccessGroups_onLoad(sender, e) {350 document.getElementById('loadingPanel_trvAccessLevel_AccessGroups').innerHTML = '';351}352function CallBack_trvAccessLevel_AccessGroups_onCallbackComplete(sender, e) {353 var error = document.getElementById('ErrorHiddenField_AccessLevel').value;354 if (error != "") {355 var errorParts = eval('(' + error + ')');356 showDialog(errorParts[0], errorParts[1], errorParts[2]);357 if (errorParts[3] == 'Reload')358 Fill_trvAccessLevel_AccessGroups();359 }360}361function Fill_trvAccessLevel_AccessGroups() {362 var AccessGroupID = '0';363 document.getElementById('loadingPanel_trvAccessLevel_AccessGroups').innerHTML = document.getElementById('hfloadingPanel_trvAccessLevel_AccessGroups').value;364 var selectedItems_GridAccessGroups_AccessGroups = GridAccessGroups_AccessGroups.getSelectedItems();365 if (CurrentPageState_AccessGroups == 'Edit')366 AccessGroupID = selectedItems_GridAccessGroups_AccessGroups[0].getMember('ID').get_text();367 CallBack_trvAccessLevel_AccessGroups.callback(CharToKeyCode_AccessGroups(AccessGroupID));368}369function DialogAccessLevel_OnShow(sender, e) {370 document.getElementById('Title_DialogAccessLevel').innerHTML = document.getElementById('hfTitle_DialogAccessLevel').value;371 SetAccessGroupTitle_AccessGroups();372 var CurrentLangID = parent.parent.CurrentLangID;373 if (CurrentLangID == 'fa-IR') {374 document.getElementById('DialogAccessLevel_topLeftImage').src = 'Images/Dialog/top_right.gif';375 document.getElementById('DialogAccessLevel_topRightImage').src = 'Images/Dialog/top_left.gif';376 document.getElementById('DialogAccessLevel_downLeftImage').src = 'Images/Dialog/down_right.gif';377 document.getElementById('DialogAccessLevel_downRightImage').src = 'Images/Dialog/down_left.gif';378 document.getElementById('CloseButton_DialogAccessLevel').align = 'left';379 }380 if (CurrentLangID == 'en-US')381 document.getElementById('CloseButton_DialogAccessLevel').align = 'right';382 Fill_trvAccessLevel_AccessGroups();383}384function tlbItemAccessLevel_TlbAccessLevel_AccessGroups_onClick() {385 if (CurrentPageState_AccessGroups == 'Add' || (CurrentPageState_AccessGroups == 'Edit' && GridAccessGroups_AccessGroups.getSelectedItems().length > 0))386 ShowDialogAccessLevel();387}388function ShowDialogAccessLevel() {389 DialogAccessLevel.Show();390}391function SetAccessGroupTitle_AccessGroups() { 392 var AccessGroupTitle = '';393 switch (CurrentPageState_AccessGroups) {394 case 'Add':395 if (document.getElementById('txtAccessGroupName_AccessGroups').value != '')396 AccessGroupTitle = document.getElementById('txtAccessGroupName_AccessGroups').value;397 break;398 case 'Edit':399 if (GridAccessGroups_AccessGroups.getSelectedItems().length > 0)400 AccessGroupTitle = GridAccessGroups_AccessGroups.getSelectedItems()[0].getMember('Name').get_text();401 break;402 }403 document.getElementById('txtAccessGroupName_AccessLevel_AccessGroups').value = AccessGroupTitle;404}405function CallBack_GridAccessGroups_AccessGroups_onCallbackError(sender, e) {406 document.getElementById('loadingPanel_GridAccessGroups_AccessGroups').innerHTML = '';407 ShowConnectionError_AccessLevels();408}409function ShowConnectionError_AccessLevels() {410 var error = document.getElementById('hfErrorType_AccessLevels').value;411 var errorBody = document.getElementById('hfConnectionError_AccessLevels').value;412 showDialog(error, errorBody, 'error');413}414function CallBack_trvAccessLevel_AccessGroups_onCallbackError(sender, e) {415 ShowConnectionError_AccessLevels();416}417function tlbItemFormReconstruction_TlbAccessGroups_onClick() {418 CloseDialogAccessGroups();419 parent.parent.document.getElementById('DialogUnderManagementPersonnel_IFrame').contentWindow.CollapseControls_UnderManagementPersonnel();420 parent.parent.document.getElementById('DialogUnderManagementPersonnel_IFrame').contentWindow.ShowDialogAccessGroups();421}422function tlbItemHelp_TlbAccessGroups_onClick() {423 LoadHelpPage('tlbItemHelp_TlbAccessGroups');...
user.team.access.controller.js
Source:user.team.access.controller.js
1'use strict';2(function () {3 angular.module('adams.user.administration.team.access.modal.controller', ['common.modules.logging'])4 .controller('UserTeamAccessController', ['$rootScope', '$scope', '$uibModalInstance', '$interval', 'ModalDialogService', 'loginAppName', 'loginRoleName', 'applications', 'defaultApplication', 'loginRoles', 'userRoles', 'userName', 'roleName', 'UserAdministrationService', 'ADAMS_CONSTANTS', '$timeout', '$log',5 function($rootScope, $scope, $uibModalInstance, $interval, ModalDialogService, loginAppName, loginRoleName, applications, defaultApplication, loginRoles, userRoles, userName, roleName, UserAdministrationService, ADAMS_CONSTANTS, $timeout, $log) {6 var userTeamAccessController = this,7 userSearchGridPromise;8 $scope.$on('hierarchyTreeTeamSelectionChange', function($event, refId, isSelected, node) {9 if(userTeamAccessController.teams.length > 0){10 if (node.team_id === '1') {11 userTeamAccessController.teams = [];12 userTeamAccessController.teams.push(node);13 return;14 }15 if (userTeamAccessController.contains(node.team_display_name, node.team_display_path)) {16 return;17 }18 else {19 userTeamAccessController.teams.push(node);20 }21 }22 else {23 userTeamAccessController.teams.push(node);24 }25 userTeamAccessController.teams.sort();26 if(userTeamAccessController.role && userTeamAccessController.role.length > 0) {27 userTeamAccessController.checkforParent();28 }29 });30 function initialize() {31 userTeamAccessController.teams = [];32 userTeamAccessController.searchTeamName = '';33 userTeamAccessController.searchTeamDescription = '';34 userTeamAccessController.searchTeamType = '';35 userTeamAccessController.applications = angular.copy(applications);36 userTeamAccessController.application = defaultApplication || userTeamAccessController.applications[0].name;37 userTeamAccessController.userRoles = userRoles;38 userTeamAccessController.loginRoles = loginRoles;39 userTeamAccessController.loginUserApp = loginAppName;40 userTeamAccessController.loginUserRole = loginRoleName;41 if(roleName) {42 userTeamAccessController.roleName = '';43 userTeamAccessController.role = ' ';44 }45 else {46 userTeamAccessController.roleName = roleName;47 userTeamAccessController.role = roleName;48 }49 userTeamAccessController.hierarchyTeam = false;50 userTeamAccessController.gridOptions = defineUserSearchGridOptions();51 userTeamAccessController.messageFieldConfig = {52 height: 175,53 toolbar: [54 ['style', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']],55 ['textsize', ['fontsize']],56 ['fontclr', ['color']],57 ['alignment', ['ul', 'ol', 'paragraph', 'lineheight']],58 ['height', ['height']],59 ['table', ['table']],60 ['insert', ['link','video','hr']],61 ['view', ['codeview']]62 ]63 };64 }65 userTeamAccessController.getGridData = function(pageSize, pageNumber, sort, searchInput) {66 userTeamAccessController.searchTeamName = getSearchValue(searchInput, "team_name");67 userTeamAccessController.searchTeamDescription = getSearchValue(searchInput, "team_description");68 userTeamAccessController.searchTeamType = getSearchValue(searchInput, "team_type_name");69 return UserAdministrationService.getHierarchicalTeams(pageSize, pageNumber, userTeamAccessController.loginUserApp, userTeamAccessController.loginUserRole,70 userTeamAccessController.searchTeamName, userTeamAccessController.searchTeamDescription, userTeamAccessController.searchTeamType, sort);71 };72 function getSearchValue(searchInput, propertyName){73 var value = "";74 if(searchInput && angular.isArray(searchInput.search)){75 angular.forEach(searchInput.search, function(searchObject){76 if(searchObject.property === propertyName){77 value = searchObject.value || "";78 }79 });80 }81 return value;82 }83 userTeamAccessController.itemSelected = function (index) {84 if(index === 1) {85 userTeamAccessController.application = userTeamAccessController.application.name;86 userTeamAccessController.getLoginUserRoles();87 }88 else {89 userTeamAccessController.role = userTeamAccessController.role.name;90 userTeamAccessController.checkforParent();91 }92 };93 userTeamAccessController.teamIndex = function(index) {94 userTeamAccessController.teams.splice(index, 1);95 };96 userTeamAccessController.checkforParent = function() {97 if (userTeamAccessController.teams.length > 0) {98 userTeamAccessController.message = '';99 userTeamAccessController.removedTeams = [];100 userTeamAccessController.selectedRoles = [];101 userTeamAccessController.selectedRoles.push({name: userTeamAccessController.role, teams: []});102 for (var i = 0; i < userTeamAccessController.teams.length; i++) {103 userTeamAccessController.selectedRoles[0].teams.push({team_display_name: userTeamAccessController.teams[i].team_display_name, team_display_path: userTeamAccessController.teams[i].team_display_path});104 }105 for (var j = 0; j < userTeamAccessController.selectedRoles[0].teams.length; j++) {106 var teams = userTeamAccessController.selectedRoles[0].teams;107 userTeamAccessController.clearChildTeam(teams[j].team_display_name, teams[j].team_display_path);108 }109 if(userTeamAccessController.removedTeams.length > 0) {110 for (var k = 0; k < userTeamAccessController.removedTeams.length; k++) {111 userTeamAccessController.message += '<br>' + userTeamAccessController.removedTeams[k];112 }113 ModalDialogService.alert({114 bodyHTML: 'User already have access to Parent Team(s) for the following team(s): <br>' + userTeamAccessController.message,115 title: 'Selected Teams',116 size: 'md'117 });118 }119 }120 };121 userTeamAccessController.clearChildTeam = function (text, path) {122 for (var x=0; x < userTeamAccessController.userRoles.length; x++) {123 var roles = userTeamAccessController.userRoles[x];124 if (userTeamAccessController.role === roles.name) {125 for (var i=0; i < roles.teams.length; i++) {126 if (path.includes(roles.teams[i].team_display_path) || roles.teams[i].team_name + '-' + roles.teams[i].team_description === text) {127 for(var y=0; y < userTeamAccessController.teams.length; y++) {128 if(userTeamAccessController.teams[y].team_display_name === text) {129 userTeamAccessController.teams.splice(y, 1);130 userTeamAccessController.removedTeams.push(text);131 break;132 }133 }134 }135 }136 }137 }138 };139 userTeamAccessController.contains = function (text, path) {140 for (var i=0; i < userTeamAccessController.teams.length; i++) {141 if (userTeamAccessController.teams[i].team_display_name === text || path.includes(userTeamAccessController.teams[i].team_display_path)) {142 return true;143 }144 else if (userTeamAccessController.teams[i].team_display_path.includes(path)) {145 userTeamAccessController.teams.splice(i, 1);146 i--;147 }148 }149 return false;150 };151 userTeamAccessController.getLoginUserRoles = function() {152 UserAdministrationService.getRolesByLoginUser(userTeamAccessController.application, loginRoleName).then(153 function(data){154 if (data) {155 if (data === 'error') {156 userTeamAccessController.loginRoles = [];157 }158 else {159 userTeamAccessController.loginRoles = data;160 userTeamAccessController.role = ' ';161 }162 163 } else {164 userTeamAccessController.loginRoles = [];165 }166 167 },168 function(){169 $log.error("An error occurred while getting login user roles data");170 });171 };172 userTeamAccessController.close = function() {173 $uibModalInstance.dismiss('cancel');174 };175 userTeamAccessController.submit = function() {176 $uibModalInstance.close({selectedTeam: userTeamAccessController.teams[0].team_name});177 };178 userTeamAccessController.switchTab = function(id) {179 if(id === 'hierarchyTeam')180 {181 userTeamAccessController.hierarchyTeam = true;182 }183 else {184 userTeamAccessController.hierarchyTeam = false;185 }186 };187 $scope.$on('uiGridLoadDetails', function ($event, gridOptions, gridApi) {188 // emitted gridOptions and gridApi from Directive controller189 userTeamAccessController.gridApi = gridApi;190 });191 $scope.$on('uiGridSelectedRows', function ($event, mySelectedRows, selectionEvent) {192 // emitted selected rows from Directive controller193 if (selectionEvent) {194 var elemClass = selectionEvent.target.className || selectionEvent.srcElement.className;195 if(elemClass.includes("ui-grid-icon-plus-squared") || elemClass.includes("ui-grid-icon-minus-squared")) {196 userTeamAccessController.gridApi.selection.unSelectRow(mySelectedRows[0]);197 }198 else {199 handleRowSelectionChange(mySelectedRows);200 }201 }202 });203 /** PRIVATE FUNCTIONS **/204 function defineUserSearchGridOptions() {205 return {206 paginationPageSizes: [25, 50, 75],207 paginationPageSize: 25, // pagination out of box208 virtualizationThreshold: 25,209 useExternalPagination: true,210 useExternalFiltering: true,211 enableFiltering: true, //step1 to enable all grid columns filtering212 enableRowSelection: true,213 enableRowHeaderSelection: false,214 multiSelect: false,215 modifierKeysToMultiSelect: false,216 noUnselect: false,217 showColumnFooter: false,218 treeRowHeaderAlwaysVisible: true,219 enableGridMenu: true, //true will display grid menu on top-right220 enableSorting: true,221 enableExpandable: true,222 enableExpandableRowHeader : true,223 expandableRowTemplate: '<div team-display-path team-path="row.entity.team_display_path"></div>',224 expandableRowHeight: 125,225 //subGridVariable will be available in subGrid scope226 expandableRowScope: {227 subGridVariable: 'subGridScopeVariable'228 },229 columnDefs: [230 { field: 'team_name',231 displayName: "Team Name",232 minWidth: 100,233 filter: {234 placeholder: ''235 }236 },237 { field: 'team_description',238 displayName: "Description",239 minWidth: 200,240 filter: {241 placeholder: ''242 }243 },244 { field: 'team_type_name',245 displayName: "Type",246 minWidth: 100,247 filter: {248 placeholder: ''249 }250 }251 ]252 };253 }254 function handleRowSelectionChange(selectedRows) {255 //Do something when a row is selected256 var node = selectedRows[0];257 if(node) {258 if(userTeamAccessController.teams.length > 0){259 if (userTeamAccessController.contains(node.team_name + ' - ' + node.team_description, node.team_display_path)) {260 return;261 }262 else {263 userTeamAccessController.teams.push(node);264 }265 }266 else {267 userTeamAccessController.teams.push(node);268 }269 }270 if (userTeamAccessController.teams.length > 0) {271 for (var i = 0; i < userTeamAccessController.teams.length; i++) {272 userTeamAccessController.teams[i].team_display_name = userTeamAccessController.teams[i].team_name + ' - ' +273 userTeamAccessController.teams[i].team_description;274 }275 }276 if(userTeamAccessController.role.length > 0) {277 userTeamAccessController.checkforParent();278 }279 }280 initialize();281 }282 ]);...
whitelist.js
Source:whitelist.js
1/*2 *3 * Licensed to the Apache Software Foundation (ASF) under one4 * or more contributor license agreements. See the NOTICE file5 * distributed with this work for additional information6 * regarding copyright ownership. The ASF licenses this file7 * to you under the Apache License, Version 2.0 (the8 * "License"); you may not use this file except in compliance9 * with the License. You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing,14 * software distributed under the License is distributed on an15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY16 * KIND, either express or implied. See the License for the17 * specific language governing permissions and limitations18 * under the License.19 *20*/21var WebFolderAccess = require("./folderAccess").WebFolderAccess,22 util = require("../utils");23function _isLocalAccess(access) {24 return access && access.uri === "WIDGET_LOCAL";25}26function _isMatch(access, requestURI) {27 // Look for local first28 if (_isLocalAccess(access)) {29 // Local access always allowed30 //THIS USED TO RETURN TRUE FOR FILE ACCESS31 //I HAVE TURNED IT OFF BECAUSE IT MAKES NO SENSE THAT LOCAL ACCESS ALWAYS MATCHES FILE ACCESS32 return (util.isLocalURI(requestURI));33 } else if (util.isDataURI(requestURI)) {34 // Check for data url35 // data urls are allowed36 return true;37 }38 // Based on widgets 1.0 (access control)39 // http://www.w3.org/TR/2009/WD-widgets-access-20090618/#rfc398740 var refURI = util.parseUri(access.uri),41 allowSub = access.allowSubDomain;42 if (!requestURI.path) {43 requestURI.path = "/";44 }45 // Start comparison based on widget spec.46 // 1. Compare scheme47 if (refURI.scheme.toLowerCase() !== requestURI.scheme.toLowerCase()) {48 return false;49 }50 // 2. Compare host - if subdomain is false, host must match exactly51 // (referenceURI MUST HAVE host specified - not null.)52 // Special Case: Ignore this condition if we are dealing with file://53 if (!requestURI.authority && !util.isFileURI(requestURI)) {54 return false;55 }56 if (!allowSub && refURI.host.toLowerCase() !== requestURI.host.toLowerCase()) {57 return false;58 }59 // 3. Compare host - if subdomain is true, check for subdomain or match60 if (allowSub && !util.endsWith(requestURI.host.toLowerCase(), "." + refURI.host.toLowerCase()) &&61 requestURI.host.toLowerCase() !== refURI.host.toLowerCase()) {62 return false;63 }64 // 4. Compare port65 if (refURI.port && refURI.port !== requestURI.port) {66 return false;67 }68 // 5. Compare path+query69 if (!util.startsWith(requestURI.path.toLowerCase(), refURI.path.toLowerCase()) && refURI.query !== "*") {70 return false;71 }72 return true;73}74function _getAccessForPathAndQuery(folderAccess, path, query) {75 if (folderAccess) {76 if (!query) {77 return folderAccess.getAccess(path);78 } else {79 return folderAccess.getAccess(path + "?" + query);80 }81 }82 return null;83}84function AccessManager(config) {85 config = config || require("../config");86 this._accessList = config.accessList;87 this._hasGlobalAccess = config.hasMultiAccess;88 this._authorityCollection = null;89 this._localAccess = null;90}91AccessManager.prototype.getFolderAccess = function (scheme, authority) {92 var key = scheme + "://" + authority;93 key = key.toLowerCase();94 if (this._authorityCollection.hasOwnProperty(key)) {95 return this._authorityCollection[key];96 }97 return null;98};99AccessManager.prototype.putFolderAccess = function (scheme, authority, folderAccess) {100 var key = scheme + "://" + authority;101 key = key.toLowerCase();102 this._authorityCollection[key] = folderAccess;103};104AccessManager.prototype.initializeAuthCollection = function () {105 var folderAccess, currentURI, that = this;106 if (!this._authorityCollection) {107 this._authorityCollection = {};108 if (this._accessList) {109 this._accessList.forEach(function (access) {110 if (_isLocalAccess(access)) {111 that._localAccess = access;112 } else {113 currentURI = util.parseUri(access.uri);114 // Check the authority collection to see if the authority item115 // we want already exists116 folderAccess = that.getFolderAccess(currentURI.scheme, currentURI.authority) || new WebFolderAccess();117 // Add folder path access to the authority item118 if (!currentURI.query) {119 folderAccess.addAccess(currentURI.path, access);120 } else {121 folderAccess.addAccess(currentURI.path + "?" + currentURI.query, access);122 }123 that.putFolderAccess(currentURI.scheme, currentURI.authority, folderAccess);124 }125 });126 }127 }128};129AccessManager.prototype.authorityCheck = function (port, scheme, authority) {130 var originalAuthority = authority;131 if (port) {132 // If authority has a specific port, and the collection does not have an access matches133 // the exact authority, strip port from authority to see if there is a match134 if (!this.getFolderAccess(scheme, authority)) {135 authority = authority.slice(0, authority.lastIndexOf(":"));136 authority = this.authorityCheck("", scheme, authority);137 }138 //If no successful match was found without the port, reset the authority and try with it139 if (!this.getFolderAccess(scheme, authority)) {140 authority = originalAuthority;141 }142 }143 if (authority.indexOf(".") === -1) {144 // If authority is computer name, must have exact match in collection145 if (!this.getFolderAccess(scheme, authority)) {146 return "";147 }148 return authority;149 }150 while (authority && !this.getFolderAccess(scheme, authority)) {151 if (authority.indexOf(".") === -1) {152 return "";153 }154 authority = authority.substring(authority.indexOf(".") + 1);155 }156 return authority;157};158AccessManager.prototype.getFromFolderAccess = function (folderAccess, requestURI) {159 var fetchedAccess = null,160 scheme = requestURI.scheme,161 authority = requestURI.authority,162 path = requestURI.path,163 query = requestURI.query,164 prevAuthority;165 if (!path) {166 fetchedAccess = folderAccess.getAccess("/");167 } else {168 fetchedAccess = _getAccessForPathAndQuery(folderAccess, path, query);169 }170 // Make sure we've got the right one171 while (!fetchedAccess || !_isMatch(fetchedAccess, requestURI)) {172 // There was an auth url that matched, but didnt match the folder structure173 // Try the next level up174 prevAuthority = authority;175 authority = authority.substring(authority.indexOf(".") + 1);176 //If authority hasn't changed, then this loop will continue endlessly because nothing else has changed177 //This will happen when an element has the same authority but no folder access.178 if (prevAuthority === authority) {179 return null;180 }181 // Check for an authority string that has an existing key182 authority = this.authorityCheck(requestURI.port, scheme, authority);183 if (!authority) {184 return null;185 }186 // Retrieve access set for the specified authority187 folderAccess = this.getFolderAccess(scheme, authority);188 // Special case: no access element was found for a file protocol request.189 // This is added since file protocol was allowed through the above check190 if (scheme === "file" && !folderAccess) {191 return null;192 }193 fetchedAccess = _getAccessForPathAndQuery(folderAccess, path, query);194 }195 return fetchedAccess;196};197AccessManager.prototype.getAccessByUrl = function (url) {198 var requestURI = util.parseUri(url),199 authority = requestURI.authority,200 scheme = requestURI.scheme,201 folderAccess,202 fetchedAccess;203 if (util.isAbsoluteURI(requestURI)) {204 // Initialize authority collection if it does not yet exist205 this.initializeAuthCollection();206 // Start with the full authority path and check if an access exists for that path207 // If it does not exist, remove the first section of the authority path and try again208 // Check for an authority string that has an existing key209 // Special case: Allow file, and local protocol to proceed without an authority210 authority = this.authorityCheck(requestURI.port, scheme, authority);211 if (!authority && !(scheme === "file" || scheme === "local" || scheme === "data")) {212 return null;213 }214 // Retrieve access set for the specified authority215 folderAccess = this.getFolderAccess(scheme, authority);216 // Special case: no access was found for a file protocol request217 // This is added since file protocol was allowed through the above check218 if (scheme === "file" && !folderAccess) {219 return null;220 } else if (scheme === "local" && !folderAccess) {221 // If no access element is found with local URI, use local access for this request222 return this._localAccess;223 } else if (scheme === "data") {224 // Always allow data-uris225 return true;226 }227 fetchedAccess = this.getFromFolderAccess(folderAccess, requestURI);228 if (fetchedAccess) {229 return fetchedAccess;230 } else if (this._localAccess && _isMatch(this._localAccess, requestURI)) {231 // If we cannot find a more specific access for this local URI, use local access232 return this._localAccess;233 } else if (folderAccess && _isMatch(folderAccess, requestURI)) {234 return folderAccess;235 }236 }237 return null;238};239AccessManager.prototype.hasGlobalAccess = function () {240 return this._hasGlobalAccess;241};242function Whitelist(config) {243 this._mgr = new AccessManager(config);244}245Whitelist.prototype.getFeaturesForUrl = function (url) {246 var access = this._mgr.getAccessByUrl(url),247 featureIds = [];248 if (access && access.features) {249 access.features.forEach(function (elem) {250 featureIds.push(elem.id);251 });252 }253 return featureIds;254};255Whitelist.prototype.isFeatureAllowed = function (url, feature) {256 var features = this.getFeaturesForUrl(url);257 return !!features && features.reduce(function (found, current) {258 return found || current === feature;259 }, false);260};261Whitelist.prototype.isAccessAllowed = function (url, isXHR) {262 return (this._mgr.hasGlobalAccess() && !isXHR) || !!this._mgr.getAccessByUrl(url);263};...
Using AI Code Generation
1const qawolf = require("qawolf");2const selectors = require("./selectors/test.json");3describe("test", () => {4 let browser;5 beforeAll(async () => {6 browser = await qawolf.launch();7 });8 afterAll(async () => {9 await qawolf.stopVideos();10 await browser.close();11 });12 it("test", async () => {13 const context = await browser.newContext();14 const page = await context.newPage();15 await qawolf.scroll(page, "html", { x: 0, y: 200 });16 await page.click(selectors["#tsf > div:nth-child(2) > div > div.FPdoLc.lJ9FBc > center > input.gNO89b"]);17 await qawolf.scroll(page, "html", { x: 0, y: 200 });18 await page.click(selectors["#tsf > div:nth-child(2) > div > div.FPdoLc.lJ9FBc > center > input.gNO89b"]);19 await qawolf.scroll(page, "html", { x: 0, y: 200 });20 await page.click(selectors["#tsf > div:nth-child(2) > div > div.FPdoLc.lJ9FBc > center > input.gNO89b"]);21 await qawolf.scroll(page, "html", { x: 0, y: 200 });22 await page.click(selectors["#tsf > div:nth-child(2) > div > div.FPdoLc.lJ9FBc > center > input.gNO89b"]);23 await qawolf.scroll(page, "html", { x: 0, y: 200 });24 await page.click(selectors["#tsf > div:nth-child(2) > div > div.FPdoLc.lJ9FBc > center > input.gNO89b"]);25 await qawolf.scroll(page, "html", { x: 0, y: 200 });26 await page.click(selectors["#tsf > div:nth-child(2) > div > div.FPdoLc.lJ9FBc > center > input.gNO89b"]);27 await qawolf.scroll(page, "html", { x: 0, y:
Using AI Code Generation
1const { launch } = require("qawolf");2const selectors = require("../selectors/test");3describe("test", () => {4 let browser;5 let page;6 beforeAll(async () => {7 page = await browser.newPage();8 });9 afterAll(async () => {10 await browser.close();11 });
Using AI Code Generation
1const { launch } = require('qawolf');2const selectors = require('./selectors/test.json');3describe('test', () => {4 let browser;5 let page;6 beforeAll(async () => {7 browser = await launch();8 });9 afterAll(async () => {10 await browser.close();11 });12 beforeEach(async () => {13 page = await browser.newPage();14 });15 afterEach(async () => {16 await page.close();17 });18 it('test', async () => {19 await page.click(selectors['#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input']);20 await page.fill(selectors['#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input'], 'test');21 await page.click(selectors['#tsf > div:nth-child(2) > div > div.FPdoLc.VlcLAe > center > input.gNO89b']);22 });23});24Error: Failed to find element matching selector "#tsf > div:nth-child(2) > div > div.RNNXgb > div > div.a4bIc > input"25await page.click(selectors['input[name="q"]']);
Using AI Code Generation
1const qawolf = require("qawolf");2const browser = await qawolf.launch();3const context = await browser.newContext();4const page = await context.newPage();5await qawolf.stopVideos();6await browser.close();7await qawolf.create();8await qawolf.createCode();9const qawolf = require("qawolf");10const browser = await qawolf.launch();11const context = await browser.newContext();12const page = await context.newPage();13await qawolf.stopVideos();14await browser.close();15await qawolf.create();16await qawolf.createCode();17await qawolf.create();18const qawolf = require("qawolf");19const browser = await qawolf.launch();20const context = await browser.newContext();21const page = await context.newPage();22await qawolf.stopVideos();23await browser.close();24await qawolf.create();25await qawolf.createCode();26await qawolf.create();27await qawolf.create();28const qawolf = require("qawolf");29const browser = await qawolf.launch();30const context = await browser.newContext();31const page = await context.newPage();32await qawolf.stopVideos();33await browser.close();34await qawolf.create();35await qawolf.createCode();36await qawolf.create();37await qawolf.create();38await qawolf.create();39const qawolf = require("qawolf");40const browser = await qawolf.launch();41const context = await browser.newContext();42const page = await context.newPage();43await qawolf.stopVideos();44await browser.close();
Using AI Code Generation
1const qawolf = require("qawolf");2const puppeteer = require("puppeteer");3const fs = require("fs");4const path = require("path");5const os = require("os");6const child_process = require("child_process");7const request = require("request");8const express = require("express");9const bodyParser = require("body-parser");10const rp = require("request-promise");11const fetch = require("node-fetch");12const axios = require("axios");13const cheerio = require("cheerio");14const jsdom = require("jsdom");15const puppeteerExtra = require("puppeteer-extra");16const StealthPlugin = require("puppeteer-extra-plugin-stealth");17const RecaptchaPlugin = require("puppeteer-extra-plugin-recaptcha");18const AdblockerPlugin = require("puppeteer-extra-plugin-adblocker");19const AnonymizeUaPlugin = require("puppeteer-extra-plugin-anonymize-ua");20const UserPreferencesPlugin = require("puppeteer-extra-plugin-user-preferences");21const UserDataPlugin = require("puppeteer-extra-plugin-user-data");22const BlockResourcesPlugin = require("puppeteer-extra-plugin-block-resources");23const FlashPlugin = require("p
Using AI Code Generation
1const qawolf = require('qawolf');2const browser = await qawolf.launch();3const qawolf = require('qawolf');4const browser = await qawolf.launch();5const qawolf = require('qawolf');6const browser = await qawolf.launch();7const qawolf = require('qawolf');8const browser = await qawolf.launch();9const qawolf = require('qawolf');10const browser = await qawolf.launch();11const qawolf = require('qawolf');12const browser = await qawolf.launch();13const qawolf = require('qawolf');14const browser = await qawolf.launch();15const qawolf = require('qawolf');16const browser = await qawolf.launch();17const qawolf = require('qawolf');18const browser = await qawolf.launch();19const qawolf = require('qawolf');20const browser = await qawolf.launch();21const qawolf = require('qawolf');22const browser = await qawolf.launch();
Using AI Code Generation
1const { test, expect } = require("@playwright/test");2const { launch } = require("qawolf");3const { describe, it } = require("mocha");4describe("Test", () => {5 it("test", async () => {6 const browser = await launch();7 const context = await browser.newContext();8 const page = await context.newPage();9 await page.click("text=Login");10 await page.fill("input[name=email]", "
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!