configeditor-settings.js 137 KB

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