configeditor-settings.js 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682
  1. /*
  2. * Password Management Servlets (PWM)
  3. * http://code.google.com/p/pwm/
  4. *
  5. * Copyright (c) 2006-2009 Novell, Inc.
  6. * Copyright (c) 2009-2015 The PWM Project
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. "use strict";
  23. var PWM_CFGEDIT = PWM_CFGEDIT || {};
  24. var PWM_CONFIG = PWM_CONFIG || {};
  25. var PWM_MAIN = PWM_MAIN || {};
  26. var PWM_VAR = PWM_VAR || {};
  27. var PWM_SETTINGS = PWM_SETTINGS || {};
  28. PWM_VAR['clientSettingCache'] = { };
  29. // -------------------------- locale table handler ------------------------------------
  30. var LocalizedStringValueHandler = {};
  31. LocalizedStringValueHandler.init = function(keyName, regExPattern, syntax) {
  32. console.log('LocalizedStringValueHandler init for ' + keyName);
  33. var parentDiv = 'table_setting_' + keyName;
  34. PWM_MAIN.getObject(parentDiv).innerHTML = '<table id="tableTop_' + keyName + '" style="border-width:0">';
  35. parentDiv = PWM_MAIN.getObject('tableTop_' + keyName);
  36. PWM_VAR['clientSettingCache'][keyName + "_regExPattern"] = regExPattern;
  37. PWM_VAR['clientSettingCache'][keyName + "_syntax"] = syntax;
  38. PWM_VAR['clientSettingCache'][keyName + "_parentDiv"] = parentDiv;
  39. PWM_CFGEDIT.clearDivElements(parentDiv, true);
  40. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  41. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  42. LocalizedStringValueHandler.draw(keyName);
  43. });
  44. };
  45. LocalizedStringValueHandler.draw = function(keyName) {
  46. var parentDiv = PWM_VAR['clientSettingCache'][keyName + "_parentDiv"];
  47. var regExPattern = PWM_VAR['clientSettingCache'][keyName + "_regExPattern"];
  48. var syntax = PWM_VAR['clientSettingCache'][keyName + "_syntax"];
  49. require(["dojo/parser","dijit/form/Button","dijit/form/Textarea","dijit/form/ValidationTextBox"],function(dojoParser){
  50. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  51. PWM_CFGEDIT.clearDivElements(parentDiv, false);
  52. for (var i in resultValue) {
  53. LocalizedStringValueHandler.addLocaleTableRow(parentDiv, keyName, i, resultValue[i], regExPattern, syntax)
  54. }
  55. PWM_CFGEDIT.addAddLocaleButtonRow(parentDiv, keyName, function(localeKey) {
  56. LocalizedStringValueHandler.addLocaleSetting(keyName, localeKey);
  57. });
  58. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  59. dojoParser.parse(parentDiv);
  60. });
  61. };
  62. LocalizedStringValueHandler.addLocaleTableRow = function(parentDiv, settingKey, localeString, value, regExPattern, syntax) {
  63. var inputID = 'value-' + settingKey + '-' + localeString;
  64. // clear the old dijit node (if it exists)
  65. PWM_MAIN.clearDijitWidget(inputID);
  66. var newTableRow = document.createElement("tr");
  67. newTableRow.setAttribute("style", "border-width: 0");
  68. var td1 = document.createElement("td");
  69. td1.setAttribute("style", "border-width: 0; width: 15px");
  70. if (localeString == null || localeString.length < 1) {
  71. td1.innerHTML = "";
  72. } else {
  73. td1.innerHTML = localeString;
  74. }
  75. newTableRow.appendChild(td1);
  76. var td2 = document.createElement("td");
  77. td2.setAttribute("style", "border-width: 0");
  78. if (syntax == 'LOCALIZED_TEXT_AREA') {
  79. var textAreaElement = document.createElement("textarea");
  80. textAreaElement.setAttribute("id", inputID);
  81. textAreaElement.setAttribute("value", PWM_MAIN.showString('Display_PleaseWait'));
  82. textAreaElement.setAttribute("onchange", "LocalizedStringValueHandler.writeLocaleSetting('" + settingKey + "','" + localeString + "',this.value)");
  83. textAreaElement.setAttribute("style", "width: 510px; max-width:510px; max-height: 300px; overflow: auto; white-space: nowrap");
  84. textAreaElement.setAttribute("data-dojo-type", "dijit.form.Textarea");
  85. textAreaElement.setAttribute("value", value);
  86. td2.appendChild(textAreaElement);
  87. } else {
  88. var inputElement = document.createElement("input");
  89. inputElement.setAttribute("id", inputID);
  90. inputElement.setAttribute("value", PWM_MAIN.showString('Display_PleaseWait'));
  91. inputElement.setAttribute("onchange", "LocalizedStringValueHandler.writeLocaleSetting('" + settingKey + "','" + localeString + "',this.value)");
  92. inputElement.setAttribute("style", "width: 510px;");
  93. inputElement.setAttribute("data-dojo-type", "dijit.form.ValidationTextBox");
  94. inputElement.setAttribute("regExp", regExPattern);
  95. inputElement.setAttribute("value", value);
  96. td2.appendChild(inputElement);
  97. }
  98. newTableRow.appendChild(td2);
  99. if (localeString != null && localeString.length > 0) {
  100. var imgElement = document.createElement("div");
  101. imgElement.setAttribute("style", "width: 10px; height: 10px;");
  102. imgElement.setAttribute("class", "delete-row-icon action-icon fa fa-times");
  103. imgElement.setAttribute("id", "button-" + settingKey + '-' + localeString + "-deleteRow");
  104. imgElement.setAttribute("onclick", "LocalizedStringValueHandler.removeLocaleSetting('" + settingKey + "','" + localeString + "','" + parentDiv + "','" + regExPattern + "','" + syntax + "')");
  105. td2.appendChild(imgElement);
  106. }
  107. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  108. parentDivElement.appendChild(newTableRow);
  109. PWM_MAIN.addEventHandler("button-" + settingKey + '-' + localeString + "-deleteRow","click",function(){
  110. LocalizedStringValueHandler.removeLocaleSetting(settingKey, localeString);
  111. });
  112. };
  113. LocalizedStringValueHandler.writeLocaleSetting = function(settingKey, locale, value) {
  114. var existingValues = PWM_VAR['clientSettingCache'][settingKey];
  115. var currentValues = { };
  116. for (var i in existingValues) {
  117. var inputID = 'value-' + settingKey + '-' + i;
  118. currentValues[i] = PWM_MAIN.getObject(inputID).value;
  119. }
  120. if (value == null) {
  121. delete currentValues[locale];
  122. } else {
  123. currentValues[locale] = value;
  124. }
  125. PWM_CFGEDIT.writeSetting(settingKey, currentValues);
  126. PWM_VAR['clientSettingCache'][settingKey] = currentValues;
  127. };
  128. LocalizedStringValueHandler.removeLocaleSetting = function(keyName, locale, parentDiv, regExPattern, syntax) {
  129. LocalizedStringValueHandler.writeLocaleSetting(keyName, locale, null);
  130. LocalizedStringValueHandler.draw(keyName);
  131. };
  132. LocalizedStringValueHandler.addLocaleSetting = function(keyName, inputValue) {
  133. try {
  134. var existingElementForLocale = PWM_MAIN.getObject('value-' + keyName + '-' + inputValue);
  135. if (existingElementForLocale == null) {
  136. PWM_VAR['clientSettingCache'][keyName][inputValue] = [];
  137. PWM_CFGEDIT.writeSetting(keyName, PWM_VAR['clientSettingCache'][keyName]);
  138. //LocalizedStringValueHandler.writeLocaleSetting(keyName, inputValue, '');
  139. LocalizedStringValueHandler.draw(keyName);
  140. }
  141. } finally {
  142. }
  143. };
  144. // -------------------------- string array value handler ------------------------------------
  145. var StringArrayValueHandler = {};
  146. StringArrayValueHandler.init = function(keyName) {
  147. console.log('StringArrayValueHandler init for ' + keyName);
  148. var parentDiv = 'table_setting_' + keyName;
  149. PWM_MAIN.getObject(parentDiv).innerHTML = '<table id="tableTop_' + keyName + '" style="border-width:0">';
  150. parentDiv = PWM_MAIN.getObject('tableTop_' + keyName);
  151. PWM_VAR['clientSettingCache'][keyName + "_options"] = PWM_VAR['clientSettingCache'][keyName + "_options"] || {};
  152. PWM_VAR['clientSettingCache'][keyName + "_options"]['parentDiv'] = parentDiv;
  153. PWM_CFGEDIT.clearDivElements(parentDiv, true);
  154. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  155. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  156. StringArrayValueHandler.draw(keyName);
  157. var syntax = PWM_SETTINGS['settings'][keyName]['syntax'];
  158. if (syntax == 'PROFILE') {
  159. PWM_MAIN.getObject("resetButton-" + keyName).style.display = 'none';
  160. PWM_MAIN.getObject("helpButton-" + keyName).style.display = 'none';
  161. PWM_MAIN.getObject("modifiedNoticeIcon-" + keyName).style.display = 'none';
  162. }
  163. });
  164. };
  165. StringArrayValueHandler.draw = function(settingKey) {
  166. var parentDiv = PWM_VAR['clientSettingCache'][settingKey + "_options"]['parentDiv'];
  167. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  168. PWM_CFGEDIT.clearDivElements(parentDiv, false);
  169. var resultValue = PWM_VAR['clientSettingCache'][settingKey];
  170. var tableElement = document.createElement("table");
  171. tableElement.setAttribute("style", "border-width: 0;");
  172. var syntax = PWM_SETTINGS['settings'][settingKey]['syntax'];
  173. if (syntax == 'PROFILE') {
  174. var divDescriptionElement = document.createElement("div");
  175. divDescriptionElement.innerHTML = PWM_SETTINGS['settings'][settingKey]['description'];
  176. parentDivElement.appendChild(divDescriptionElement);
  177. var defaultProfileRow = document.createElement("tr");
  178. defaultProfileRow.setAttribute("colspan", "5");
  179. }
  180. var counter = 0;
  181. var itemCount = PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][settingKey]);
  182. for (var i in resultValue) {
  183. (function(iteration) {
  184. StringArrayValueHandler.drawRow(settingKey, iteration, resultValue[iteration], itemCount, tableElement);
  185. counter++;
  186. })(i);
  187. }
  188. parentDivElement.appendChild(tableElement);
  189. var addItemButton = document.createElement("button");
  190. addItemButton.setAttribute("type", "button");
  191. addItemButton.setAttribute("class","btn");
  192. addItemButton.setAttribute("id","button-" + settingKey + "-addItem");
  193. addItemButton.innerHTML = '<span class="btn-icon fa fa-plus-square"></span>' + (syntax == 'PROFILE' ? "Add Profile" : "Add Value");
  194. parentDivElement.appendChild(addItemButton);
  195. require(["dojo/parser","dijit/form/Button","dijit/form/ValidationTextBox"],function(dojoParser){
  196. dojoParser.parse(parentDiv);
  197. PWM_MAIN.addEventHandler('button-' + settingKey + '-addItem','click',function(){
  198. StringArrayValueHandler.valueHandler(settingKey,-1);
  199. });
  200. });
  201. };
  202. StringArrayValueHandler.drawRow = function(settingKey, iteration, value, itemCount, parentDivElement) {
  203. var settingInfo = PWM_SETTINGS['settings'][settingKey];
  204. var syntax = settingInfo['syntax'];
  205. var inputID = 'value-' + settingKey + '-' + iteration;
  206. // clear the old dijit node (if it exists)
  207. PWM_MAIN.clearDijitWidget(inputID);
  208. var valueRow = document.createElement("tr");
  209. valueRow.setAttribute("style", "border-width: 0");
  210. valueRow.setAttribute("id",inputID + "_row");
  211. var rowHtml = '<td style=""><div style="width:500px; overflow:hidden; text-overflow: ellipsis" id="' + inputID + '">' + value + '</div></td>';
  212. var downButtonID = 'button-' + settingKey + '-' + iteration + '-moveDown';
  213. rowHtml += '<td style="border:0">';
  214. if (itemCount > 1 && iteration != (itemCount -1)) {
  215. rowHtml += '<span id="' + downButtonID + '" class="action-icon fa fa-chevron-down"></span>';
  216. }
  217. rowHtml += '</td>';
  218. var upButtonID = 'button-' + settingKey + '-' + iteration + '-moveUp';
  219. rowHtml += '<td style="border:0">';
  220. if (itemCount > 1 && iteration != 0) {
  221. rowHtml += '<span id="' + upButtonID + '" class="action-icon fa fa-chevron-up"></span>';
  222. }
  223. rowHtml += '</td>';
  224. var deleteButtonID = 'button-' + settingKey + '-' + iteration + '-delete';
  225. rowHtml += '<td style="border:0">';
  226. if (itemCount > 1 || (!settingInfo['required'] && (syntax != 'PROFILE'))) {
  227. rowHtml += '<span id="' + deleteButtonID + '" class="delete-row-icon action-icon fa fa-times"></span>';
  228. }
  229. rowHtml += '</td>';
  230. valueRow.innerHTML = rowHtml;
  231. parentDivElement.appendChild(valueRow);
  232. setTimeout(function(){
  233. if (syntax != 'PROFILE') {
  234. PWM_MAIN.addEventHandler(inputID,'click',function(){
  235. StringArrayValueHandler.valueHandler(settingKey,iteration);
  236. });
  237. }
  238. if (itemCount > 1 && iteration != (itemCount -1)) {
  239. PWM_MAIN.addEventHandler(downButtonID,'click',function(){StringArrayValueHandler.move(settingKey,false,iteration)});
  240. }
  241. if (itemCount > 1 && iteration != 0) {
  242. PWM_MAIN.addEventHandler(upButtonID,'click',function(){StringArrayValueHandler.move(settingKey,true,iteration)});
  243. }
  244. if (itemCount > 1 || !PWM_SETTINGS['settings'][settingKey]['required']) {
  245. PWM_MAIN.addEventHandler(deleteButtonID,'click',function(){StringArrayValueHandler.removeValue(settingKey,iteration)});
  246. }
  247. },100);
  248. };
  249. StringArrayValueHandler.valueHandler = function(settingKey, iteration) {
  250. var text = '';
  251. //text += '<div>' + PWM_SETTINGS['settings'][settingKey]['description'] + '</div><hr/>';
  252. text += '<input style="width: 500px" required="required" id="addValueDialog_input"/>';
  253. var changeFunction = function() {
  254. PWM_VAR['addDialog_value'] = this.value;
  255. PWM_MAIN.getObject('dialog_ok_button').disabled = !this.validate();
  256. };
  257. var loadFunction = function() {
  258. var value = iteration > -1 ? PWM_VAR['clientSettingCache'][settingKey][iteration] : '';
  259. PWM_MAIN.getObject('dialog_ok_button').disabled = true;
  260. require(["dijit/form/ValidationTextBox"],function(ValidationTextBox) {
  261. new ValidationTextBox({
  262. id:"addValueDialog_input",
  263. regExp: PWM_SETTINGS['settings'][settingKey]['pattern'],
  264. style: 'width: 500px',
  265. required: true,
  266. invalidMessage: 'The value does not have the correct format',
  267. value: value,
  268. onChange: changeFunction,
  269. onKeyUp: changeFunction
  270. },"addValueDialog_input");
  271. });
  272. };
  273. var okAction = function() {
  274. var value = PWM_VAR['addDialog_value'];
  275. if (iteration > -1) {
  276. PWM_VAR['clientSettingCache'][settingKey][iteration] = value;
  277. } else {
  278. PWM_VAR['clientSettingCache'][settingKey].push(value);
  279. }
  280. StringArrayValueHandler.writeSetting(settingKey)
  281. };
  282. PWM_MAIN.showDialog({
  283. title:PWM_SETTINGS['settings'][settingKey]['label'] + " - " + (iteration > -1 ? "Edit" : "Add") + " Value",
  284. text:text,
  285. loadFunction:loadFunction,
  286. okAction:okAction,
  287. showCancel:true,
  288. showClose: true,
  289. allowMove: true
  290. });
  291. };
  292. StringArrayValueHandler.move = function(settingKey, moveUp, iteration) {
  293. var currentValues = PWM_VAR['clientSettingCache'][settingKey];
  294. if (moveUp) {
  295. StringArrayValueHandler.arrayMoveUtil(currentValues, iteration, iteration - 1);
  296. } else {
  297. StringArrayValueHandler.arrayMoveUtil(currentValues, iteration, iteration + 1);
  298. }
  299. StringArrayValueHandler.writeSetting(settingKey)
  300. };
  301. StringArrayValueHandler.arrayMoveUtil = function(arr, fromIndex, toIndex) {
  302. var element = arr[fromIndex];
  303. arr.splice(fromIndex, 1);
  304. arr.splice(toIndex, 0, element);
  305. };
  306. StringArrayValueHandler.removeValue = function(settingKey, iteration) {
  307. var syntax = PWM_SETTINGS['settings'][settingKey]['syntax'];
  308. var deleteFunction = function() {
  309. var currentValues = PWM_VAR['clientSettingCache'][settingKey];
  310. currentValues.splice(iteration,1);
  311. StringArrayValueHandler.writeSetting(settingKey,false);
  312. };
  313. if (syntax == 'PROFILE') {
  314. PWM_MAIN.showConfirmDialog({
  315. text:'Are you sure you want to remove the profile?',
  316. okAction:function(){
  317. deleteFunction();
  318. }
  319. });
  320. } else {
  321. deleteFunction();
  322. }
  323. };
  324. StringArrayValueHandler.writeSetting = function(settingKey, reload) {
  325. var syntax = PWM_SETTINGS['settings'][settingKey]['syntax'];
  326. var nextFunction = function() {
  327. if (syntax == 'PROFILE') {
  328. PWM_CFGEDIT.drawNavigationMenu();
  329. }
  330. if (reload) {
  331. StringArrayValueHandler.init(settingKey);
  332. } else {
  333. StringArrayValueHandler.draw(settingKey);
  334. }
  335. };
  336. var currentValues = PWM_VAR['clientSettingCache'][settingKey];
  337. PWM_CFGEDIT.writeSetting(settingKey, currentValues, nextFunction);
  338. };
  339. // -------------------------- multi locale table handler ------------------------------------
  340. var MultiLocaleTableHandler = {};
  341. MultiLocaleTableHandler.initMultiLocaleTable = function(keyName) {
  342. console.log('MultiLocaleTableHandler init for ' + keyName);
  343. var parentDiv = 'table_setting_' + keyName;
  344. PWM_CFGEDIT.clearDivElements(parentDiv, true);
  345. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  346. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  347. MultiLocaleTableHandler.draw(keyName);
  348. });
  349. };
  350. MultiLocaleTableHandler.draw = function(keyName) {
  351. var parentDiv = 'table_setting_' + keyName;
  352. var regExPattern = PWM_SETTINGS['settings'][keyName]['pattern'];
  353. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  354. require(["dojo","dijit/registry","dojo/parser","dijit/form/Button","dijit/form/ValidationTextBox","dijit/form/Textarea","dijit/registry"],function(dojo,registry,dojoParser){
  355. PWM_CFGEDIT.clearDivElements(parentDiv, false);
  356. for (var localeName in resultValue) {
  357. var localeTableRow = document.createElement("tr");
  358. localeTableRow.setAttribute("style", "border-width: 0;");
  359. var localeTdName = document.createElement("td");
  360. localeTdName.setAttribute("style", "border-width: 0; width:15px");
  361. localeTdName.innerHTML = localeName;
  362. localeTableRow.appendChild(localeTdName);
  363. var localeTdContent = document.createElement("td");
  364. localeTdContent.setAttribute("style", "border-width: 0; width: 525px");
  365. localeTableRow.appendChild(localeTdContent);
  366. var localeTableElement = document.createElement("table");
  367. localeTableElement.setAttribute("style", "border-width: 2px; width:525px; margin:0");
  368. localeTdContent.appendChild(localeTableElement);
  369. var multiValues = resultValue[localeName];
  370. for (var iteration in multiValues) {
  371. var valueTableRow = document.createElement("tr");
  372. var valueTd1 = document.createElement("td");
  373. valueTd1.setAttribute("style", "border-width: 0;");
  374. // clear the old dijit node (if it exists)
  375. var inputID = "value-" + keyName + "-" + localeName + "-" + iteration;
  376. var oldDijitNode = registry.byId(inputID);
  377. if (oldDijitNode != null) {
  378. try {
  379. oldDijitNode.destroy();
  380. } catch (error) {
  381. }
  382. }
  383. var inputElement = document.createElement("input");
  384. inputElement.setAttribute("id", inputID);
  385. inputElement.setAttribute("value", multiValues[iteration]);
  386. inputElement.setAttribute("onchange", "MultiLocaleTableHandler.writeMultiLocaleSetting('" + keyName + "','" + localeName + "','" + iteration + "',this.value,'" + regExPattern + "')");
  387. inputElement.setAttribute("style", "width: 490px");
  388. inputElement.setAttribute("data-dojo-type", "dijit.form.ValidationTextBox");
  389. inputElement.setAttribute("regExp", regExPattern);
  390. inputElement.setAttribute("invalidMessage", "The value does not have the correct format.");
  391. valueTd1.appendChild(inputElement);
  392. valueTableRow.appendChild(valueTd1);
  393. localeTableElement.appendChild(valueTableRow);
  394. // add remove button
  395. var imgElement = document.createElement("div");
  396. imgElement.setAttribute("style", "width: 10px; height: 10px;");
  397. imgElement.setAttribute("class", "delete-row-icon action-icon fa fa-times");
  398. imgElement.setAttribute("onclick", "MultiLocaleTableHandler.writeMultiLocaleSetting('" + keyName + "','" + localeName + "','" + iteration + "',null,'" + regExPattern + "')");
  399. valueTd1.appendChild(imgElement);
  400. }
  401. { // add row button for this locale group
  402. var newTableRow = document.createElement("tr");
  403. newTableRow.setAttribute("style", "border-width: 0");
  404. newTableRow.setAttribute("colspan", "5");
  405. var newTableData = document.createElement("td");
  406. newTableData.setAttribute("style", "border-width: 0;");
  407. var addItemButton = document.createElement("button");
  408. addItemButton.setAttribute("type", "[button");
  409. addItemButton.setAttribute("onclick", "PWM_VAR['clientSettingCache']['" + keyName + "']['" + localeName + "'].push('');MultiLocaleTableHandler.writeMultiLocaleSetting('" + keyName + "',null,null,null,'" + regExPattern + "')");
  410. addItemButton.setAttribute("data-dojo-type", "dijit.form.Button");
  411. addItemButton.innerHTML = "Add Value";
  412. newTableData.appendChild(addItemButton);
  413. newTableRow.appendChild(newTableData);
  414. localeTableElement.appendChild(newTableRow);
  415. }
  416. if (localeName != '') { // add remove locale x
  417. var imgElement2 = document.createElement("div");
  418. imgElement2.setAttribute("class", "delete-row-icon action-icon fa fa-times");
  419. imgElement2.setAttribute("onclick", "MultiLocaleTableHandler.writeMultiLocaleSetting('" + keyName + "','" + localeName + "',null,null,'" + regExPattern + "')");
  420. var tdElement = document.createElement("td");
  421. tdElement.setAttribute("style", "border-width: 0; text-align: left; vertical-align: top;width 10px");
  422. localeTableRow.appendChild(tdElement);
  423. tdElement.appendChild(imgElement2);
  424. }
  425. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  426. parentDivElement.appendChild(localeTableRow);
  427. { // add a spacer row
  428. var spacerTableRow = document.createElement("tr");
  429. spacerTableRow.setAttribute("style", "border-width: 0");
  430. parentDivElement.appendChild(spacerTableRow);
  431. var spacerTableData = document.createElement("td");
  432. spacerTableData.setAttribute("style", "border-width: 0");
  433. spacerTableData.innerHTML = "&nbsp;";
  434. spacerTableRow.appendChild(spacerTableData);
  435. }
  436. }
  437. var addLocaleFunction = function(value) {
  438. require(["dijit/registry"],function(registry){
  439. MultiLocaleTableHandler.writeMultiLocaleSetting(keyName, value, 0, '', regExPattern);
  440. });
  441. };
  442. PWM_CFGEDIT.addAddLocaleButtonRow(parentDiv, keyName, addLocaleFunction);
  443. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  444. dojoParser.parse(parentDiv);
  445. });
  446. };
  447. MultiLocaleTableHandler.writeMultiLocaleSetting = function(settingKey, locale, iteration, value) {
  448. if (locale != null) {
  449. if (PWM_VAR['clientSettingCache'][settingKey][locale] == null) {
  450. PWM_VAR['clientSettingCache'][settingKey][locale] = [ "" ];
  451. }
  452. if (iteration == null) {
  453. delete PWM_VAR['clientSettingCache'][settingKey][locale];
  454. } else {
  455. if (value == null) {
  456. PWM_VAR['clientSettingCache'][settingKey][locale].splice(iteration,1);
  457. } else {
  458. PWM_VAR['clientSettingCache'][settingKey][locale][iteration] = value;
  459. }
  460. }
  461. }
  462. PWM_CFGEDIT.writeSetting(settingKey, PWM_VAR['clientSettingCache'][settingKey]);
  463. MultiLocaleTableHandler.draw(settingKey);
  464. };
  465. // -------------------------- form table handler ------------------------------------
  466. var FormTableHandler = {};
  467. FormTableHandler.newRowValue = {
  468. name:'',
  469. minimumLength:0,
  470. maximumLength:255,
  471. labels:{'':''},
  472. regexErrors:{'':''},
  473. selectOptions:{},
  474. description:{'':''}
  475. };
  476. FormTableHandler.init = function(keyName) {
  477. console.log('FormTableHandler init for ' + keyName);
  478. var parentDiv = 'table_setting_' + keyName;
  479. PWM_CFGEDIT.clearDivElements(parentDiv, true);
  480. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  481. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  482. FormTableHandler.redraw(keyName);
  483. });
  484. };
  485. FormTableHandler.redraw = function(keyName) {
  486. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  487. var parentDiv = 'table_setting_' + keyName;
  488. PWM_CFGEDIT.clearDivElements(parentDiv, false);
  489. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  490. if (!PWM_MAIN.isEmpty(resultValue)) {
  491. var headerRow = document.createElement("tr");
  492. var rowHtml = '<td>Name</td><td>Label</td>';
  493. headerRow.innerHTML = rowHtml;
  494. parentDivElement.appendChild(headerRow);
  495. }
  496. for (var i in resultValue) {
  497. FormTableHandler.drawRow(parentDiv, keyName, i, resultValue[i]);
  498. }
  499. var buttonRow = document.createElement("tr");
  500. buttonRow.setAttribute("colspan","5");
  501. buttonRow.innerHTML = '<td><button class="btn" id="button-' + keyName + '-addRow"><span class="btn-icon fa fa-plus-square"></span>Add Form Item</button></td>';
  502. parentDivElement.appendChild(buttonRow);
  503. PWM_MAIN.addEventHandler('button-' + keyName + '-addRow','click',function(){
  504. FormTableHandler.addRow(keyName);
  505. });
  506. };
  507. FormTableHandler.drawRow = function(parentDiv, settingKey, iteration, value) {
  508. require(["dojo/json"], function(JSON){
  509. var itemCount = PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][settingKey]);
  510. var inputID = 'value_' + settingKey + '_' + iteration + "_";
  511. var options = PWM_SETTINGS['settings'][settingKey]['options'];
  512. var newTableRow = document.createElement("tr");
  513. newTableRow.setAttribute("style", "border-width: 0");
  514. var htmlRow = '';
  515. htmlRow += '<td><input style="width:180px" class="configStringInput" id="' + inputID + 'name" value="' + value['name'] + '"/></td>';
  516. htmlRow += '<td style="width:170px"><div class="noWrapTextBox" id="' + inputID + 'label"><span class="btn-icon fa fa-edit"></span><span>' + value['labels'][''] + '...</span></div></td>';
  517. htmlRow += '<td>';
  518. var userDNtypeAllowed = options['type-userDN'] == 'show';
  519. var optionList = PWM_GLOBAL['formTypeOptions'];
  520. if ('types' in options) {
  521. optionList = JSON.parse(options['types']);
  522. }
  523. if (!PWM_MAIN.isEmpty(optionList)) {
  524. htmlRow += '<select id="' + inputID + 'type">';
  525. for (var optionItem in optionList) {
  526. if (optionList[optionItem] != 'userDN' || userDNtypeAllowed) {
  527. var optionName = optionList[optionItem];
  528. var selected = (optionName == PWM_VAR['clientSettingCache'][settingKey][iteration]['type']);
  529. htmlRow += '<option value="' + optionName + '"' + (selected ? " selected" : "") + '>' + optionName + '</option>';
  530. }
  531. }
  532. htmlRow += '</select>';
  533. }
  534. htmlRow += '</td>';
  535. var hideOptions = PWM_SETTINGS['settings'][settingKey]['options']['hideOptions'] == 'true';
  536. if (!hideOptions) {
  537. htmlRow += '<td><button id="' + inputID + 'optionsButton"><span class="btn-icon fa fa-sliders"/> Options</button></td>';
  538. }
  539. htmlRow += '<td>';
  540. if (itemCount > 1 && iteration != (itemCount -1)) {
  541. htmlRow += '<span id="' + inputID + '-moveDown" class="action-icon fa fa-chevron-down"></span>';
  542. }
  543. htmlRow += '</td>';
  544. htmlRow += '<td>';
  545. if (itemCount > 1 && iteration != 0) {
  546. htmlRow += '<span id="' + inputID + '-moveUp" class="action-icon fa fa-chevron-up"></span>';
  547. }
  548. htmlRow += '</td>';
  549. htmlRow += '<td><span class="delete-row-icon action-icon fa fa-times" id="' + inputID + '-deleteRowButton"></span></td>';
  550. newTableRow.innerHTML = htmlRow;
  551. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  552. parentDivElement.appendChild(newTableRow);
  553. PWM_MAIN.addEventHandler(inputID + "-moveUp", 'click', function () {
  554. FormTableHandler.move(settingKey, true, iteration);
  555. });
  556. PWM_MAIN.addEventHandler(inputID + "-moveDown", 'click', function () {
  557. FormTableHandler.move(settingKey, false, iteration);
  558. });
  559. PWM_MAIN.addEventHandler(inputID + "-deleteRowButton", 'click', function () {
  560. FormTableHandler.removeRow(settingKey, iteration);
  561. });
  562. PWM_MAIN.addEventHandler(inputID + "label", 'click, keypress', function () {
  563. FormTableHandler.showLabelDialog(settingKey, iteration);
  564. });
  565. PWM_MAIN.addEventHandler(inputID + "optionsButton", 'click', function () {
  566. FormTableHandler.showOptionsDialog(settingKey, iteration);
  567. });
  568. PWM_MAIN.addEventHandler(inputID + "name", 'input', function () {
  569. PWM_VAR['clientSettingCache'][settingKey][iteration]['name'] = PWM_MAIN.getObject(inputID + "name").value;
  570. FormTableHandler.writeFormSetting(settingKey);
  571. });
  572. PWM_MAIN.addEventHandler(inputID + "type", 'click', function () {
  573. PWM_VAR['clientSettingCache'][settingKey][iteration]['type'] = PWM_MAIN.getObject(inputID + "type").value;
  574. FormTableHandler.writeFormSetting(settingKey);
  575. });
  576. });
  577. };
  578. FormTableHandler.writeFormSetting = function(settingKey, finishFunction) {
  579. var cachedSetting = PWM_VAR['clientSettingCache'][settingKey];
  580. PWM_CFGEDIT.writeSetting(settingKey, cachedSetting, finishFunction);
  581. };
  582. FormTableHandler.removeRow = function(keyName, iteration) {
  583. PWM_MAIN.showConfirmDialog({
  584. text:'Are you sure you wish to delete this item?',
  585. okAction:function(){
  586. var currentValues = PWM_VAR['clientSettingCache'][keyName];
  587. currentValues.splice(iteration,1);
  588. FormTableHandler.writeFormSetting(keyName,function(){
  589. FormTableHandler.init(keyName);
  590. });
  591. }
  592. });
  593. };
  594. FormTableHandler.move = function(settingKey, moveUp, iteration) {
  595. var currentValues = PWM_VAR['clientSettingCache'][settingKey];
  596. if (moveUp) {
  597. FormTableHandler.arrayMoveUtil(currentValues, iteration, iteration - 1);
  598. } else {
  599. FormTableHandler.arrayMoveUtil(currentValues, iteration, iteration + 1);
  600. }
  601. FormTableHandler.writeFormSetting(settingKey);
  602. FormTableHandler.redraw(settingKey);
  603. };
  604. FormTableHandler.arrayMoveUtil = function(arr, fromIndex, toIndex) {
  605. var element = arr[fromIndex];
  606. arr.splice(fromIndex, 1);
  607. arr.splice(toIndex, 0, element);
  608. };
  609. FormTableHandler.addRow = function(keyName) {
  610. var body='Name <input class="configStringInput" id="newFormFieldName" style="width:300px"/>';
  611. PWM_MAIN.showConfirmDialog({title:'New Form Field',text:body,showClose:true,loadFunction:function(){
  612. PWM_MAIN.getObject('dialog_ok_button').disabled = true;
  613. PWM_MAIN.addEventHandler('newFormFieldName','input',function(){
  614. PWM_VAR['newFormFieldName'] = PWM_MAIN.getObject('newFormFieldName').value;
  615. if (PWM_VAR['newFormFieldName'] && PWM_VAR['newFormFieldName'].length > 1) {
  616. PWM_MAIN.getObject('dialog_ok_button').disabled = false;
  617. }
  618. });
  619. },okAction:function(){
  620. var currentSize = PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][keyName]);
  621. PWM_VAR['clientSettingCache'][keyName][currentSize + 1] = FormTableHandler.newRowValue
  622. PWM_VAR['clientSettingCache'][keyName][currentSize + 1].name = PWM_VAR['newFormFieldName'];
  623. FormTableHandler.writeFormSetting(keyName,function(){
  624. FormTableHandler.init(keyName);
  625. });
  626. }});
  627. };
  628. FormTableHandler.showOptionsDialog = function(keyName, iteration) {
  629. var options = 'options' in PWM_SETTINGS['settings'][keyName] ? PWM_SETTINGS['settings'][keyName]['options'] : {};
  630. var showUnique = options['unique'] == 'show';
  631. require(["dijit/Dialog","dijit/form/Textarea","dijit/form/CheckBox","dijit/form/NumberSpinner"],function(){
  632. var inputID = 'value_' + keyName + '_' + iteration + "_";
  633. var bodyText = '<div style="max-height: 500px; overflow-y: auto"><table class="noborder">';
  634. bodyText += '<tr>';
  635. var descriptionValue = PWM_VAR['clientSettingCache'][keyName][iteration]['description'][''];
  636. bodyText += '<td id="' + inputID + '-label-description" class="key">Description</td><td>';
  637. bodyText += '<div class="noWrapTextBox" id="' + inputID + 'description"><span class="btn-icon fa fa-edit"></span><span>' + descriptionValue + '...</span></div>';
  638. bodyText += '</td>';
  639. bodyText += '</tr><tr>';
  640. if (options['required'] != 'hide') {
  641. bodyText += '<td id="' + inputID + '-label-required" class="key">Required</td><td><input type="checkbox" id="' + inputID + 'required' + '"/></td>';
  642. bodyText += '</tr><tr>';
  643. }
  644. bodyText += '<td id="' + inputID + '-label-confirm" class="key">Confirm</td><td><input type="checkbox" id="' + inputID + 'confirmationRequired' + '"/></td>';
  645. bodyText += '</tr><tr>';
  646. if (options['readonly'] == 'show') {
  647. bodyText += '<td id="' + inputID + '-label-readOnly" class="key">Read Only</td><td><input type="checkbox" id="' + inputID + 'readonly' + '"/></td>';
  648. bodyText += '</tr><tr>';
  649. }
  650. if (showUnique) {
  651. bodyText += '<td id="' + inputID + '-label-unique" class="key">Unique</td><td><input type="checkbox" id="' + inputID + 'unique' + '"/></td>';
  652. bodyText += '</tr><tr>';
  653. }
  654. bodyText += '<td class="key">Minimum Length</td><td><input type="number" id="' + inputID + 'minimumLength' + '"/></td>';
  655. bodyText += '</tr><tr>';
  656. bodyText += '<td class="key">Maximum Length</td><td><input type="number" id="' + inputID + 'maximumLength' + '"/></td>';
  657. bodyText += '</tr><tr>';
  658. { // regex
  659. bodyText += '<td id="' + inputID + '-label-regex" class="key">Regular Expression</td><td><input type="text" class="configStringInput" id="' + inputID + 'regex' + '"/></td>';
  660. bodyText += '</tr><tr>';
  661. var regexErrorValue = PWM_VAR['clientSettingCache'][keyName][iteration]['regexErrors'][''];
  662. bodyText += '<td id="' + inputID + '-label-regexError" class="key">Regular Expression<br/>Error Message</td><td>';
  663. bodyText += '<div class="noWrapTextBox" id="' + inputID + 'regexErrors"><span class="btn-icon fa fa-edit"></span><span>' + regexErrorValue + '...</span></div>';
  664. bodyText += '</td>';
  665. bodyText += '</tr><tr>';
  666. }
  667. bodyText += '<td id="' + inputID + '-label-placeholder" class="key">Placeholder</td><td><input type="text" id="' + inputID + 'placeholder' + '"/></td>';
  668. bodyText += '</tr><tr>';
  669. bodyText += '<td id="' + inputID + '-label-js" class="key">JavaScript</td><td><input type="text" id="' + inputID + 'javascript' + '"/></td>';
  670. bodyText += '</tr><tr>';
  671. if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'select') {
  672. bodyText += '<td class="key">Select Options</td><td><button id="' + inputID + 'editOptionsButton"><span class="btn-icon fa fa-list-ul"/> Edit</button></td>';
  673. bodyText += '</tr>';
  674. }
  675. bodyText += '</table></div>';
  676. var initDialogWidgets = function() {
  677. PWM_MAIN.showTooltip({
  678. id: inputID + '-label-description',
  679. text: PWM_CONFIG.showString('Tooltip_FormOptions_Description')
  680. });
  681. PWM_MAIN.showTooltip({
  682. id: inputID + '-label-required',
  683. text: PWM_CONFIG.showString('Tooltip_FormOptions_Required')
  684. });
  685. PWM_MAIN.showTooltip({
  686. id: inputID + '-label-confirm',
  687. text: PWM_CONFIG.showString('Tooltip_FormOptions_Confirm')
  688. });
  689. PWM_MAIN.showTooltip({
  690. id: inputID + '-label-readOnly',
  691. text: PWM_CONFIG.showString('Tooltip_FormOptions_ReadOnly')
  692. });
  693. PWM_MAIN.showTooltip({
  694. id: inputID + '-label-unique',
  695. text: PWM_CONFIG.showString('Tooltip_FormOptions_Unique')
  696. });
  697. PWM_MAIN.showTooltip({
  698. id: inputID + '-label-regex',
  699. text: PWM_CONFIG.showString('Tooltip_FormOptions_Regex')
  700. });
  701. PWM_MAIN.showTooltip({
  702. id: inputID + '-label-regexError',
  703. text: PWM_CONFIG.showString('Tooltip_FormOptions_RegexError')
  704. });
  705. PWM_MAIN.showTooltip({
  706. id: inputID + '-label-placeholder',
  707. text: PWM_CONFIG.showString('Tooltip_FormOptions_Placeholder')
  708. });
  709. PWM_MAIN.showTooltip({
  710. id: inputID + '-label-js',
  711. text: PWM_CONFIG.showString('Tooltip_FormOptions_Javascript')
  712. });
  713. PWM_MAIN.addEventHandler(inputID + 'editOptionsButton', 'click', function(){
  714. FormTableHandler.showSelectOptionsDialog(keyName,iteration);
  715. });
  716. PWM_MAIN.addEventHandler(inputID + 'description','click',function(){
  717. FormTableHandler.showDescriptionDialog(keyName, iteration);
  718. });
  719. PWM_MAIN.clearDijitWidget(inputID + "required");
  720. new dijit.form.CheckBox({
  721. checked: PWM_VAR['clientSettingCache'][keyName][iteration]['required'],
  722. onChange: function () {
  723. PWM_VAR['clientSettingCache'][keyName][iteration]['required'] = this.checked;
  724. FormTableHandler.writeFormSetting(keyName)
  725. }
  726. }, inputID + "required");
  727. PWM_MAIN.clearDijitWidget(inputID + "confirmationRequired");
  728. new dijit.form.CheckBox({
  729. checked: PWM_VAR['clientSettingCache'][keyName][iteration]['confirmationRequired'],
  730. onChange: function () {
  731. PWM_VAR['clientSettingCache'][keyName][iteration]['confirmationRequired'] = this.checked;
  732. FormTableHandler.writeFormSetting(keyName)
  733. }
  734. }, inputID + "confirmationRequired");
  735. if (PWM_SETTINGS['settings'][keyName]['options']['readonly'] == 'show') {
  736. PWM_MAIN.clearDijitWidget(inputID + "readonly");
  737. new dijit.form.CheckBox({
  738. checked: PWM_VAR['clientSettingCache'][keyName][iteration]['readonly'],
  739. onChange: function () {
  740. PWM_VAR['clientSettingCache'][keyName][iteration]['readonly'] = this.checked;
  741. FormTableHandler.writeFormSetting(keyName)
  742. }
  743. }, inputID + "readonly");
  744. }
  745. if (showUnique) {
  746. PWM_MAIN.clearDijitWidget(inputID + "unique");
  747. new dijit.form.CheckBox({
  748. checked: PWM_VAR['clientSettingCache'][keyName][iteration]['unique'],
  749. onChange: function () {
  750. PWM_VAR['clientSettingCache'][keyName][iteration]['unique'] = this.checked;
  751. FormTableHandler.writeFormSetting(keyName)
  752. }
  753. }, inputID + "unique");
  754. }
  755. if (PWM_SETTINGS['settings'][keyName]['options']['unique'] == 'show') {
  756. PWM_MAIN.clearDijitWidget(inputID + "unique");
  757. new dijit.form.CheckBox({
  758. checked: PWM_VAR['clientSettingCache'][keyName][iteration]['unique'],
  759. onChange: function () {
  760. PWM_VAR['clientSettingCache'][keyName][iteration]['unique'] = this.checked;
  761. FormTableHandler.writeFormSetting(keyName)
  762. }
  763. }, inputID + "unique");
  764. }
  765. PWM_MAIN.clearDijitWidget(inputID + "minimumLength");
  766. new dijit.form.NumberSpinner({
  767. value: PWM_VAR['clientSettingCache'][keyName][iteration]['minimumLength'],
  768. onChange: function () {
  769. PWM_VAR['clientSettingCache'][keyName][iteration]['minimumLength'] = this.value;
  770. FormTableHandler.writeFormSetting(keyName)
  771. },
  772. constraints: {min: 0, max: 5000},
  773. style: "width: 70px"
  774. }, inputID + "minimumLength");
  775. PWM_MAIN.clearDijitWidget(inputID + "maximumLength");
  776. new dijit.form.NumberSpinner({
  777. value: PWM_VAR['clientSettingCache'][keyName][iteration]['maximumLength'],
  778. onChange: function () {
  779. PWM_VAR['clientSettingCache'][keyName][iteration]['maximumLength'] = this.value;
  780. FormTableHandler.writeFormSetting(keyName)
  781. },
  782. constraints: {min: 0, max: 5000},
  783. style: "width: 70px"
  784. }, inputID + "maximumLength");
  785. PWM_MAIN.clearDijitWidget(inputID + "regex");
  786. new dijit.form.Textarea({
  787. value: PWM_VAR['clientSettingCache'][keyName][iteration]['regex'],
  788. onChange: function () {
  789. PWM_VAR['clientSettingCache'][keyName][iteration]['regex'] = this.value;
  790. FormTableHandler.writeFormSetting(keyName)
  791. }
  792. }, inputID + "regex");
  793. PWM_MAIN.addEventHandler(inputID + 'regexErrors','click',function(){
  794. FormTableHandler.showRegexErrorsDialog(keyName, iteration);
  795. });
  796. PWM_MAIN.clearDijitWidget(inputID + "placeholder");
  797. new dijit.form.Textarea({
  798. value: PWM_VAR['clientSettingCache'][keyName][iteration]['placeholder'],
  799. onChange: function () {
  800. PWM_VAR['clientSettingCache'][keyName][iteration]['placeholder'] = this.value;
  801. FormTableHandler.writeFormSetting(keyName)
  802. }
  803. }, inputID + "placeholder");
  804. PWM_MAIN.clearDijitWidget(inputID + "javascript");
  805. new dijit.form.Textarea({
  806. value: PWM_VAR['clientSettingCache'][keyName][iteration]['javascript'],
  807. onChange: function(){PWM_VAR['clientSettingCache'][keyName][iteration]['javascript'] = this.value;FormTableHandler.writeFormSetting(keyName)}
  808. },inputID + "javascript");
  809. };
  810. PWM_MAIN.showDialog({
  811. title: PWM_SETTINGS['settings'][keyName]['label'] + ' - ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'],
  812. text:bodyText,
  813. allowMove:true,
  814. loadFunction:initDialogWidgets,
  815. okAction:function(){
  816. FormTableHandler.redraw(keyName);
  817. }
  818. });
  819. });
  820. };
  821. FormTableHandler.showLabelDialog = function(keyName, iteration) {
  822. var finishAction = function(){ FormTableHandler.redraw(keyName); };
  823. var title = 'Label for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
  824. FormTableHandler.multiLocaleStringDialog(keyName, iteration, 'labels', finishAction, title);
  825. };
  826. FormTableHandler.multiLocaleStringDialog = function(keyName, iteration, settingType, finishAction, titleText) {
  827. require(["dijit/Dialog","dijit/form/Textarea","dijit/form/CheckBox"],function(){
  828. var inputID = 'value_' + keyName + '_' + iteration + "_" + "label_";
  829. var bodyText = '<table class="noborder" id="' + inputID + 'table">';
  830. bodyText += '<tr>';
  831. for (var localeName in PWM_VAR['clientSettingCache'][keyName][iteration][settingType]) {
  832. var value = PWM_VAR['clientSettingCache'][keyName][iteration][settingType][localeName];
  833. var localeID = inputID + localeName;
  834. bodyText += '<td>' + localeName + '</td>';
  835. bodyText += '<td><input style="width:445px" class="configStringInput" type="text" value="' + value + '" id="' + localeID + '-input"></input></td>';
  836. if (localeName != '') {
  837. bodyText += '<td><span class="delete-row-icon action-icon fa fa-times" id="' + localeID + '-removeLocaleButton"></span></td>';
  838. }
  839. bodyText += '</tr><tr>';
  840. }
  841. bodyText += '</tr></table>';
  842. PWM_MAIN.showDialog({
  843. title: titleText,
  844. text: bodyText,
  845. okAction:function(){
  846. finishAction();
  847. },
  848. loadFunction:function(){
  849. for (var iter in PWM_VAR['clientSettingCache'][keyName][iteration][settingType]) {
  850. (function(localeName) {
  851. var localeID = inputID + localeName;
  852. PWM_MAIN.addEventHandler(localeID + '-input', 'input', function () {
  853. var inputElement = PWM_MAIN.getObject(localeID + '-input');
  854. var value = inputElement.value;
  855. PWM_VAR['clientSettingCache'][keyName][iteration][settingType][localeName] = value;
  856. FormTableHandler.writeFormSetting(keyName);
  857. });
  858. PWM_MAIN.addEventHandler(localeID + '-removeLocaleButton', 'click', function () {
  859. delete PWM_VAR['clientSettingCache'][keyName][iteration]['labels'][localeName];
  860. FormTableHandler.writeFormSetting(keyName);
  861. FormTableHandler.multiLocaleStringDialog(keyName, iteration, settingType, finishAction, titleText);
  862. });
  863. }(iter));
  864. }
  865. PWM_CFGEDIT.addAddLocaleButtonRow(inputID + 'table', inputID, function(localeName){
  866. PWM_VAR['clientSettingCache'][keyName][iteration][settingType][localeName] = '';
  867. FormTableHandler.writeFormSetting(keyName);
  868. FormTableHandler.multiLocaleStringDialog(keyName, iteration, settingType, finishAction, titleText);
  869. });
  870. }
  871. });
  872. });
  873. };
  874. FormTableHandler.showRegexErrorsDialog = function(keyName, iteration) {
  875. var finishAction = function(){ FormTableHandler.showOptionsDialog(keyName, iteration); };
  876. var title = 'Regular Expression Error Message for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
  877. FormTableHandler.multiLocaleStringDialog(keyName, iteration, 'regexErrors', finishAction, title);
  878. };
  879. FormTableHandler.showSelectOptionsDialog = function(keyName, iteration) {
  880. var inputID = 'value_' + keyName + '_' + iteration + "_" + "selectOptions_";
  881. var bodyText = '';
  882. bodyText += '<table class="noborder" id="' + inputID + 'table"">';
  883. bodyText += '<tr>';
  884. bodyText += '<td><b>Value</b></td><td><b>Display Name</b></td>';
  885. bodyText += '</tr><tr>';
  886. for (var optionName in PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions']) {
  887. var value = PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions'][optionName];
  888. var optionID = inputID + optionName;
  889. bodyText += '<td>' + optionName + '</td><td>' + value + '</td>';
  890. bodyText += '<td style="border:0; width:15px">';
  891. bodyText += '<span id="' + optionID + '-removeButton" class="delete-row-icon action-icon fa fa-times"></span>';
  892. bodyText += '</td>';
  893. bodyText += '</tr><tr>';
  894. }
  895. bodyText += '</tr></table>';
  896. bodyText += '<br/><br/><br/>';
  897. bodyText += '<input class="configStringInput" style="width:200px" type="text" placeholder="Value" required id="addSelectOptionName"/>';
  898. bodyText += '<input class="configStringInput" style="width:200px" type="text" placeholder="Display Name" required id="addSelectOptionValue"/>';
  899. bodyText += '<button id="addSelectOptionButton"><span class="btn-icon fa fa-plus-square"/> Add</button>';
  900. PWM_MAIN.showDialog({
  901. title: 'Select Options for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'],
  902. text: bodyText,
  903. okAction: function(){
  904. FormTableHandler.showOptionsDialog(keyName,iteration);
  905. }
  906. });
  907. for (var optionName in PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions']) {
  908. var loopID = inputID + optionName;
  909. var optionID = inputID + optionName;
  910. PWM_MAIN.clearDijitWidget(loopID);
  911. PWM_MAIN.addEventHandler(optionID + '-removeButton','click',function(){
  912. FormTableHandler.removeSelectOptionsOption(keyName,iteration,optionName);
  913. });
  914. }
  915. PWM_MAIN.addEventHandler('addSelectOptionButton','click',function(){
  916. var value = PWM_MAIN.getObject('addSelectOptionName').value;
  917. var display = PWM_MAIN.getObject('addSelectOptionValue').value;
  918. FormTableHandler.addSelectOptionsOption(keyName, iteration, value, display);
  919. });
  920. };
  921. FormTableHandler.addSelectOptionsOption = function(keyName, iteration, optionName, optionValue) {
  922. if (optionName == null || optionName.length < 1) {
  923. alert('Name field is required');
  924. return;
  925. }
  926. if (optionValue == null || optionValue.length < 1) {
  927. alert('Value field is required');
  928. return;
  929. }
  930. PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions'][optionName] = optionValue;
  931. FormTableHandler.writeFormSetting(keyName);
  932. FormTableHandler.showSelectOptionsDialog(keyName, iteration);
  933. };
  934. FormTableHandler.removeSelectOptionsOption = function(keyName, iteration, optionName) {
  935. delete PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions'][optionName];
  936. FormTableHandler.writeFormSetting(keyName);
  937. FormTableHandler.showSelectOptionsDialog(keyName, iteration);
  938. };
  939. FormTableHandler.showDescriptionDialog = function(keyName, iteration) {
  940. var finishAction = function(){ FormTableHandler.showOptionsDialog(keyName, iteration); };
  941. var title = 'Description for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
  942. FormTableHandler.multiLocaleStringDialog(keyName, iteration, 'description', finishAction, title);
  943. };
  944. // -------------------------- change password handler ------------------------------------
  945. var ChangePasswordHandler = {};
  946. ChangePasswordHandler.init = function(settingKey) {
  947. var parentDiv = 'table_setting_' + settingKey;
  948. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  949. if (parentDivElement) {
  950. PWM_CFGEDIT.readSetting(settingKey,function(data){
  951. var hasPassword = !data['isDefault'];
  952. var htmlBody = '';
  953. if (hasPassword) {
  954. htmlBody += '<table><tr><td>Value stored.</td></tr></table>';
  955. htmlBody += '<button id="button-clearPassword-' + settingKey + '" class="btn"><span class="btn-icon fa fa-times"></span>Clear Value</button>';
  956. } else {
  957. htmlBody += '<button id="button-changePassword-' + settingKey + '" class="btn"><span class="btn-icon fa fa-plus-square"></span>Store Value</button>';
  958. }
  959. parentDivElement.innerHTML = htmlBody;
  960. PWM_MAIN.addEventHandler('button-changePassword-' + settingKey,'click',function(){
  961. ChangePasswordHandler.popup(settingKey,PWM_SETTINGS['settings'][settingKey]['label']);
  962. });
  963. PWM_MAIN.addEventHandler('button-clearPassword-' + settingKey,'click',function(){
  964. PWM_MAIN.showConfirmDialog({
  965. text:'Clear password for setting ' + PWM_SETTINGS['settings'][settingKey]['label'] + '?',
  966. okAction:function() {
  967. PWM_CFGEDIT.resetSetting(settingKey,function(){
  968. ChangePasswordHandler.init(settingKey);
  969. });
  970. }
  971. });
  972. });
  973. });
  974. }
  975. };
  976. ChangePasswordHandler.popup = function(settingKey,settingName,writeFunction) {
  977. if (!PWM_VAR['clientSettingCache'][settingKey]) {
  978. PWM_VAR['clientSettingCache'][settingKey] = {};
  979. }
  980. if (!PWM_VAR['clientSettingCache'][settingKey]['settings']) {
  981. PWM_VAR['clientSettingCache'][settingKey]['settings'] = {};
  982. }
  983. PWM_VAR['clientSettingCache'][settingKey]['settings']['name'] = settingName;
  984. if (writeFunction) {
  985. PWM_VAR['clientSettingCache'][settingKey]['settings']['writeFunction'] = writeFunction;
  986. } else {
  987. PWM_VAR['clientSettingCache'][settingKey]['settings']['writeFunction'] = function(passwordValue){
  988. ChangePasswordHandler.doChange(settingKey,passwordValue);
  989. }
  990. }
  991. PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields'] = false;
  992. ChangePasswordHandler.clear(settingKey);
  993. ChangePasswordHandler.changePasswordPopup(settingKey);
  994. };
  995. ChangePasswordHandler.validatePasswordPopupFields = function() {
  996. var password1 = PWM_MAIN.getObject('password1').value;
  997. var password2 = PWM_MAIN.getObject('password2').value;
  998. var matchStatus = "";
  999. PWM_MAIN.getObject('button-storePassword').disabled = true;
  1000. if (password2.length > 0) {
  1001. if (password1 == password2) {
  1002. matchStatus = "MATCH";
  1003. PWM_MAIN.getObject('button-storePassword').disabled = false;
  1004. } else {
  1005. matchStatus = "NO_MATCH";
  1006. }
  1007. }
  1008. ChangePasswordHandler.markConfirmationCheck(matchStatus);
  1009. };
  1010. ChangePasswordHandler.markConfirmationCheck = function(matchStatus) {
  1011. if (matchStatus == "MATCH") {
  1012. PWM_MAIN.getObject("confirmCheckMark").style.visibility = 'visible';
  1013. PWM_MAIN.getObject("confirmCrossMark").style.visibility = 'hidden';
  1014. PWM_MAIN.getObject("confirmCheckMark").width = '15';
  1015. PWM_MAIN.getObject("confirmCrossMark").width = '0';
  1016. } else if (matchStatus == "NO_MATCH") {
  1017. PWM_MAIN.getObject("confirmCheckMark").style.visibility = 'hidden';
  1018. PWM_MAIN.getObject("confirmCrossMark").style.visibility = 'visible';
  1019. PWM_MAIN.getObject("confirmCheckMark").width = '0';
  1020. PWM_MAIN.getObject("confirmCrossMark").width = '15';
  1021. } else {
  1022. PWM_MAIN.getObject("confirmCheckMark").style.visibility = 'hidden';
  1023. PWM_MAIN.getObject("confirmCrossMark").style.visibility = 'hidden';
  1024. PWM_MAIN.getObject("confirmCheckMark").width = '0';
  1025. PWM_MAIN.getObject("confirmCrossMark").width = '0';
  1026. }
  1027. };
  1028. ChangePasswordHandler.doChange = function(settingKey, passwordValue) {
  1029. PWM_MAIN.showWaitDialog({loadFunction:function(){
  1030. PWM_CFGEDIT.writeSetting(settingKey,passwordValue,function(){
  1031. ChangePasswordHandler.clear(settingKey);
  1032. ChangePasswordHandler.init(settingKey);
  1033. PWM_MAIN.closeWaitDialog();
  1034. });
  1035. }})
  1036. };
  1037. ChangePasswordHandler.clear = function(settingKey) {
  1038. PWM_VAR['clientSettingCache'][settingKey]['settings']['p1'] = '';
  1039. PWM_VAR['clientSettingCache'][settingKey]['settings']['p2'] = '';
  1040. };
  1041. ChangePasswordHandler.generateRandom = function(settingKey) {
  1042. var length = PWM_VAR['passwordDialog-randomLength'];
  1043. var special = PWM_VAR['passwordDialog-special'];
  1044. if (!PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields']) {
  1045. PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields'] = true;
  1046. }
  1047. var charMap = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  1048. if (special) {
  1049. charMap += '~`!@#$%^&*()_-+=;:,.[]{}';
  1050. }
  1051. var postData = { };
  1052. postData.maxLength = length;
  1053. postData.minLength = length;
  1054. postData.chars = charMap;
  1055. postData.noUser = true;
  1056. PWM_MAIN.getObject('button-storePassword').disabled = true;
  1057. var url = PWM_GLOBAL['url-restservice'] + "/randompassword";
  1058. var loadFunction = function(data) {
  1059. ChangePasswordHandler.changePasswordPopup(settingKey);
  1060. PWM_MAIN.getObject('password1').value = data['data']['password'];
  1061. PWM_MAIN.getObject('password2').value = '';
  1062. PWM_MAIN.getObject('button-storePassword').disabled = false;
  1063. };
  1064. PWM_MAIN.showWaitDialog({loadFunction:function(){
  1065. PWM_MAIN.ajaxRequest(url,loadFunction,{content:postData});
  1066. }});
  1067. };
  1068. ChangePasswordHandler.changePasswordPopup = function(settingKey) {
  1069. var writeFunction = PWM_VAR['clientSettingCache'][settingKey]['settings']['writeFunction'];
  1070. var showFields = PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields'];
  1071. var p1 = PWM_VAR['clientSettingCache'][settingKey]['settings']['p1'];
  1072. var p2 = PWM_VAR['clientSettingCache'][settingKey]['settings']['p2'];
  1073. var length = 'passwordDialog-randomLength' in PWM_VAR ? PWM_VAR['passwordDialog-randomLength'] : 25;
  1074. var special = 'passwordDialog-special' in PWM_VAR ? PWM_VAR['passwordDialog-special'] : false;
  1075. var bodyText = '<table class="noborder">'
  1076. + '<tr><td><span class="formFieldLabel">' + PWM_MAIN.showString('Field_NewPassword') + '</span></td></tr>'
  1077. + '<tr><td>';
  1078. if (showFields) {
  1079. bodyText += '<textarea name="password1" id="password1" class="configStringInput" style="width: 400px; max-width: 400px; max-height:100px; overflow-y: auto" autocomplete="off">' + p1 + '</textarea>';
  1080. } else {
  1081. bodyText += '<input name="password1" id="password1" class="configStringInput" type="password" style="width: 400px;" autocomplete="off" value="' + p1 + '"></input>';
  1082. }
  1083. bodyText += '</td></tr>'
  1084. + '<tr><td><span class="formFieldLabel">' + PWM_MAIN.showString('Field_ConfirmPassword') + '</span></td></tr>'
  1085. + '<tr><td>';
  1086. if (showFields) {
  1087. bodyText += '<textarea name="password2" id="password2" class="configStringInput" style="width: 400px; max-width: 400px; max-height:100px; overflow-y: auto" autocomplete="off">' + p2 + '</textarea>';
  1088. } else {
  1089. bodyText += '<input name="password2" type="password" id="password2" class="configStringInput" style="width: 400px;" autocomplete="off" value="' + p2 + '"></input>';
  1090. }
  1091. bodyText += '</td>'
  1092. + '<td><div style="margin:0;">'
  1093. + '<img style="visibility:hidden;" id="confirmCheckMark" alt="checkMark" height="15" width="15" src="' + PWM_GLOBAL['url-resources'] + '/greenCheck.png">'
  1094. + '<img style="visibility:hidden;" id="confirmCrossMark" alt="crossMark" height="15" width="15" src="' + PWM_GLOBAL['url-resources'] + '/redX.png">'
  1095. + '</div></td>'
  1096. + '</tr></table>'
  1097. + '<br/><br/><div class="dialogSection" style="width: 400px"><span class="formFieldLabel">Generate Random Password </span><br/>'
  1098. + '<label class="checkboxWrapper"><input id="input-special" type="checkbox"' + (special ? ' checked' : '') + '>Specials</input></label>'
  1099. + '&nbsp;&nbsp;&nbsp;&nbsp;<input id="input-randomLength" type="number" min="10" max="1000" value="' + length + '" style="width:45px">Length'
  1100. + '&nbsp;&nbsp;&nbsp;&nbsp;<button id="button-generateRandom" name="button-generateRandom"><span class="fa fa-random btn-icon"></span>Generate Random</button>'
  1101. + '</div><br/><br/>'
  1102. + '<button name="button-storePassword" class="btn" id="button-storePassword" disabled="true"/>'
  1103. + '<span class="fa fa-forward btn-icon"></span>Store Password</button>&nbsp;&nbsp;'
  1104. + '<label class="checkboxWrapper"><input id="show" type="checkbox"' + (showFields ? ' checked' : '') + '>Show Passwords</input></label>'
  1105. + '</div><br/><br/>';
  1106. PWM_MAIN.showDialog({
  1107. title: 'Store Password - ' + PWM_VAR['clientSettingCache'][settingKey]['settings']['name'],
  1108. text: bodyText,
  1109. showOk: false,
  1110. showClose: true,
  1111. loadFunction:function(){
  1112. PWM_MAIN.addEventHandler('button-storePassword','click',function() {
  1113. var passwordValue = PWM_MAIN.getObject('password1').value;
  1114. PWM_MAIN.closeWaitDialog();
  1115. writeFunction(passwordValue);
  1116. });
  1117. PWM_MAIN.addEventHandler('button-generateRandom','click',function() {
  1118. PWM_VAR['passwordDialog-randomLength'] = PWM_MAIN.getObject('input-randomLength').value;
  1119. PWM_VAR['passwordDialog-special'] = PWM_MAIN.getObject('input-special').checked;
  1120. ChangePasswordHandler.generateRandom(settingKey);
  1121. });
  1122. PWM_MAIN.addEventHandler('password1','input',function(){
  1123. PWM_VAR['clientSettingCache'][settingKey]['settings']['p1'] = PWM_MAIN.getObject('password1').value;
  1124. ChangePasswordHandler.validatePasswordPopupFields();
  1125. PWM_MAIN.getObject('password2').value = '';
  1126. });
  1127. PWM_MAIN.addEventHandler('password2','input',function(){
  1128. PWM_VAR['clientSettingCache'][settingKey]['settings']['p2'] = PWM_MAIN.getObject('password2').value;
  1129. ChangePasswordHandler.validatePasswordPopupFields();
  1130. });
  1131. PWM_MAIN.addEventHandler('show','change',function(){
  1132. PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields'] = PWM_MAIN.getObject('show').checked;
  1133. ChangePasswordHandler.changePasswordPopup(settingKey);
  1134. });
  1135. PWM_MAIN.getObject('password1').focus();
  1136. ChangePasswordHandler.validatePasswordPopupFields();
  1137. }
  1138. });
  1139. };
  1140. // -------------------------- action handler ------------------------------------
  1141. var ActionHandler = {};
  1142. ActionHandler.defaultValue = {
  1143. name:"",
  1144. description:"",
  1145. type:"webservice",
  1146. method:"get",
  1147. ldapMethod:"replace",
  1148. url:"",
  1149. body:"",
  1150. headers:{},
  1151. attributeName:"",
  1152. attributeValue:""
  1153. };
  1154. ActionHandler.httpMethodOptions = [
  1155. { label: "Delete", value: "delete" },
  1156. { label: "Get", value: "get" },
  1157. { label: "Post", value: "post" },
  1158. { label: "Put", value: "put" }
  1159. ];
  1160. ActionHandler.ldapMethodOptions = [
  1161. { label: "Replace", value: "replace" },
  1162. { label: "Add", value: "add" },
  1163. { label: "Remove", value: "remove" }
  1164. ];
  1165. ActionHandler.init = function(keyName) {
  1166. console.log('ActionHandler init for ' + keyName);
  1167. var parentDiv = 'table_setting_' + keyName;
  1168. PWM_CFGEDIT.clearDivElements(parentDiv, true);
  1169. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  1170. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  1171. ActionHandler.redraw(keyName);
  1172. });
  1173. };
  1174. ActionHandler.redraw = function(keyName) {
  1175. console.log('ActionHandler redraw for ' + keyName)
  1176. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  1177. var parentDiv = 'table_setting_' + keyName;
  1178. PWM_CFGEDIT.clearDivElements(parentDiv, false);
  1179. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  1180. if (!PWM_MAIN.isEmpty(resultValue)) {
  1181. var headerRow = document.createElement("tr");
  1182. headerRow.setAttribute("style", "border-width: 0");
  1183. var header1 = document.createElement("td");
  1184. header1.setAttribute("style", "border-width: 0;");
  1185. header1.innerHTML = "Name";
  1186. headerRow.appendChild(header1);
  1187. var header2 = document.createElement("td");
  1188. header2.setAttribute("style", "border-width: 0;");
  1189. header2.innerHTML = "Description";
  1190. headerRow.appendChild(header2);
  1191. parentDivElement.appendChild(headerRow);
  1192. }
  1193. for (var i in resultValue) {
  1194. ActionHandler.drawRow(parentDiv, keyName, i, resultValue[i]);
  1195. }
  1196. var newTableRow = document.createElement("tr");
  1197. newTableRow.setAttribute("style", "border-width: 0");
  1198. newTableRow.setAttribute("colspan", "5");
  1199. var newTableData = document.createElement("td");
  1200. newTableData.setAttribute("style", "border-width: 0");
  1201. var addItemButton = document.createElement("button");
  1202. addItemButton.setAttribute("type", "button");
  1203. addItemButton.setAttribute("class", "btn");
  1204. addItemButton.setAttribute("id", "button-" + keyName + "-addValue");
  1205. addItemButton.innerHTML = '<span class="btn-icon fa fa-plus-square"></span>Add Value';
  1206. newTableData.appendChild(addItemButton);
  1207. newTableRow.appendChild(newTableData);
  1208. parentDivElement.appendChild(newTableRow);
  1209. require(["dojo/parser","dijit/form/Button","dijit/form/Select","dijit/form/Textarea"],function(dojoParser){
  1210. dojoParser.parse(parentDiv);
  1211. });
  1212. PWM_MAIN.addEventHandler('button-' + keyName + '-addValue','click',function(){
  1213. ActionHandler.addRow(keyName);
  1214. });
  1215. };
  1216. ActionHandler.drawRow = function(parentDiv, settingKey, iteration, value) {
  1217. var inputID = 'value_' + settingKey + '_' + iteration + "_";
  1218. var optionList = PWM_GLOBAL['actionTypeOptions'];
  1219. var newTableRow = document.createElement("tr");
  1220. newTableRow.setAttribute("style", "border-width: 0");
  1221. var htmlRow = '';
  1222. htmlRow += '<td>';
  1223. htmlRow += '<input id="input-' + inputID + '-name" class="configStringInput" style="width:180px" value="' + value['name'] + '"/>';
  1224. htmlRow += '</td><td>';
  1225. htmlRow += '<input id="input-' + inputID + '-description" class="configStringInput" style="width:180px" value="' + value['description'] + '"/>';
  1226. htmlRow += '</td><td>';
  1227. htmlRow += '<select id="select-' + inputID + '-type">';
  1228. for (var optionItem in optionList) {
  1229. var selected = optionList[optionItem] == PWM_VAR['clientSettingCache'][settingKey][iteration]['type'];
  1230. htmlRow += '<option value="' + optionList[optionItem] + '"' + (selected ? ' selected' : '') + '>' + optionList[optionItem] + '</option>';
  1231. }
  1232. htmlRow += '</td><td>';
  1233. htmlRow += '<button id="button-' + inputID + '-options"><span class="btn-icon fa fa-sliders"/> Options</button>';
  1234. htmlRow += '</td>';
  1235. htmlRow += '<td><span class="delete-row-icon action-icon fa fa-times" id="button-' + inputID + '-deleteRow"></span></td>';
  1236. newTableRow.innerHTML = htmlRow;
  1237. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  1238. parentDivElement.appendChild(newTableRow);
  1239. PWM_MAIN.addEventHandler('button-' + inputID + '-options','click',function(){
  1240. ActionHandler.showOptionsDialog(settingKey, iteration);
  1241. });
  1242. PWM_MAIN.addEventHandler('input-' + inputID + '-name','input',function(){
  1243. PWM_VAR['clientSettingCache'][settingKey][iteration]['name'] = PWM_MAIN.getObject('input-' + inputID + '-name').value;
  1244. ActionHandler.writeFormSetting(settingKey);
  1245. });
  1246. PWM_MAIN.addEventHandler('input-' + inputID + '-description','input',function(){
  1247. PWM_VAR['clientSettingCache'][settingKey][iteration]['description'] = PWM_MAIN.getObject('input-' + inputID + '-description').value;
  1248. ActionHandler.writeFormSetting(settingKey);
  1249. });
  1250. PWM_MAIN.addEventHandler('select-' + inputID + '-type','input',function(){
  1251. PWM_VAR['clientSettingCache'][settingKey][iteration]['type'] = PWM_MAIN.getObject('select-' + inputID + '-type').value;
  1252. ActionHandler.writeFormSetting(settingKey);
  1253. });
  1254. PWM_MAIN.addEventHandler('button-' + inputID + '-deleteRow','click',function(){
  1255. ActionHandler.removeRow(settingKey, iteration);
  1256. });
  1257. };
  1258. ActionHandler.writeFormSetting = function(settingKey, finishFunction) {
  1259. var cachedSetting = PWM_VAR['clientSettingCache'][settingKey];
  1260. PWM_CFGEDIT.writeSetting(settingKey, cachedSetting, finishFunction);
  1261. };
  1262. ActionHandler.removeRow = function(keyName, iteration) {
  1263. PWM_MAIN.showConfirmDialog({
  1264. text:'Are you sure you wish to delete this item?',
  1265. okAction:function(){
  1266. delete PWM_VAR['clientSettingCache'][keyName][iteration];
  1267. console.log("removed iteration " + iteration + " from " + keyName + ", cached keyValue=" + PWM_VAR['clientSettingCache'][keyName]);
  1268. ActionHandler.writeFormSetting(keyName,function(){
  1269. ActionHandler.init(keyName);
  1270. });
  1271. }
  1272. })
  1273. };
  1274. ActionHandler.addRow = function(keyName) {
  1275. var body='Name <input class="configStringInput" id="newActionName" style="width:300px"/>';
  1276. PWM_MAIN.showConfirmDialog({title:'New Action',text:body,showClose:true,loadFunction:function(){
  1277. PWM_MAIN.getObject('dialog_ok_button').disabled = true;
  1278. PWM_MAIN.addEventHandler('newActionName','input',function(){
  1279. PWM_VAR['newActionName'] = PWM_MAIN.getObject('newActionName').value;
  1280. if (PWM_VAR['newActionName'] && PWM_VAR['newActionName'].length > 1) {
  1281. PWM_MAIN.getObject('dialog_ok_button').disabled = false;
  1282. }
  1283. });
  1284. },okAction:function(){
  1285. var currentSize = PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][keyName]);
  1286. PWM_VAR['clientSettingCache'][keyName][currentSize + 1] = ActionHandler.defaultValue;
  1287. PWM_VAR['clientSettingCache'][keyName][currentSize + 1].name = PWM_VAR['newActionName'];
  1288. ActionHandler.writeFormSetting(keyName,function(){
  1289. ActionHandler.init(keyName);
  1290. });
  1291. }});
  1292. };
  1293. ActionHandler.showOptionsDialog = function(keyName, iteration) {
  1294. require(["dojo/store/Memory","dijit/Dialog","dijit/form/Textarea","dijit/form/CheckBox","dijit/form/Select","dijit/form/ValidationTextBox"],function(Memory){
  1295. var inputID = 'value_' + keyName + '_' + iteration + "_";
  1296. var value = PWM_VAR['clientSettingCache'][keyName][iteration];
  1297. var titleText = 'title';
  1298. var bodyText = '<table class="noborder">';
  1299. if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'webservice') {
  1300. titleText = 'Web Service options for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
  1301. bodyText += '<tr>';
  1302. bodyText += '<td class="key">HTTP Method</td><td style="border:0;"><select id="select-' + inputID + '-method' + '">';
  1303. for (var optionItem in ActionHandler.httpMethodOptions) {
  1304. var label = ActionHandler.httpMethodOptions[optionItem]['label'];
  1305. var optionValue = ActionHandler.httpMethodOptions[optionItem]['value'];
  1306. var selected = optionValue == PWM_VAR['clientSettingCache'][keyName][iteration]['method'];
  1307. bodyText += '<option value="' + optionValue + '"' + (selected ? ' selected' : '') + '>' + label + '</option>';
  1308. }
  1309. bodyText += '</td>';
  1310. bodyText += '</tr><tr>';
  1311. bodyText += '<td class="key">HTTP Headers</td><td><button id="button-' + inputID + '-headers"><span class="btn-icon fa fa-list-ul"/> Edit</button></td>';
  1312. bodyText += '</tr><tr>';
  1313. bodyText += '<td class="key">URL</td><td><input type="text" placeholder="http://www.example.com/service" id="input-' + inputID + '-url' + '" value="' + value['url'] + '"/></td>';
  1314. bodyText += '</tr><tr>';
  1315. bodyText += '<td class="key">Body</td><td><textarea style="max-width:300px; height:100px; max-height:100px" class="configStringInput" id="input-' + inputID + '-body' + '"/>' + value['body'] + '</textarea></td>';
  1316. bodyText += '</tr>';
  1317. } else if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'ldap') {
  1318. titleText = 'LDAP options for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
  1319. bodyText += '<tr>';
  1320. bodyText += '<td class="key">Attribute Name</td><td><input style="width:300px" class="configStringInput" type="text" id="input-' + inputID + '-attributeName' + '" value="' + value['attributeName'] + '"/></td>';
  1321. bodyText += '</tr><tr>';
  1322. bodyText += '<td class="key">Attribute Value</td><td><input style="width:300px" class="configStringInput" type="text" id="input-' + inputID + '-attributeValue' + '" value="' + value['attributeValue'] + '"/></td>';
  1323. bodyText += '</tr>';
  1324. bodyText += '<tr>';
  1325. bodyText += '<td class="key">Operation Type</td><td style="border:0;"><select id="select-' + inputID + '-ldapMethod' + '">';
  1326. for (var optionItem in ActionHandler.ldapMethodOptions) {
  1327. var label = ActionHandler.ldapMethodOptions[optionItem]['label'];
  1328. var optionValue = ActionHandler.ldapMethodOptions[optionItem]['value'];
  1329. var selected = optionValue == PWM_VAR['clientSettingCache'][keyName][iteration]['ldapMethod'];
  1330. bodyText += '<option value="' + optionValue + '"' + (selected ? ' selected' : '') + '>' + label + '</option>';
  1331. }
  1332. bodyText += '</td></tr>';
  1333. }
  1334. bodyText += '</table>';
  1335. PWM_MAIN.showDialog({
  1336. title: titleText,
  1337. text: bodyText,
  1338. loadFunction: function(){
  1339. PWM_MAIN.addEventHandler('button-' + inputID + '-headers','click',function(){
  1340. ActionHandler.showHeadersDialog(keyName,iteration);
  1341. });
  1342. if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'webservice') {
  1343. PWM_MAIN.addEventHandler('select-' + inputID + '-method','input',function(){
  1344. PWM_VAR['clientSettingCache'][keyName][iteration]['method'] = PWM_MAIN.getObject('select-' + inputID + '-method').value;
  1345. ActionHandler.writeFormSetting(keyName);
  1346. });
  1347. PWM_MAIN.addEventHandler('input-' + inputID + '-url','input',function(){
  1348. PWM_VAR['clientSettingCache'][keyName][iteration]['url'] = PWM_MAIN.getObject('input-' + inputID + '-url').value;
  1349. ActionHandler.writeFormSetting(keyName);
  1350. });
  1351. PWM_MAIN.addEventHandler('input-' + inputID + '-body','input',function(){
  1352. PWM_VAR['clientSettingCache'][keyName][iteration]['body'] = PWM_MAIN.getObject('input-' + inputID + '-body').value;
  1353. ActionHandler.writeFormSetting(keyName);
  1354. });
  1355. } else if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'ldap') {
  1356. PWM_MAIN.addEventHandler('input-' + inputID + '-attributeName','input',function(){
  1357. PWM_VAR['clientSettingCache'][keyName][iteration]['attributeName'] = PWM_MAIN.getObject('input-' + inputID + '-attributeName').value;
  1358. ActionHandler.writeFormSetting(keyName);
  1359. });
  1360. PWM_MAIN.addEventHandler('input-' + inputID + '-attributeValue','input',function(){
  1361. PWM_VAR['clientSettingCache'][keyName][iteration]['attributeValue'] = PWM_MAIN.getObject('input-' + inputID + '-attributeValue').value;
  1362. ActionHandler.writeFormSetting(keyName);
  1363. });
  1364. PWM_MAIN.addEventHandler('select-' + inputID + '-ldapMethod','input',function(){
  1365. PWM_VAR['clientSettingCache'][keyName][iteration]['ldapMethod'] = PWM_MAIN.getObject('select-' + inputID + '-ldapMethod').value;
  1366. ActionHandler.writeFormSetting(keyName);
  1367. });
  1368. }
  1369. }
  1370. });
  1371. });
  1372. };
  1373. ActionHandler.showHeadersDialog = function(keyName, iteration) {
  1374. require(["dijit/Dialog","dijit/form/ValidationTextBox","dijit/form/Button","dijit/form/TextBox"],function(Dialog,ValidationTextBox,Button,TextBox){
  1375. var inputID = 'value_' + keyName + '_' + iteration + "_" + "headers_";
  1376. var bodyText = '';
  1377. bodyText += '<table class="noborder">';
  1378. bodyText += '<tr>';
  1379. bodyText += '<td><b>Name</b></td><td><b>Value</b></td>';
  1380. bodyText += '</tr><tr>';
  1381. for (var headerName in PWM_VAR['clientSettingCache'][keyName][iteration]['headers']) {
  1382. var value = PWM_VAR['clientSettingCache'][keyName][iteration]['headers'][headerName];
  1383. var optionID = inputID + headerName;
  1384. bodyText += '<td>' + headerName + '</td><td>' + value + '</td>';
  1385. bodyText += '<td><span class="delete-row-icon action-icon fa fa-times" id="button-' + optionID + '-deleteRow"></span></td>';
  1386. bodyText += '</tr><tr>';
  1387. }
  1388. bodyText += '</tr></table>';
  1389. bodyText += '<br/>';
  1390. bodyText += '<button id="button-' + inputID + '-addHeader" class="btn"><span class="btn-icon fa fa-plus-square"></span>Add Header</button>';
  1391. PWM_MAIN.showDialog({
  1392. title: 'Http Headers for webservice ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'],
  1393. text: bodyText,
  1394. okAction: function() {
  1395. ActionHandler.showOptionsDialog(keyName,iteration);
  1396. },
  1397. loadFunction: function() {
  1398. for (var headerName in PWM_VAR['clientSettingCache'][keyName][iteration]['headers']) {
  1399. var headerID = inputID + headerName;
  1400. PWM_MAIN.addEventHandler('button-' + headerID + '-deleteRow','click',function(){
  1401. delete PWM_VAR['clientSettingCache'][keyName][iteration]['headers'][headerName];
  1402. ActionHandler.writeFormSetting(keyName);
  1403. ActionHandler.showHeadersDialog(keyName, iteration);
  1404. });
  1405. }
  1406. PWM_MAIN.addEventHandler('button-' + inputID + '-addHeader','click',function(){
  1407. ActionHandler.addHeader(keyName, iteration);
  1408. });
  1409. }
  1410. });
  1411. });
  1412. };
  1413. ActionHandler.addHeader = function(keyName, iteration) {
  1414. var body = '<table class="noborder">';
  1415. body += '<tr><td>Name</td><td><input class="configStringInput" id="newHeaderName" style="width:300px"/></td></tr>';
  1416. body += '<tr><td>Value</td><td><input class="configStringInput" id="newHeaderValue" style="width:300px"/></td></tr>';
  1417. body += '</table>';
  1418. var updateFunction = function(){
  1419. PWM_MAIN.getObject('dialog_ok_button').disabled = true;
  1420. PWM_VAR['newHeaderName'] = PWM_MAIN.getObject('newHeaderName').value;
  1421. PWM_VAR['newHeaderValue'] = PWM_MAIN.getObject('newHeaderValue').value;
  1422. if (PWM_VAR['newHeaderName'].length > 1 && PWM_VAR['newHeaderValue'].length > 1) {
  1423. PWM_MAIN.getObject('dialog_ok_button').disabled = false;
  1424. }
  1425. };
  1426. PWM_MAIN.showConfirmDialog({
  1427. title:'New Header',
  1428. text:body,
  1429. showClose:true,
  1430. loadFunction:function(){
  1431. PWM_MAIN.addEventHandler('newHeaderName','input',function(){
  1432. updateFunction();
  1433. });
  1434. PWM_MAIN.addEventHandler('newHeaderValue','input',function(){
  1435. updateFunction();
  1436. });
  1437. },okAction:function(){
  1438. var headers = PWM_VAR['clientSettingCache'][keyName][iteration]['headers'];
  1439. headers[PWM_VAR['newHeaderName']] = PWM_VAR['newHeaderValue'];
  1440. ActionHandler.writeFormSetting(keyName);
  1441. ActionHandler.showHeadersDialog(keyName, iteration);
  1442. }
  1443. });
  1444. };
  1445. // -------------------------- email table handler ------------------------------------
  1446. var EmailTableHandler = {};
  1447. EmailTableHandler.init = function(keyName) {
  1448. console.log('EmailTableHandler init for ' + keyName);
  1449. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  1450. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  1451. EmailTableHandler.draw(keyName);
  1452. });
  1453. };
  1454. EmailTableHandler.draw = function(keyName) {
  1455. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  1456. var parentDiv = 'table_setting_' + keyName;
  1457. PWM_CFGEDIT.clearDivElements(parentDiv, true);
  1458. require(["dojo/parser","dojo/html","dijit/form/ValidationTextBox","dijit/form/Textarea"],
  1459. function(dojoParser,dojoHtml,ValidationTextBox,Textarea){
  1460. PWM_CFGEDIT.clearDivElements(parentDiv, false);
  1461. for (var localeName in resultValue) {
  1462. EmailTableHandler.drawRow(keyName,localeName,parentDiv)
  1463. }
  1464. if (PWM_MAIN.isEmpty(resultValue)) {
  1465. var newTableRow = document.createElement("tr");
  1466. newTableRow.setAttribute("style", "border-width: 0");
  1467. newTableRow.setAttribute("colspan", "5");
  1468. var newTableData = document.createElement("td");
  1469. newTableData.setAttribute("style", "border-width: 0;");
  1470. var addItemButton = document.createElement("button");
  1471. addItemButton.setAttribute("type", "[button");
  1472. addItemButton.setAttribute("onclick", "PWM_CFGEDIT.resetSetting('" + keyName + "',function(){PWM_CFGEDIT.loadMainPageBody()});");
  1473. addItemButton.setAttribute("class", "btn");
  1474. addItemButton.innerHTML = '<span class="btn-icon fa fa-plus-square"></span>Add Value';
  1475. newTableData.appendChild(addItemButton);
  1476. newTableRow.appendChild(newTableData);
  1477. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  1478. parentDivElement.appendChild(newTableRow);
  1479. } else {
  1480. var addLocaleFunction = function(localeValue) {
  1481. if (!PWM_VAR['clientSettingCache'][keyName][localeValue]) {
  1482. PWM_VAR['clientSettingCache'][keyName][localeValue] = {};
  1483. EmailTableHandler.writeSetting(keyName,true);
  1484. }
  1485. };
  1486. PWM_CFGEDIT.addAddLocaleButtonRow(parentDiv, keyName, addLocaleFunction);
  1487. }
  1488. dojoParser.parse(parentDiv);
  1489. });
  1490. };
  1491. EmailTableHandler.drawRow = function(keyName, localeName, parentDiv) {
  1492. require(["dojo/parser","dojo/html","dijit/form/ValidationTextBox","dijit/form/Textarea"],
  1493. function(dojoParser,dojoHtml,ValidationTextBox,Textarea){
  1494. var localeTableRow = document.createElement("tr");
  1495. localeTableRow.setAttribute("style", "border-width: 0;");
  1496. var localeTdName = document.createElement("td");
  1497. localeTdName.setAttribute("style", "border-width: 0; width:15px");
  1498. localeTdName.innerHTML = localeName;
  1499. localeTableRow.appendChild(localeTdName);
  1500. var localeTdContent = document.createElement("td");
  1501. localeTdContent.setAttribute("style", "border-width: 0; width: 520px");
  1502. localeTableRow.appendChild(localeTdContent);
  1503. var localeTableElement = document.createElement("table");
  1504. localeTableElement.setAttribute("style", "border-width: 0px; width:515px; margin:0");
  1505. localeTdContent.appendChild(localeTableElement);
  1506. var idPrefix = "setting_" + localeName + "_" + keyName;
  1507. var htmlBody = '';
  1508. htmlBody += '<table class="noborder">';
  1509. htmlBody += '<tr><td style="width:30px; text-align:right">To</td>';
  1510. htmlBody += '<td><input id="' + idPrefix + '_to"/></td></tr>';
  1511. htmlBody += '<tr><td style="width:30px; text-align:right">From</td>';
  1512. htmlBody += '<td><input id="' + idPrefix + '_from"/></td></tr>';
  1513. htmlBody += '<tr><td style="width:30px; text-align:right">Subject</td>';
  1514. htmlBody += '<td><input id="' + idPrefix + '_subject"/></td></tr>';
  1515. htmlBody += '<tr><td style="width:30px; text-align:right">Plain Body</td>';
  1516. htmlBody += '<td><input id="' + idPrefix + '_bodyPlain"/></td></tr>';
  1517. htmlBody += '<tr><td style="width:30px; text-align:right">HTML Body</td>';
  1518. htmlBody += '<td><div style="border:2px solid #EAEAEA; background: white; width: 446px" onclick="EmailTableHandler.popupEditor(\'' + keyName + '\',\'' + localeName + '\')">';
  1519. htmlBody += PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'] ? PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'] : "&nbsp;" ;
  1520. htmlBody += '</div></td></tr>';
  1521. htmlBody += "</table>"
  1522. dojoHtml.set(localeTableElement,htmlBody);
  1523. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  1524. parentDivElement.appendChild(localeTableRow);
  1525. PWM_MAIN.clearDijitWidget(idPrefix + "_to");
  1526. new ValidationTextBox({
  1527. value: PWM_VAR['clientSettingCache'][keyName][localeName]['to'],
  1528. style: 'width: 450px',
  1529. required: true,
  1530. onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['to'] = this.value;EmailTableHandler.writeSetting(keyName)}
  1531. },idPrefix + "_to");
  1532. PWM_MAIN.clearDijitWidget(idPrefix + "_from");
  1533. new ValidationTextBox({
  1534. value: PWM_VAR['clientSettingCache'][keyName][localeName]['from'],
  1535. style: 'width: 450px',
  1536. required: true,
  1537. onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['from'] = this.value;EmailTableHandler.writeSetting(keyName)}
  1538. },idPrefix + "_from");
  1539. PWM_MAIN.clearDijitWidget(idPrefix + "_subject");
  1540. new ValidationTextBox({
  1541. value: PWM_VAR['clientSettingCache'][keyName][localeName]['subject'],
  1542. style: 'width: 450px',
  1543. required: true,
  1544. onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['subject'] = this.value;EmailTableHandler.writeSetting(keyName)}
  1545. },idPrefix + "_subject");
  1546. PWM_MAIN.clearDijitWidget(idPrefix + "_bodyPlain");
  1547. new Textarea({
  1548. value: PWM_VAR['clientSettingCache'][keyName][localeName]['bodyPlain'],
  1549. style: 'width: 450px',
  1550. required: true,
  1551. onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['bodyPlain'] = this.value;EmailTableHandler.writeSetting(keyName)}
  1552. },idPrefix + "_bodyPlain");
  1553. { // add a spacer row
  1554. var spacerTableRow = document.createElement("tr");
  1555. spacerTableRow.setAttribute("style", "border-width: 0");
  1556. parentDivElement.appendChild(spacerTableRow);
  1557. var spacerTableData = document.createElement("td");
  1558. spacerTableData.setAttribute("style", "border-width: 0");
  1559. spacerTableData.innerHTML = "&nbsp;";
  1560. spacerTableRow.appendChild(spacerTableData);
  1561. }
  1562. if (localeName != '' || PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][keyName])){ // add remove locale x
  1563. var imgElement2 = document.createElement("div");
  1564. imgElement2.setAttribute("style", "width: 10px; height: 10px;");
  1565. imgElement2.setAttribute("class", "delete-row-icon action-icon fa fa-times");
  1566. imgElement2.setAttribute("id", "button-" + keyName + "-" + localeName + "-deleteRow");
  1567. //imgElement2.setAttribute("onclick", "delete PWM_VAR['clientSettingCache']['" + keyName + "']['" + localeName + "'];EmailTableHandler.writeSetting('" + keyName + "',true)");
  1568. var tdElement = document.createElement("td");
  1569. tdElement.setAttribute("style", "border-width: 0; text-align: left; vertical-align: top");
  1570. localeTableRow.appendChild(tdElement);
  1571. tdElement.appendChild(imgElement2);
  1572. }
  1573. PWM_MAIN.addEventHandler("button-" + keyName + "-" + localeName + "-deleteRow","click",function(){
  1574. delete PWM_VAR['clientSettingCache'][keyName][localeName];
  1575. EmailTableHandler.writeSetting(keyName,true);
  1576. });
  1577. });
  1578. };
  1579. EmailTableHandler.popupEditor = function(keyName, localeName) {
  1580. require(["dijit/Editor","dijit/_editor/plugins/AlwaysShowToolbar","dijit/_editor/plugins/LinkDialog","dijit/_editor/plugins/ViewSource","dijit/_editor/plugins/FontChoice","dijit/_editor/plugins/TextColor"],
  1581. function(Editor,AlwaysShowToolbar){
  1582. var idValue = keyName + "_" + localeName + "_htmlEditor";
  1583. var idValueDialog = idValue + "_Dialog";
  1584. var bodyText = '';
  1585. bodyText += '<div id="' + idValue + '" style="border:2px solid #EAEAEA; min-height: 200px;"></div>';
  1586. PWM_MAIN.showDialog({
  1587. title: "HTML Editor",
  1588. text: bodyText,
  1589. dialogClass: 'wide',
  1590. loadFunction:function(){
  1591. PWM_MAIN.clearDijitWidget(idValue);
  1592. new Editor({
  1593. extraPlugins: [
  1594. AlwaysShowToolbar,"viewsource",
  1595. {name:"dijit/_editor/plugins/LinkDialog",command:"createLink",urlRegExp:".*"},
  1596. "fontName","foreColor"
  1597. ],
  1598. height: '',
  1599. value: PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'],
  1600. style: 'width: 100%',
  1601. onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'] = this.get('value')},
  1602. onKeyUp: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'] = this.get('value')}
  1603. },idValue).startup();
  1604. },
  1605. okAction:function(){
  1606. EmailTableHandler.writeSetting(keyName,true);
  1607. }
  1608. });
  1609. });
  1610. };
  1611. EmailTableHandler.writeSetting = function(settingKey, redraw) {
  1612. var currentValues = PWM_VAR['clientSettingCache'][settingKey];
  1613. PWM_CFGEDIT.writeSetting(settingKey, currentValues);
  1614. if (redraw) {
  1615. EmailTableHandler.draw(settingKey);
  1616. }
  1617. };
  1618. // -------------------------- boolean handler ------------------------------------
  1619. var BooleanHandler = {};
  1620. BooleanHandler.init = function(keyName) {
  1621. console.log('BooleanHandler init for ' + keyName);
  1622. var parentDiv = 'table_setting_' + keyName;
  1623. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  1624. parentDivElement.innerHTML = '<label class="checkboxWrapper">'
  1625. + '<input type="checkbox" id="value_' + keyName + '" value="false" disabled/>'
  1626. + 'Enabled (True)</label>';
  1627. PWM_CFGEDIT.readSetting(keyName,function(data){
  1628. var checkElement = PWM_MAIN.getObject("value_" + keyName);
  1629. checkElement.checked = data;
  1630. checkElement.disabled = false;
  1631. PWM_MAIN.addEventHandler("value_" + keyName, 'change', function(){
  1632. PWM_CFGEDIT.writeSetting(keyName,checkElement.checked);
  1633. });
  1634. });
  1635. };
  1636. BooleanHandler.toggle = function(keyName,widget) {
  1637. PWM_CFGEDIT.writeSetting(keyName,widget.checked);
  1638. };
  1639. // -------------------------- challenge handler ------------------------------------
  1640. var ChallengeSettingHandler = {};
  1641. ChallengeSettingHandler.defaultItem = {text:'Question',minLength:4,maxLength:200,adminDefined:true};
  1642. ChallengeSettingHandler.init = function(keyName) {
  1643. var parentDiv = "table_setting_" + keyName;
  1644. console.log('ChallengeSettingHandler init for ' + keyName);
  1645. PWM_CFGEDIT.clearDivElements(parentDiv, true);
  1646. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  1647. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  1648. ChallengeSettingHandler.draw(keyName);
  1649. });
  1650. };
  1651. ChallengeSettingHandler.draw = function(keyName) {
  1652. var parentDiv = "table_setting_" + keyName;
  1653. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  1654. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  1655. var bodyText = '';
  1656. bodyText += '<table style="cursor: pointer; table-layout: fixed" class="noborder">';
  1657. bodyText += '<col style="width:60px"/>';
  1658. bodyText += '<col style="width:100%"/>';
  1659. PWM_CFGEDIT.clearDivElements(parentDiv, false);
  1660. for (var localeName in resultValue) {
  1661. (function(localeKey) {
  1662. var isDefaultLocale = localeKey == "";
  1663. var multiValues = resultValue[localeKey];
  1664. var rowCount = PWM_MAIN.itemCount(multiValues);
  1665. var editJsText = 'ChallengeSettingHandler.editLocale(\'' + keyName + '\',\'' + localeKey + '\')';
  1666. bodyText += '<tr><td style="" onclick="' + editJsText + '">';
  1667. bodyText += isDefaultLocale ? "Default" : localeKey;
  1668. bodyText += '</td>';
  1669. bodyText += '<td onclick="' + editJsText + '"> ';
  1670. bodyText += '<div style="text-overflow:ellipsis; white-space:nowrap; overflow:hidden">';
  1671. if (rowCount > 0) {
  1672. for (var iteration in multiValues) {
  1673. (function (rowKey) {
  1674. var questionText = multiValues[rowKey]['text'];
  1675. var adminDefined = multiValues[rowKey]['adminDefined'];
  1676. bodyText += '<div>' + (adminDefined ? questionText : '[User Defined]') + '</div>';
  1677. }(iteration));
  1678. }
  1679. } else {
  1680. bodyText += '[No Questions]';
  1681. }
  1682. bodyText += '</div>';
  1683. //bodyText += '</td><td style="border:0; vertical-align: top">';
  1684. //if (!isDefaultLocale) {
  1685. // bodyText += '<span id="button-' + keyName + '-' + localeKey + '-deleteRow" style="top:0" class="delete-row-icon action-icon fa fa-times"/>';
  1686. //}
  1687. bodyText += '</td></tr>';
  1688. bodyText += '<tr><td>&nbsp;</td></tr>';
  1689. parentDivElement.innerHTML = bodyText;
  1690. PWM_MAIN.addEventHandler('button-' + keyName + '-' + localeKey + '-deleteRow','click',function(){
  1691. ChallengeSettingHandler.deleteLocale(keyName)
  1692. });
  1693. }(localeName));
  1694. }
  1695. bodyText += '</table>';
  1696. var addLocaleFunction = function(localeValue) {
  1697. if (localeValue in PWM_VAR['clientSettingCache'][keyName]) {
  1698. PWM_MAIN.showDialog({title:PWM_MAIN.showString('Title_Error'),text:'Locale <i>' + localeValue + '</i> is already present.'});
  1699. } else {
  1700. PWM_VAR['clientSettingCache'][keyName][localeValue] = [];
  1701. PWM_VAR['clientSettingCache'][keyName][localeValue][0] = ChallengeSettingHandler.defaultItem;
  1702. ChallengeSettingHandler.write(keyName);
  1703. ChallengeSettingHandler.editLocale(keyName,localeValue);
  1704. }
  1705. };
  1706. var tableElement = document.createElement("table");
  1707. parentDivElement.appendChild(tableElement);
  1708. PWM_CFGEDIT.addAddLocaleButtonRow(tableElement, keyName, addLocaleFunction);
  1709. };
  1710. ChallengeSettingHandler.editLocale = function(keyName, localeKey) {
  1711. var localeDisplay = localeKey == "" ? "Default" : localeKey;
  1712. var dialogBody = '<div id="challengeLocaleDialogDiv" style="max-height:500px; overflow-x: auto">';
  1713. var localeName = localeKey;
  1714. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  1715. require(["dojo","dijit/registry","dojo/parser","dijit/form/Button","dijit/form/ValidationTextBox","dijit/form/Textarea","dijit/form/NumberSpinner","dijit/form/ToggleButton"],
  1716. function(dojo,registry,dojoParser){
  1717. var multiValues = resultValue[localeName];
  1718. dialogBody += '<table class="noborder">';
  1719. for (var iteration in multiValues) {
  1720. (function(rowKey) {
  1721. var isAdminDefined = multiValues[rowKey]['adminDefined'];
  1722. var questionText = multiValues[rowKey]['text'];
  1723. dialogBody += '<tr>';
  1724. dialogBody += '<td colspan="200" style="border-width: 0;">';
  1725. var inputID = "value-" + keyName + "-" + localeName + "-" + rowKey;
  1726. PWM_MAIN.clearDijitWidget(inputID);
  1727. dialogBody += '<textarea id="' + inputID + '" style="width: 700px" required="required"';
  1728. dialogBody += ' data-dojo-type="dijit/form/Textarea' + '"';
  1729. dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'text\'] = this.value"';
  1730. if (!isAdminDefined) {
  1731. dialogBody += ' disabled="disabled"';
  1732. dialogBody += ' value="[User Defined]"';
  1733. } else {
  1734. dialogBody += ' value="' + questionText + '"';
  1735. }
  1736. dialogBody += '></textarea>';
  1737. dialogBody += '<div class="delete-row-icon action-icon fa fa-times"';
  1738. dialogBody += ' onclick="ChallengeSettingHandler.deleteRow(\'' + keyName + '\',\'' + localeKey + '\',\'' + rowKey + '\')");';
  1739. dialogBody += '/>';
  1740. dialogBody += '</td>';
  1741. dialogBody += '</tr>';
  1742. dialogBody += '<tr style="padding-bottom: 15px; border:0"><td style="padding-bottom: 15px; border:0">';
  1743. dialogBody += '<button data-dojo-type="dijit/form/ToggleButton" data-dojo-props="iconClass:\'dijitCheckBoxIcon\',showLabel:true,label:\'Admin Defined\',checked:' + isAdminDefined + '"';
  1744. dialogBody += ' onchange="ChallengeSettingHandler.toggleAdminDefinedRow(this,\'' + inputID + '\',\'' + keyName + '\',\'' + localeKey + '\',\'' + rowKey + '\')"';
  1745. dialogBody += '></button>';
  1746. dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
  1747. dialogBody += '<input style="width: 50px" data-dojo-type="dijit/form/NumberSpinner" value="' +multiValues[rowKey]['minLength'] + '" data-dojo-props="constraints:{min:0,max:255,places:0}""';
  1748. dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'minLength\'] = this.value"/><br/>Min Length';
  1749. dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
  1750. dialogBody += '<input style="width: 50px" data-dojo-type="dijit/form/NumberSpinner" value="' +multiValues[rowKey]['maxLength'] + '" data-dojo-props="constraints:{min:0,max:255,places:0}""';
  1751. dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'maxLength\'] = this.value"/><br/>Max Length';
  1752. dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
  1753. dialogBody += '<input style="width: 50px" data-dojo-type="dijit/form/NumberSpinner" value="' +multiValues[rowKey]['maxQuestionCharsInAnswer'] + '" data-dojo-props="constraints:{min:0,max:255,places:0}""';
  1754. dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'maxQuestionCharsInAnswer\'] = this.value"/><br/> Max Question Chars';
  1755. dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
  1756. var enforceWordlist = multiValues[rowKey]['enforceWordlist'];
  1757. dialogBody += '<button data-dojo-type="dijit/form/ToggleButton" data-dojo-props="iconClass:\'dijitCheckBoxIcon\',showLabel:true,label:\'Enforce Wordlist\',checked:' + enforceWordlist + '"';
  1758. dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'enforceWordlist\'] = this.checked"';
  1759. dialogBody += '></button>';
  1760. /*
  1761. dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
  1762. dialogBody += '<input style="width: 50px" data-dojo-type="dijit/form/NumberSpinner" value="' +multiValues[rowKey]['points'] + '" data-dojo-props="constraints:{min:0,max:255,places:0}""';
  1763. dialogBody += ' onchange="PWM_VAR['clientSettingCache'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'points\'] = this.value"/><br/>Points';
  1764. */
  1765. dialogBody += '</td></tr>';
  1766. }(iteration));
  1767. }
  1768. dialogBody += '</table></div>';
  1769. dialogBody += '<br/><br/><button type="button" data-dojo-type="dijit/form/Button"';
  1770. dialogBody += ' onclick="ChallengeSettingHandler.addRow(\'' + keyName + '\',\'' + localeKey + '\')"';
  1771. dialogBody += '><span class="btn-icon fa fa-plus-square"></span>Add Value</button>';
  1772. if (localeKey != "") {
  1773. dialogBody += '<button type="button" data-dojo-type="dijit/form/Button"';
  1774. dialogBody += ' onclick="ChallengeSettingHandler.deleteLocale(\'' + keyName + '\',\'' + localeKey + '\')"';
  1775. dialogBody += '><span class="btn-icon fa fa-times"></span>Delete Locale ' + localeDisplay + '</button>';
  1776. }
  1777. var dialogTitle = PWM_SETTINGS['settings'][keyName]['label'] + ' - ' + localeDisplay;
  1778. PWM_MAIN.showDialog({title:dialogTitle,text:dialogBody,showClose:true,dialogClass:'wide',loadFunction:function(){
  1779. dojoParser.parse(PWM_MAIN.getObject('challengeLocaleDialogDiv'));
  1780. },okAction:function(){
  1781. ChallengeSettingHandler.write(keyName );
  1782. ChallengeSettingHandler.draw(keyName);
  1783. }});
  1784. }
  1785. );
  1786. };
  1787. ChallengeSettingHandler.deleteLocale = function(keyName,localeKey) {
  1788. PWM_MAIN.showConfirmDialog({
  1789. text: 'Are you sure you want to remove all the questions for the <i>' + localeKey + '</i> locale?',
  1790. okAction:function(){
  1791. PWM_MAIN.showWaitDialog();
  1792. delete PWM_VAR['clientSettingCache'][keyName][localeKey];
  1793. PWM_CFGEDIT.writeSetting(keyName, PWM_VAR['clientSettingCache'][keyName],function(){
  1794. PWM_MAIN.closeWaitDialog();
  1795. ChallengeSettingHandler.init(keyName);
  1796. });
  1797. }
  1798. });
  1799. };
  1800. ChallengeSettingHandler.toggleAdminDefinedRow = function(toggleElement,inputID,keyName,localeKey,rowKey) {
  1801. require(["dojo","dijit/registry"],function(dojo,registry){
  1802. var currentSetting = toggleElement.checked;
  1803. PWM_VAR['clientSettingCache'][keyName][localeKey][rowKey]['adminDefined'] = currentSetting;
  1804. var inputElement = registry.byId(inputID);
  1805. if (currentSetting) {
  1806. inputElement.set('disabled',false);
  1807. inputElement.set('value','Question');
  1808. } else {
  1809. inputElement.set('disabled',true);
  1810. inputElement.set('value','[User Defined]');
  1811. PWM_VAR['clientSettingCache'][keyName][localeKey][rowKey]['text'] = '';
  1812. }
  1813. });
  1814. };
  1815. ChallengeSettingHandler.deleteRow = function(keyName, localeKey, rowName) {
  1816. delete PWM_VAR['clientSettingCache'][keyName][localeKey][rowName];
  1817. ChallengeSettingHandler.editLocale(keyName, localeKey);
  1818. };
  1819. ChallengeSettingHandler.addRow = function(keyName, localeKey) {
  1820. PWM_VAR['clientSettingCache'][keyName][localeKey].push(ChallengeSettingHandler.defaultItem);
  1821. ChallengeSettingHandler.write(keyName);
  1822. ChallengeSettingHandler.editLocale(keyName, localeKey);
  1823. };
  1824. ChallengeSettingHandler.write = function(keyName) {
  1825. PWM_CFGEDIT.writeSetting(keyName, PWM_VAR['clientSettingCache'][keyName]);
  1826. };
  1827. // -------------------------- user permission handler ------------------------------------
  1828. var UserPermissionHandler = {};
  1829. UserPermissionHandler.defaultFilterValue = {type:'ldapFilter',ldapQuery:"(objectClass=*)",ldapBase:""};
  1830. UserPermissionHandler.defaultGroupValue = {type:'ldapGroup',ldapBase:"cn=exampleGroup,ou=container,o=organization"};
  1831. UserPermissionHandler.init = function(keyName) {
  1832. console.log('UserPermissionHandler init for ' + keyName);
  1833. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  1834. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  1835. UserPermissionHandler.draw(keyName);
  1836. });
  1837. };
  1838. UserPermissionHandler.draw = function(keyName) {
  1839. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  1840. var parentDiv = 'table_setting_' + keyName;
  1841. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  1842. while (parentDivElement.firstChild) {
  1843. parentDivElement.removeChild(parentDivElement.firstChild);
  1844. }
  1845. var htmlBody = '';
  1846. for (var iteration in resultValue) {
  1847. (function(rowKey) {
  1848. var inputID = "value-" + keyName + "-" + rowKey;
  1849. htmlBody += '<div class="setting_item_value_wrapper" style="float:left; width: 570px;"><div style="width:100%; text-align:center">';
  1850. if (resultValue[rowKey]['type'] == 'ldapGroup') {
  1851. htmlBody += 'LDAP Group';
  1852. } else {
  1853. htmlBody += 'LDAP Filter';
  1854. }
  1855. var currentProfileValue = ('ldapProfileID' in resultValue[rowKey]) ? resultValue[rowKey]['ldapProfileID'] : "";
  1856. htmlBody += '</div><table class="noborder">'
  1857. + '<td style="width:200px" id="' + inputID + '_profileHeader' + '">' + PWM_CONFIG.showString('Setting_Permission_Profile') + '</td>'
  1858. + '<td><input style="width: 200px;" class="configStringInput" id="' + inputID + '-profile" list="' + inputID + '-datalist" value="' + currentProfileValue + '"/>'
  1859. + '<datalist id="' + inputID + '-datalist"/></td>'
  1860. + '</tr>';
  1861. if (resultValue[rowKey]['type'] != 'ldapGroup') {
  1862. var currentQueryValue = ('ldapQuery' in resultValue[rowKey]) ? resultValue[rowKey]['ldapQuery'] : "";
  1863. htmlBody += '<tr>'
  1864. + '<td><span id="' + inputID + '_FilterHeader' + '">' + PWM_CONFIG.showString('Setting_Permission_Filter') + '</span></td>'
  1865. + '<td><input style="width: 420px;" class="configStringInput" id="' + inputID + '-query" value="' + currentQueryValue + '"></input></td>'
  1866. + '</tr>';
  1867. }
  1868. var currentBaseValue = ('ldapBase' in resultValue[rowKey]) ? resultValue[rowKey]['ldapBase'] : "";
  1869. htmlBody += '<tr>'
  1870. + '<td><span id="' + inputID + '_BaseHeader' + '">'
  1871. + PWM_CONFIG.showString((resultValue[rowKey]['type'] == 'ldapGroup') ? 'Setting_Permission_Base_Group' : 'Setting_Permission_Base')
  1872. + '</span></td>'
  1873. + '<td><input style="width: 420px;" class="configStringInput" id="' + inputID + '-base" value="' + currentBaseValue + '"></input></td>'
  1874. + '</td>'
  1875. + '</tr>';
  1876. htmlBody += '</table></div><div id="button-' + inputID + '-deleteRow" style="float:right" class="delete-row-icon action-icon fa fa-times"></div>';
  1877. }(iteration));
  1878. }
  1879. parentDivElement.innerHTML = parentDivElement.innerHTML + htmlBody;
  1880. setTimeout(function(){
  1881. for (var iteration in resultValue) {
  1882. (function(rowKey) {
  1883. var inputID = "value-" + keyName + "-" + rowKey;
  1884. console.log('inputID-' + inputID);
  1885. var profileSelectElement = PWM_MAIN.getObject(inputID + "-datalist");
  1886. profileSelectElement.appendChild(new Option('all'));
  1887. for (var i in PWM_VAR['ldapProfileIds']) {
  1888. profileSelectElement.appendChild(new Option(PWM_VAR['ldapProfileIds'][i]));
  1889. }
  1890. PWM_MAIN.addEventHandler(inputID + '-profile','input',function(){
  1891. console.log('write');
  1892. PWM_VAR['clientSettingCache'][keyName][rowKey]['ldapProfileID'] = this.value;
  1893. UserPermissionHandler.write(keyName);
  1894. });
  1895. if (resultValue[rowKey]['type'] != 'ldapGroup') {
  1896. var queryInput = PWM_MAIN.getObject(inputID + "-query");
  1897. queryInput.disabled = false;
  1898. queryInput.required = true;
  1899. PWM_MAIN.addEventHandler(inputID + "-query",'input',function(){
  1900. PWM_VAR['clientSettingCache'][keyName][rowKey]['ldapQuery'] = this.value;
  1901. UserPermissionHandler.write(keyName);
  1902. });
  1903. }
  1904. var queryInput = PWM_MAIN.getObject(inputID + "-base");
  1905. queryInput.disabled = false;
  1906. queryInput.required = true;
  1907. PWM_MAIN.addEventHandler(inputID + "-base",'input',function(){
  1908. PWM_VAR['clientSettingCache'][keyName][rowKey]['ldapBase'] = this.value;
  1909. UserPermissionHandler.write(keyName);
  1910. });
  1911. var deleteButtonID = 'button-' + inputID + '-deleteRow';
  1912. var hasID = PWM_MAIN.getObject(deleteButtonID) ? "YES" : "NO";
  1913. console.log("addEventHandler row: " + deleteButtonID + " rowKey=" + rowKey + " hasID="+hasID);
  1914. PWM_MAIN.addEventHandler(deleteButtonID,'click',function(){
  1915. console.log("delete row: " + inputID + " rowKey=" + rowKey + " hasID="+hasID);
  1916. delete PWM_VAR['clientSettingCache'][keyName][rowKey];
  1917. UserPermissionHandler.write(keyName,true);
  1918. });
  1919. PWM_MAIN.showTooltip({
  1920. id:inputID +'_profileHeader',
  1921. width: 300,
  1922. text:PWM_CONFIG.showString('Tooltip_Setting_Permission_Profile')
  1923. });
  1924. PWM_MAIN.showTooltip({
  1925. id:inputID +'_FilterHeader',
  1926. width: 300,
  1927. text:PWM_CONFIG.showString('Tooltip_Setting_Permission_Filter')
  1928. });
  1929. PWM_MAIN.showTooltip({
  1930. id: inputID + '_BaseHeader',
  1931. width: 300,
  1932. text: PWM_CONFIG.showString('Tooltip_Setting_Permission_Base')
  1933. });
  1934. }(iteration));
  1935. }
  1936. },10);
  1937. var options = PWM_SETTINGS['settings'][keyName]['options'];
  1938. var buttonRowHtml = '<button class="btn" id="button-' + keyName + '-addFilterValue">'
  1939. + '<span class="btn-icon fa fa-plus-square"></span>Add Filter</button>';
  1940. var hideGroup = 'hideGroups' in options && options['hideGroups'] == "true";
  1941. if (!hideGroup) {
  1942. buttonRowHtml += '<button class="btn" id="button-' + keyName + '-addGroupValue">'
  1943. + '<span class="btn-icon fa fa-plus-square"></span>Add Group</button>';
  1944. }
  1945. var hideMatch = 'hideMatch' in options && options['hideMatch'] == "true";
  1946. if (!hideMatch) {
  1947. buttonRowHtml += '<button id="button-' + keyName + '-viewMatches" class="btn">'
  1948. + '<span class="btn-icon fa fa-eye"></span>View Matches</button>';
  1949. }
  1950. parentDivElement.innerHTML = parentDivElement.innerHTML + buttonRowHtml;
  1951. PWM_MAIN.addEventHandler('button-' + keyName + '-viewMatches','click',function(){
  1952. PWM_CFGEDIT.executeSettingFunction(keyName,'password.pwm.config.function.UserMatchViewerFunction')
  1953. });
  1954. PWM_MAIN.addEventHandler('button-' + keyName + '-addFilterValue','click',function(){
  1955. PWM_VAR['clientSettingCache'][keyName].push(UserPermissionHandler.defaultFilterValue);
  1956. UserPermissionHandler.write(keyName, true);
  1957. });
  1958. PWM_MAIN.addEventHandler('button-' + keyName + '-addGroupValue','click',function(){
  1959. PWM_VAR['clientSettingCache'][keyName].push(UserPermissionHandler.defaultGroupValue);
  1960. UserPermissionHandler.write(keyName, true);
  1961. });
  1962. };
  1963. UserPermissionHandler.write = function(settingKey,redraw) {
  1964. var nextFunction = function(){
  1965. if (redraw) {
  1966. UserPermissionHandler.draw(settingKey);
  1967. }
  1968. };
  1969. PWM_CFGEDIT.writeSetting(settingKey, PWM_VAR['clientSettingCache'][settingKey], nextFunction);
  1970. };
  1971. // -------------------------- option list handler ------------------------------------
  1972. var OptionListHandler = {};
  1973. OptionListHandler.defaultItem = [];
  1974. OptionListHandler.init = function(keyName) {
  1975. console.log('OptionListHandler init for ' + keyName);
  1976. var parentDiv = 'table_setting_' + keyName;
  1977. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  1978. var htmlBody = '';
  1979. var options = PWM_SETTINGS['settings'][keyName]['options'];
  1980. for (var key in options) {
  1981. (function (optionKey) {
  1982. var buttonID = keyName + "_button_" + optionKey;
  1983. htmlBody += '<label class="checkboxWrapper" style="min-width:180px;">'
  1984. + '<input type="checkbox" id="' + buttonID + '" disabled/>'
  1985. + options[optionKey] + '</label>';
  1986. })(key);
  1987. }
  1988. parentDivElement.innerHTML = htmlBody;
  1989. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  1990. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  1991. OptionListHandler.draw(keyName);
  1992. });
  1993. };
  1994. OptionListHandler.draw = function(keyName) {
  1995. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  1996. require(["dojo/_base/array"],function(array){
  1997. var options = PWM_SETTINGS['settings'][keyName]['options'];
  1998. for (var key in options) {
  1999. (function (optionKey) {
  2000. var buttonID = keyName + "_button_" + optionKey;
  2001. var checked = array.indexOf(resultValue,optionKey) > -1;
  2002. PWM_MAIN.getObject(buttonID).checked = checked;
  2003. PWM_MAIN.getObject(buttonID).disabled = false;
  2004. PWM_MAIN.addEventHandler(buttonID,'change',function(){
  2005. OptionListHandler.toggle(keyName,optionKey);
  2006. });
  2007. })(key);
  2008. }
  2009. });
  2010. };
  2011. OptionListHandler.toggle = function(keyName,optionKey) {
  2012. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  2013. require(["dojo/_base/array"],function(array){
  2014. var checked = array.indexOf(resultValue,optionKey) > -1;
  2015. if (checked) {
  2016. var index = array.indexOf(resultValue, optionKey);
  2017. while (index > -1) {
  2018. resultValue.splice(index, 1);
  2019. index = array.indexOf(resultValue, optionKey);
  2020. }
  2021. } else {
  2022. resultValue.push(optionKey);
  2023. }
  2024. });
  2025. PWM_CFGEDIT.writeSetting(keyName, resultValue);
  2026. };
  2027. // -------------------------- numeric value handler ------------------------------------
  2028. var NumericValueHandler = {};
  2029. NumericValueHandler.init = function(settingKey) {
  2030. NumericValueHandler.impl(settingKey, 'number', 0, 100);
  2031. };
  2032. NumericValueHandler.impl = function(settingKey, type, defaultMin, defaultMax) {
  2033. var parentDiv = 'table_setting_' + settingKey;
  2034. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  2035. var options = PWM_SETTINGS['settings'][settingKey]['options'];
  2036. var pattern = PWM_SETTINGS['settings'][settingKey]['pattern'];
  2037. var min = 'min' in options ? parseInt(options['min']) : defaultMin;
  2038. var max = 'max' in options ? parseInt(options['max']) : defaultMax;
  2039. var htmlBody = '<input type="number" id="value_' + settingKey + '" class="configNumericInput" min="'+min+'" max="'+max+'"/>';
  2040. if (type == 'number') {
  2041. htmlBody += '<span class="configNumericLimits">' + min + ' - ' + max + '</span>';
  2042. } else if (type == 'duration') {
  2043. htmlBody += '<span class="configNumericLimits">' + PWM_MAIN.showString('Display_Seconds') + '</span>'
  2044. htmlBody += '<span style="margin-left:10px" id="display-' + settingKey + '-duration"></span>';
  2045. }
  2046. parentDivElement.innerHTML = htmlBody;
  2047. PWM_CFGEDIT.readSetting(settingKey,function(data){
  2048. PWM_MAIN.getObject('value_' + settingKey).value = data;
  2049. PWM_VAR['clientSettingCache'][settingKey] = data;
  2050. PWM_MAIN.addEventHandler('value_' + settingKey,'input',function(){
  2051. var value = PWM_MAIN.getObject('value_' + settingKey).value;
  2052. var valid = value.match(/[0-9]+/);
  2053. if (valid) {
  2054. console.log('valid');
  2055. PWM_VAR['clientSettingCache'][settingKey] = data;
  2056. PWM_CFGEDIT.writeSetting(settingKey, value);
  2057. NumericValueHandler.updateDurationDisplay(settingKey,value);
  2058. } else {
  2059. console.log('invalid');
  2060. PWM_MAIN.getObject('value_' + settingKey).value = PWM_VAR['clientSettingCache'][settingKey];
  2061. }
  2062. });
  2063. PWM_MAIN.addEventHandler('value_' + settingKey,'mousewheel',function(e){ e.blur(); });
  2064. NumericValueHandler.updateDurationDisplay(settingKey,data);
  2065. });
  2066. };
  2067. NumericValueHandler.updateDurationDisplay = function(settingKey, numberValue) {
  2068. var displayElement = PWM_MAIN.getObject('display-' + settingKey + '-duration');
  2069. if (displayElement) {
  2070. displayElement.innerHTML = (numberValue && numberValue != 0)
  2071. ? PWM_MAIN.convertSecondsToDisplayTimeDuration(numberValue, true)
  2072. : '';
  2073. }
  2074. };
  2075. // -------------------------- duration value ---------------------------
  2076. var DurationValueHandler = {};
  2077. DurationValueHandler.init = function(settingKey) {
  2078. NumericValueHandler.impl(settingKey, 'duration', -1, 365 * 24 * 60 * 60 );
  2079. };
  2080. // -------------------------- string value handler ------------------------------------
  2081. var StringValueHandler = {};
  2082. StringValueHandler.init = function(settingKey) {
  2083. var parentDiv = 'table_setting_' + settingKey;
  2084. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  2085. parentDivElement.innerHTML = '<input class="configStringInput" id="value_' + settingKey + '" name="setting_' + settingKey + '" disabled/>'
  2086. + '&nbsp;<span id="icon-' + settingKey + '-warning" style="visibility:hidden; color:orange" class="btn-icon fa fa-warning"></span>';
  2087. PWM_CFGEDIT.readSetting(settingKey,function(data){
  2088. var inputElement = PWM_MAIN.getObject("value_" + settingKey);
  2089. inputElement.value = data;
  2090. if (PWM_SETTINGS['settings'][settingKey]['required']) {
  2091. inputElement.required = true;
  2092. }
  2093. if (PWM_SETTINGS['settings'][settingKey]['pattern']) {
  2094. inputElement.pattern = PWM_SETTINGS['settings'][settingKey]['pattern'];
  2095. inputElement.title = PWM_CONFIG.showString('Warning_InvalidFormat');
  2096. var validateValue = function() {
  2097. var re = new RegExp(PWM_SETTINGS['settings'][settingKey]['pattern']);
  2098. var matches = re.test(inputElement.value);
  2099. PWM_MAIN.getObject('icon-' + settingKey + '-warning').style.visibility = matches ? 'hidden' : 'visible';
  2100. };
  2101. PWM_MAIN.addEventHandler("value_" + settingKey,"keyup",function(){
  2102. validateValue();
  2103. });
  2104. validateValue();
  2105. PWM_MAIN.showTooltip({id:'icon-'+settingKey+'-warning',text:PWM_CONFIG.showString('Warning_InvalidFormat')});
  2106. }
  2107. if (PWM_SETTINGS['settings'][settingKey]['placeholder']) {
  2108. inputElement.placeholder = PWM_SETTINGS['settings'][settingKey]['placeholder'];
  2109. }
  2110. inputElement.disabled = false;
  2111. PWM_MAIN.addEventHandler("value_" + settingKey,"input,change",function(){
  2112. PWM_CFGEDIT.writeSetting(settingKey,inputElement.value);
  2113. });
  2114. });
  2115. };
  2116. // -------------------------- text area handler ------------------------------------
  2117. var TextAreaValueHandler = {};
  2118. TextAreaValueHandler.init = function(settingKey) {
  2119. var parentDiv = 'table_setting_' + settingKey;
  2120. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  2121. parentDivElement.innerHTML = '<textarea style="max-height:300px; overflow-y: auto" id="value_' + settingKey + '" name="setting_' + settingKey + '">&nbsp;</textarea>';
  2122. PWM_MAIN.clearDijitWidget("value_" + settingKey);
  2123. require(["dijit/form/Textarea"],function(Textarea){
  2124. new Textarea({
  2125. regExp: PWM_SETTINGS['settings'][settingKey]['pattern'],
  2126. required: PWM_SETTINGS['settings'][settingKey]['required'],
  2127. invalidMessage: PWM_CONFIG.showString('Warning_InvalidFormat'),
  2128. style: "width: 550px; max-width:550px; max-height:300px; overflow:auto; white-space: nowrap",
  2129. onChange: function() {
  2130. PWM_CFGEDIT.writeSetting(settingKey, this.value);
  2131. },
  2132. placeholder: PWM_SETTINGS['settings'][settingKey]['placeholder'],
  2133. value: PWM_MAIN.showString('Display_PleaseWait'),
  2134. disabled: true,
  2135. id: "value_" + settingKey
  2136. }, "value_" + settingKey);
  2137. PWM_CFGEDIT.readInitialTextBasedValue(settingKey);
  2138. });
  2139. };
  2140. // -------------------------- select value handler ------------------------------------
  2141. var SelectValueHandler = {};
  2142. SelectValueHandler.init = function(settingKey) {
  2143. var parentDiv = 'table_setting_' + settingKey;
  2144. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  2145. var htmlBody = '<select id="setting_' + settingKey + '" disabled="true">'
  2146. + '<option value="' + PWM_MAIN.showString('Display_PleaseWait') + '">' + PWM_MAIN.showString('Display_PleaseWait') + '</option></select>';
  2147. parentDivElement.innerHTML = htmlBody;
  2148. PWM_MAIN.clearDijitWidget("value_" + settingKey);
  2149. PWM_MAIN.clearDijitWidget("setting_" + settingKey);
  2150. PWM_MAIN.addEventHandler('setting_' + settingKey,'change',function(){
  2151. var settingElement = PWM_MAIN.getObject('setting_' + settingKey);
  2152. var selectedValue = settingElement.options[settingElement.selectedIndex].value;
  2153. PWM_CFGEDIT.writeSetting(settingKey,selectedValue)
  2154. });
  2155. PWM_CFGEDIT.readSetting(settingKey, function(dataValue) {
  2156. var settingElement = PWM_MAIN.getObject('setting_' + settingKey);
  2157. var optionsHtml = '';
  2158. var options = PWM_SETTINGS['settings'][settingKey]['options'];
  2159. for (var option in options) {
  2160. var optionValue = options[option];
  2161. optionsHtml += '<option value="' + option + '">' + optionValue + '</option>'
  2162. }
  2163. settingElement.innerHTML = optionsHtml;
  2164. settingElement.value = dataValue;
  2165. settingElement.disabled = false;
  2166. });
  2167. };
  2168. // -------------------------- x509 setting handler ------------------------------------
  2169. var X509CertificateHandler = {};
  2170. X509CertificateHandler.init = function(keyName) {
  2171. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  2172. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  2173. X509CertificateHandler.draw(keyName);
  2174. });
  2175. };
  2176. X509CertificateHandler.draw = function(keyName) {
  2177. var parentDiv = 'table_setting_' + keyName;
  2178. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  2179. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  2180. var htmlBody = '<div style="max-height: 300px; overflow-y: auto">';
  2181. for (var certCounter in resultValue) {
  2182. (function (counter) {
  2183. var certificate = resultValue[counter];
  2184. htmlBody += '<div style="max-width:100%; margin-bottom:8px"><table style="max-width:100%" id="table_certificate' + keyName + '-' + counter + '">';
  2185. htmlBody += '<tr><td colspan="2" class="key" style="text-align: center">Certificate ' + counter + ' <a id="certTimestamp-detail-' + keyName + '-' + counter + '">(detail)</a></td></tr>';
  2186. htmlBody += '<tr><td>Subject</td><td><div class="setting_table_value">' + certificate['subject'] + '</div></td></tr>';
  2187. htmlBody += '<tr><td>Issuer</td><td><div class="setting_table_value">' + certificate['issuer'] + '</div></td></tr>';
  2188. htmlBody += '<tr><td>Serial</td><td><div class="setting_table_value">' + certificate['serial'] + '</div></td></tr>';
  2189. htmlBody += '<tr><td>Issue Date</td><td id="certTimestamp-issue-' + keyName + '-' + counter + '" class="setting_table_value timestamp">' + certificate['issueDate'] + '</td></tr>';
  2190. htmlBody += '<tr><td>Expire Date</td><td id="certTimestamp-expire-' + keyName + '-' + counter + '" class="setting_table_value timestamp">' + certificate['expireDate'] + '</td></tr>';
  2191. htmlBody += '<tr><td>MD5 Hash</td><td><div class="setting_table_value">' + certificate['md5Hash'] + '</div></td></tr>';
  2192. htmlBody += '<tr><td>SHA1 Hash</td><td><div class="setting_table_value">' + certificate['sha1Hash'] + '</div></td></tr>';
  2193. htmlBody += '<tr><td>SHA512 Hash</td><td><div class="setting_table_value">' + certificate['sha512Hash'] + '</div></td></tr>';
  2194. htmlBody += '</table></div>'
  2195. })(certCounter);
  2196. }
  2197. htmlBody += '</div>';
  2198. if (!PWM_MAIN.isEmpty(resultValue)) {
  2199. htmlBody += '<button id="' + keyName + '_ClearButton" class="btn"><span class="btn-icon fa fa-times"></span>Clear</button>'
  2200. } else {
  2201. htmlBody += 'No certificates stored.<br/><br/>'
  2202. }
  2203. htmlBody += '<button id="' + keyName + '_AutoImportButton" class="btn"><span class="btn-icon fa fa-download"></span>Import From Server</button>'
  2204. parentDivElement.innerHTML = htmlBody;
  2205. for (certCounter in resultValue) {
  2206. (function (counter) {
  2207. PWM_MAIN.TimestampHandler.initElement(PWM_MAIN.getObject('certTimestamp-issue-' + keyName + '-' + counter));
  2208. PWM_MAIN.TimestampHandler.initElement(PWM_MAIN.getObject('certTimestamp-expire-' + keyName + '-' + counter));
  2209. PWM_MAIN.addEventHandler('certTimestamp-detail-' + keyName + '-' + counter,'click',function(){
  2210. PWM_MAIN.showDialog({
  2211. title: 'Detail - ' + PWM_SETTINGS['settings'][keyName]['label'] + ' - Certificate ' + counter,
  2212. text: '<pre>' + resultValue[counter]['detail'] + '</pre>',
  2213. dialogClass: 'wide',
  2214. showClose: true
  2215. });
  2216. });
  2217. })(certCounter);
  2218. }
  2219. if (!PWM_MAIN.isEmpty(resultValue)) {
  2220. PWM_MAIN.addEventHandler(keyName + '_ClearButton','click',function(){
  2221. handleResetClick(keyName);
  2222. });
  2223. }
  2224. PWM_MAIN.addEventHandler(keyName + '_AutoImportButton','click',function(){
  2225. switch (keyName) {
  2226. case 'ldap.serverCerts':
  2227. PWM_CFGEDIT.executeSettingFunction(keyName,'password.pwm.config.function.LdapCertImportFunction');
  2228. break;
  2229. case 'audit.syslog.certificates':
  2230. PWM_CFGEDIT.executeSettingFunction(keyName,'password.pwm.config.function.SyslogCertImportFunction');
  2231. break;
  2232. default:
  2233. alert('unhandled cert-import request for key=' + keyName);
  2234. }
  2235. });
  2236. };
  2237. // -------------------------- file setting handler ------------------------------------
  2238. var FileValueHandler = {};
  2239. FileValueHandler.init = function(keyName) {
  2240. PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
  2241. PWM_VAR['clientSettingCache'][keyName] = resultValue;
  2242. FileValueHandler.draw(keyName);
  2243. });
  2244. };
  2245. FileValueHandler.draw = function(keyName) {
  2246. var parentDiv = 'table_setting_' + keyName;
  2247. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  2248. var resultValue = PWM_VAR['clientSettingCache'][keyName];
  2249. var htmlBody = '';
  2250. if (PWM_MAIN.isEmpty(resultValue)) {
  2251. htmlBody = '<p>No File Present</p>';
  2252. } else {
  2253. for (var fileCounter in resultValue) {
  2254. (function (counter) {
  2255. var fileInfo = resultValue[counter];
  2256. htmlBody += '<table style="width:100%" id="table_file' + keyName + '-' + counter + '">';
  2257. htmlBody += '<tr><td colspan="2" class="key" style="text-align: center">File' + '</td></tr>';
  2258. htmlBody += '<tr><td>Name</td><td class="setting_table_value">' + fileInfo['name'] + '</td></tr>';
  2259. htmlBody += '<tr><td>Size</td><td class="setting_table_value">' + fileInfo['size'] + '</td></tr>';
  2260. htmlBody += '<tr><td>MD5 checksum</td><td class="setting_table_value">' + fileInfo['md5sum'] + '</td></tr>';
  2261. htmlBody += '<tr><td>SHA1 checksum</td><td class="setting_table_value">' + fileInfo['sha1sum'] + '</td></tr>';
  2262. htmlBody += '</table>'
  2263. })(fileCounter);
  2264. }
  2265. }
  2266. if (PWM_MAIN.isEmpty(resultValue)) {
  2267. htmlBody += '<button class="btn" id="button-uploadFile-' + keyName + '"><span class="btn-icon fa fa-upload"></span>Upload File</button>';
  2268. } else {
  2269. htmlBody += '<button class="btn" id="button-removeFile-' + keyName + '"><span class="btn-icon fa fa-trash-o"></span>Remove File</button>';
  2270. }
  2271. parentDivElement.innerHTML = htmlBody;
  2272. PWM_MAIN.addEventHandler('button-uploadFile-' + keyName,'click',function(){
  2273. FileValueHandler.uploadFile(keyName);
  2274. });
  2275. PWM_MAIN.addEventHandler('button-removeFile-' + keyName,'click',function(){
  2276. PWM_MAIN.showConfirmDialog({text:'Are you sure you want to remove the currently stored file?',okAction:function(){
  2277. PWM_MAIN.showWaitDialog({loadFunction:function(){
  2278. PWM_CFGEDIT.resetSetting(keyName,function(){
  2279. FileValueHandler.init(keyName);
  2280. PWM_MAIN.closeWaitDialog();
  2281. });
  2282. }});
  2283. }});
  2284. });
  2285. };
  2286. FileValueHandler.uploadFile = function(keyName) {
  2287. var options = {};
  2288. options['url'] = "ConfigEditor?processAction=uploadFile&key=" + keyName;
  2289. options['nextFunction'] = function() {
  2290. PWM_MAIN.showWaitDialog({loadFunction:function(){
  2291. FileValueHandler.init(keyName);
  2292. PWM_MAIN.closeWaitDialog();
  2293. }});
  2294. };
  2295. PWM_CONFIG.uploadFile(options);
  2296. };