configeditor-settings.js 137 KB

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