123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682 |
- /*
- * Password Management Servlets (PWM)
- * http://code.google.com/p/pwm/
- *
- * Copyright (c) 2006-2009 Novell, Inc.
- * Copyright (c) 2009-2015 The PWM Project
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- "use strict";
- var PWM_CFGEDIT = PWM_CFGEDIT || {};
- var PWM_CONFIG = PWM_CONFIG || {};
- var PWM_MAIN = PWM_MAIN || {};
- var PWM_VAR = PWM_VAR || {};
- var PWM_SETTINGS = PWM_SETTINGS || {};
- PWM_VAR['clientSettingCache'] = { };
- // -------------------------- locale table handler ------------------------------------
- var LocalizedStringValueHandler = {};
- LocalizedStringValueHandler.init = function(keyName, regExPattern, syntax) {
- console.log('LocalizedStringValueHandler init for ' + keyName);
- var parentDiv = 'table_setting_' + keyName;
- PWM_MAIN.getObject(parentDiv).innerHTML = '<table id="tableTop_' + keyName + '" style="border-width:0">';
- parentDiv = PWM_MAIN.getObject('tableTop_' + keyName);
- PWM_VAR['clientSettingCache'][keyName + "_regExPattern"] = regExPattern;
- PWM_VAR['clientSettingCache'][keyName + "_syntax"] = syntax;
- PWM_VAR['clientSettingCache'][keyName + "_parentDiv"] = parentDiv;
- PWM_CFGEDIT.clearDivElements(parentDiv, true);
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- LocalizedStringValueHandler.draw(keyName);
- });
- };
- LocalizedStringValueHandler.draw = function(keyName) {
- var parentDiv = PWM_VAR['clientSettingCache'][keyName + "_parentDiv"];
- var regExPattern = PWM_VAR['clientSettingCache'][keyName + "_regExPattern"];
- var syntax = PWM_VAR['clientSettingCache'][keyName + "_syntax"];
- require(["dojo/parser","dijit/form/Button","dijit/form/Textarea","dijit/form/ValidationTextBox"],function(dojoParser){
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- PWM_CFGEDIT.clearDivElements(parentDiv, false);
- for (var i in resultValue) {
- LocalizedStringValueHandler.addLocaleTableRow(parentDiv, keyName, i, resultValue[i], regExPattern, syntax)
- }
- PWM_CFGEDIT.addAddLocaleButtonRow(parentDiv, keyName, function(localeKey) {
- LocalizedStringValueHandler.addLocaleSetting(keyName, localeKey);
- });
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- dojoParser.parse(parentDiv);
- });
- };
- LocalizedStringValueHandler.addLocaleTableRow = function(parentDiv, settingKey, localeString, value, regExPattern, syntax) {
- var inputID = 'value-' + settingKey + '-' + localeString;
- // clear the old dijit node (if it exists)
- PWM_MAIN.clearDijitWidget(inputID);
- var newTableRow = document.createElement("tr");
- newTableRow.setAttribute("style", "border-width: 0");
- var td1 = document.createElement("td");
- td1.setAttribute("style", "border-width: 0; width: 15px");
- if (localeString == null || localeString.length < 1) {
- td1.innerHTML = "";
- } else {
- td1.innerHTML = localeString;
- }
- newTableRow.appendChild(td1);
- var td2 = document.createElement("td");
- td2.setAttribute("style", "border-width: 0");
- if (syntax == 'LOCALIZED_TEXT_AREA') {
- var textAreaElement = document.createElement("textarea");
- textAreaElement.setAttribute("id", inputID);
- textAreaElement.setAttribute("value", PWM_MAIN.showString('Display_PleaseWait'));
- textAreaElement.setAttribute("onchange", "LocalizedStringValueHandler.writeLocaleSetting('" + settingKey + "','" + localeString + "',this.value)");
- textAreaElement.setAttribute("style", "width: 510px; max-width:510px; max-height: 300px; overflow: auto; white-space: nowrap");
- textAreaElement.setAttribute("data-dojo-type", "dijit.form.Textarea");
- textAreaElement.setAttribute("value", value);
- td2.appendChild(textAreaElement);
- } else {
- var inputElement = document.createElement("input");
- inputElement.setAttribute("id", inputID);
- inputElement.setAttribute("value", PWM_MAIN.showString('Display_PleaseWait'));
- inputElement.setAttribute("onchange", "LocalizedStringValueHandler.writeLocaleSetting('" + settingKey + "','" + localeString + "',this.value)");
- inputElement.setAttribute("style", "width: 510px;");
- inputElement.setAttribute("data-dojo-type", "dijit.form.ValidationTextBox");
- inputElement.setAttribute("regExp", regExPattern);
- inputElement.setAttribute("value", value);
- td2.appendChild(inputElement);
- }
- newTableRow.appendChild(td2);
- if (localeString != null && localeString.length > 0) {
- var imgElement = document.createElement("div");
- imgElement.setAttribute("style", "width: 10px; height: 10px;");
- imgElement.setAttribute("class", "delete-row-icon action-icon fa fa-times");
- imgElement.setAttribute("id", "button-" + settingKey + '-' + localeString + "-deleteRow");
- imgElement.setAttribute("onclick", "LocalizedStringValueHandler.removeLocaleSetting('" + settingKey + "','" + localeString + "','" + parentDiv + "','" + regExPattern + "','" + syntax + "')");
- td2.appendChild(imgElement);
- }
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- parentDivElement.appendChild(newTableRow);
- PWM_MAIN.addEventHandler("button-" + settingKey + '-' + localeString + "-deleteRow","click",function(){
- LocalizedStringValueHandler.removeLocaleSetting(settingKey, localeString);
- });
- };
- LocalizedStringValueHandler.writeLocaleSetting = function(settingKey, locale, value) {
- var existingValues = PWM_VAR['clientSettingCache'][settingKey];
- var currentValues = { };
- for (var i in existingValues) {
- var inputID = 'value-' + settingKey + '-' + i;
- currentValues[i] = PWM_MAIN.getObject(inputID).value;
- }
- if (value == null) {
- delete currentValues[locale];
- } else {
- currentValues[locale] = value;
- }
- PWM_CFGEDIT.writeSetting(settingKey, currentValues);
- PWM_VAR['clientSettingCache'][settingKey] = currentValues;
- };
- LocalizedStringValueHandler.removeLocaleSetting = function(keyName, locale, parentDiv, regExPattern, syntax) {
- LocalizedStringValueHandler.writeLocaleSetting(keyName, locale, null);
- LocalizedStringValueHandler.draw(keyName);
- };
- LocalizedStringValueHandler.addLocaleSetting = function(keyName, inputValue) {
- try {
- var existingElementForLocale = PWM_MAIN.getObject('value-' + keyName + '-' + inputValue);
- if (existingElementForLocale == null) {
- PWM_VAR['clientSettingCache'][keyName][inputValue] = [];
- PWM_CFGEDIT.writeSetting(keyName, PWM_VAR['clientSettingCache'][keyName]);
- //LocalizedStringValueHandler.writeLocaleSetting(keyName, inputValue, '');
- LocalizedStringValueHandler.draw(keyName);
- }
- } finally {
- }
- };
- // -------------------------- string array value handler ------------------------------------
- var StringArrayValueHandler = {};
- StringArrayValueHandler.init = function(keyName) {
- console.log('StringArrayValueHandler init for ' + keyName);
- var parentDiv = 'table_setting_' + keyName;
- PWM_MAIN.getObject(parentDiv).innerHTML = '<table id="tableTop_' + keyName + '" style="border-width:0">';
- parentDiv = PWM_MAIN.getObject('tableTop_' + keyName);
- PWM_VAR['clientSettingCache'][keyName + "_options"] = PWM_VAR['clientSettingCache'][keyName + "_options"] || {};
- PWM_VAR['clientSettingCache'][keyName + "_options"]['parentDiv'] = parentDiv;
- PWM_CFGEDIT.clearDivElements(parentDiv, true);
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- StringArrayValueHandler.draw(keyName);
- var syntax = PWM_SETTINGS['settings'][keyName]['syntax'];
- if (syntax == 'PROFILE') {
- PWM_MAIN.getObject("resetButton-" + keyName).style.display = 'none';
- PWM_MAIN.getObject("helpButton-" + keyName).style.display = 'none';
- PWM_MAIN.getObject("modifiedNoticeIcon-" + keyName).style.display = 'none';
- }
- });
- };
- StringArrayValueHandler.draw = function(settingKey) {
- var parentDiv = PWM_VAR['clientSettingCache'][settingKey + "_options"]['parentDiv'];
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- PWM_CFGEDIT.clearDivElements(parentDiv, false);
- var resultValue = PWM_VAR['clientSettingCache'][settingKey];
- var tableElement = document.createElement("table");
- tableElement.setAttribute("style", "border-width: 0;");
- var syntax = PWM_SETTINGS['settings'][settingKey]['syntax'];
- if (syntax == 'PROFILE') {
- var divDescriptionElement = document.createElement("div");
- divDescriptionElement.innerHTML = PWM_SETTINGS['settings'][settingKey]['description'];
- parentDivElement.appendChild(divDescriptionElement);
- var defaultProfileRow = document.createElement("tr");
- defaultProfileRow.setAttribute("colspan", "5");
- }
- var counter = 0;
- var itemCount = PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][settingKey]);
- for (var i in resultValue) {
- (function(iteration) {
- StringArrayValueHandler.drawRow(settingKey, iteration, resultValue[iteration], itemCount, tableElement);
- counter++;
- })(i);
- }
- parentDivElement.appendChild(tableElement);
- var addItemButton = document.createElement("button");
- addItemButton.setAttribute("type", "button");
- addItemButton.setAttribute("class","btn");
- addItemButton.setAttribute("id","button-" + settingKey + "-addItem");
- addItemButton.innerHTML = '<span class="btn-icon fa fa-plus-square"></span>' + (syntax == 'PROFILE' ? "Add Profile" : "Add Value");
- parentDivElement.appendChild(addItemButton);
- require(["dojo/parser","dijit/form/Button","dijit/form/ValidationTextBox"],function(dojoParser){
- dojoParser.parse(parentDiv);
- PWM_MAIN.addEventHandler('button-' + settingKey + '-addItem','click',function(){
- StringArrayValueHandler.valueHandler(settingKey,-1);
- });
- });
- };
- StringArrayValueHandler.drawRow = function(settingKey, iteration, value, itemCount, parentDivElement) {
- var settingInfo = PWM_SETTINGS['settings'][settingKey];
- var syntax = settingInfo['syntax'];
- var inputID = 'value-' + settingKey + '-' + iteration;
- // clear the old dijit node (if it exists)
- PWM_MAIN.clearDijitWidget(inputID);
- var valueRow = document.createElement("tr");
- valueRow.setAttribute("style", "border-width: 0");
- valueRow.setAttribute("id",inputID + "_row");
- var rowHtml = '<td style=""><div style="width:500px; overflow:hidden; text-overflow: ellipsis" id="' + inputID + '">' + value + '</div></td>';
- var downButtonID = 'button-' + settingKey + '-' + iteration + '-moveDown';
- rowHtml += '<td style="border:0">';
- if (itemCount > 1 && iteration != (itemCount -1)) {
- rowHtml += '<span id="' + downButtonID + '" class="action-icon fa fa-chevron-down"></span>';
- }
- rowHtml += '</td>';
- var upButtonID = 'button-' + settingKey + '-' + iteration + '-moveUp';
- rowHtml += '<td style="border:0">';
- if (itemCount > 1 && iteration != 0) {
- rowHtml += '<span id="' + upButtonID + '" class="action-icon fa fa-chevron-up"></span>';
- }
- rowHtml += '</td>';
- var deleteButtonID = 'button-' + settingKey + '-' + iteration + '-delete';
- rowHtml += '<td style="border:0">';
- if (itemCount > 1 || (!settingInfo['required'] && (syntax != 'PROFILE'))) {
- rowHtml += '<span id="' + deleteButtonID + '" class="delete-row-icon action-icon fa fa-times"></span>';
- }
- rowHtml += '</td>';
- valueRow.innerHTML = rowHtml;
- parentDivElement.appendChild(valueRow);
- setTimeout(function(){
- if (syntax != 'PROFILE') {
- PWM_MAIN.addEventHandler(inputID,'click',function(){
- StringArrayValueHandler.valueHandler(settingKey,iteration);
- });
- }
- if (itemCount > 1 && iteration != (itemCount -1)) {
- PWM_MAIN.addEventHandler(downButtonID,'click',function(){StringArrayValueHandler.move(settingKey,false,iteration)});
- }
- if (itemCount > 1 && iteration != 0) {
- PWM_MAIN.addEventHandler(upButtonID,'click',function(){StringArrayValueHandler.move(settingKey,true,iteration)});
- }
- if (itemCount > 1 || !PWM_SETTINGS['settings'][settingKey]['required']) {
- PWM_MAIN.addEventHandler(deleteButtonID,'click',function(){StringArrayValueHandler.removeValue(settingKey,iteration)});
- }
- },100);
- };
- StringArrayValueHandler.valueHandler = function(settingKey, iteration) {
- var text = '';
- //text += '<div>' + PWM_SETTINGS['settings'][settingKey]['description'] + '</div><hr/>';
- text += '<input style="width: 500px" required="required" id="addValueDialog_input"/>';
- var changeFunction = function() {
- PWM_VAR['addDialog_value'] = this.value;
- PWM_MAIN.getObject('dialog_ok_button').disabled = !this.validate();
- };
- var loadFunction = function() {
- var value = iteration > -1 ? PWM_VAR['clientSettingCache'][settingKey][iteration] : '';
- PWM_MAIN.getObject('dialog_ok_button').disabled = true;
- require(["dijit/form/ValidationTextBox"],function(ValidationTextBox) {
- new ValidationTextBox({
- id:"addValueDialog_input",
- regExp: PWM_SETTINGS['settings'][settingKey]['pattern'],
- style: 'width: 500px',
- required: true,
- invalidMessage: 'The value does not have the correct format',
- value: value,
- onChange: changeFunction,
- onKeyUp: changeFunction
- },"addValueDialog_input");
- });
- };
- var okAction = function() {
- var value = PWM_VAR['addDialog_value'];
- if (iteration > -1) {
- PWM_VAR['clientSettingCache'][settingKey][iteration] = value;
- } else {
- PWM_VAR['clientSettingCache'][settingKey].push(value);
- }
- StringArrayValueHandler.writeSetting(settingKey)
- };
- PWM_MAIN.showDialog({
- title:PWM_SETTINGS['settings'][settingKey]['label'] + " - " + (iteration > -1 ? "Edit" : "Add") + " Value",
- text:text,
- loadFunction:loadFunction,
- okAction:okAction,
- showCancel:true,
- showClose: true,
- allowMove: true
- });
- };
- StringArrayValueHandler.move = function(settingKey, moveUp, iteration) {
- var currentValues = PWM_VAR['clientSettingCache'][settingKey];
- if (moveUp) {
- StringArrayValueHandler.arrayMoveUtil(currentValues, iteration, iteration - 1);
- } else {
- StringArrayValueHandler.arrayMoveUtil(currentValues, iteration, iteration + 1);
- }
- StringArrayValueHandler.writeSetting(settingKey)
- };
- StringArrayValueHandler.arrayMoveUtil = function(arr, fromIndex, toIndex) {
- var element = arr[fromIndex];
- arr.splice(fromIndex, 1);
- arr.splice(toIndex, 0, element);
- };
- StringArrayValueHandler.removeValue = function(settingKey, iteration) {
- var syntax = PWM_SETTINGS['settings'][settingKey]['syntax'];
- var deleteFunction = function() {
- var currentValues = PWM_VAR['clientSettingCache'][settingKey];
- currentValues.splice(iteration,1);
- StringArrayValueHandler.writeSetting(settingKey,false);
- };
- if (syntax == 'PROFILE') {
- PWM_MAIN.showConfirmDialog({
- text:'Are you sure you want to remove the profile?',
- okAction:function(){
- deleteFunction();
- }
- });
- } else {
- deleteFunction();
- }
- };
- StringArrayValueHandler.writeSetting = function(settingKey, reload) {
- var syntax = PWM_SETTINGS['settings'][settingKey]['syntax'];
- var nextFunction = function() {
- if (syntax == 'PROFILE') {
- PWM_CFGEDIT.drawNavigationMenu();
- }
- if (reload) {
- StringArrayValueHandler.init(settingKey);
- } else {
- StringArrayValueHandler.draw(settingKey);
- }
- };
- var currentValues = PWM_VAR['clientSettingCache'][settingKey];
- PWM_CFGEDIT.writeSetting(settingKey, currentValues, nextFunction);
- };
- // -------------------------- multi locale table handler ------------------------------------
- var MultiLocaleTableHandler = {};
- MultiLocaleTableHandler.initMultiLocaleTable = function(keyName) {
- console.log('MultiLocaleTableHandler init for ' + keyName);
- var parentDiv = 'table_setting_' + keyName;
- PWM_CFGEDIT.clearDivElements(parentDiv, true);
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- MultiLocaleTableHandler.draw(keyName);
- });
- };
- MultiLocaleTableHandler.draw = function(keyName) {
- var parentDiv = 'table_setting_' + keyName;
- var regExPattern = PWM_SETTINGS['settings'][keyName]['pattern'];
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- require(["dojo","dijit/registry","dojo/parser","dijit/form/Button","dijit/form/ValidationTextBox","dijit/form/Textarea","dijit/registry"],function(dojo,registry,dojoParser){
- PWM_CFGEDIT.clearDivElements(parentDiv, false);
- for (var localeName in resultValue) {
- var localeTableRow = document.createElement("tr");
- localeTableRow.setAttribute("style", "border-width: 0;");
- var localeTdName = document.createElement("td");
- localeTdName.setAttribute("style", "border-width: 0; width:15px");
- localeTdName.innerHTML = localeName;
- localeTableRow.appendChild(localeTdName);
- var localeTdContent = document.createElement("td");
- localeTdContent.setAttribute("style", "border-width: 0; width: 525px");
- localeTableRow.appendChild(localeTdContent);
- var localeTableElement = document.createElement("table");
- localeTableElement.setAttribute("style", "border-width: 2px; width:525px; margin:0");
- localeTdContent.appendChild(localeTableElement);
- var multiValues = resultValue[localeName];
- for (var iteration in multiValues) {
- var valueTableRow = document.createElement("tr");
- var valueTd1 = document.createElement("td");
- valueTd1.setAttribute("style", "border-width: 0;");
- // clear the old dijit node (if it exists)
- var inputID = "value-" + keyName + "-" + localeName + "-" + iteration;
- var oldDijitNode = registry.byId(inputID);
- if (oldDijitNode != null) {
- try {
- oldDijitNode.destroy();
- } catch (error) {
- }
- }
- var inputElement = document.createElement("input");
- inputElement.setAttribute("id", inputID);
- inputElement.setAttribute("value", multiValues[iteration]);
- inputElement.setAttribute("onchange", "MultiLocaleTableHandler.writeMultiLocaleSetting('" + keyName + "','" + localeName + "','" + iteration + "',this.value,'" + regExPattern + "')");
- inputElement.setAttribute("style", "width: 490px");
- inputElement.setAttribute("data-dojo-type", "dijit.form.ValidationTextBox");
- inputElement.setAttribute("regExp", regExPattern);
- inputElement.setAttribute("invalidMessage", "The value does not have the correct format.");
- valueTd1.appendChild(inputElement);
- valueTableRow.appendChild(valueTd1);
- localeTableElement.appendChild(valueTableRow);
- // add remove button
- var imgElement = document.createElement("div");
- imgElement.setAttribute("style", "width: 10px; height: 10px;");
- imgElement.setAttribute("class", "delete-row-icon action-icon fa fa-times");
- imgElement.setAttribute("onclick", "MultiLocaleTableHandler.writeMultiLocaleSetting('" + keyName + "','" + localeName + "','" + iteration + "',null,'" + regExPattern + "')");
- valueTd1.appendChild(imgElement);
- }
- { // add row button for this locale group
- var newTableRow = document.createElement("tr");
- newTableRow.setAttribute("style", "border-width: 0");
- newTableRow.setAttribute("colspan", "5");
- var newTableData = document.createElement("td");
- newTableData.setAttribute("style", "border-width: 0;");
- var addItemButton = document.createElement("button");
- addItemButton.setAttribute("type", "[button");
- addItemButton.setAttribute("onclick", "PWM_VAR['clientSettingCache']['" + keyName + "']['" + localeName + "'].push('');MultiLocaleTableHandler.writeMultiLocaleSetting('" + keyName + "',null,null,null,'" + regExPattern + "')");
- addItemButton.setAttribute("data-dojo-type", "dijit.form.Button");
- addItemButton.innerHTML = "Add Value";
- newTableData.appendChild(addItemButton);
- newTableRow.appendChild(newTableData);
- localeTableElement.appendChild(newTableRow);
- }
- if (localeName != '') { // add remove locale x
- var imgElement2 = document.createElement("div");
- imgElement2.setAttribute("class", "delete-row-icon action-icon fa fa-times");
- imgElement2.setAttribute("onclick", "MultiLocaleTableHandler.writeMultiLocaleSetting('" + keyName + "','" + localeName + "',null,null,'" + regExPattern + "')");
- var tdElement = document.createElement("td");
- tdElement.setAttribute("style", "border-width: 0; text-align: left; vertical-align: top;width 10px");
- localeTableRow.appendChild(tdElement);
- tdElement.appendChild(imgElement2);
- }
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- parentDivElement.appendChild(localeTableRow);
- { // add a spacer row
- var spacerTableRow = document.createElement("tr");
- spacerTableRow.setAttribute("style", "border-width: 0");
- parentDivElement.appendChild(spacerTableRow);
- var spacerTableData = document.createElement("td");
- spacerTableData.setAttribute("style", "border-width: 0");
- spacerTableData.innerHTML = " ";
- spacerTableRow.appendChild(spacerTableData);
- }
- }
- var addLocaleFunction = function(value) {
- require(["dijit/registry"],function(registry){
- MultiLocaleTableHandler.writeMultiLocaleSetting(keyName, value, 0, '', regExPattern);
- });
- };
- PWM_CFGEDIT.addAddLocaleButtonRow(parentDiv, keyName, addLocaleFunction);
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- dojoParser.parse(parentDiv);
- });
- };
- MultiLocaleTableHandler.writeMultiLocaleSetting = function(settingKey, locale, iteration, value) {
- if (locale != null) {
- if (PWM_VAR['clientSettingCache'][settingKey][locale] == null) {
- PWM_VAR['clientSettingCache'][settingKey][locale] = [ "" ];
- }
- if (iteration == null) {
- delete PWM_VAR['clientSettingCache'][settingKey][locale];
- } else {
- if (value == null) {
- PWM_VAR['clientSettingCache'][settingKey][locale].splice(iteration,1);
- } else {
- PWM_VAR['clientSettingCache'][settingKey][locale][iteration] = value;
- }
- }
- }
- PWM_CFGEDIT.writeSetting(settingKey, PWM_VAR['clientSettingCache'][settingKey]);
- MultiLocaleTableHandler.draw(settingKey);
- };
- // -------------------------- form table handler ------------------------------------
- var FormTableHandler = {};
- FormTableHandler.newRowValue = {
- name:'',
- minimumLength:0,
- maximumLength:255,
- labels:{'':''},
- regexErrors:{'':''},
- selectOptions:{},
- description:{'':''}
- };
- FormTableHandler.init = function(keyName) {
- console.log('FormTableHandler init for ' + keyName);
- var parentDiv = 'table_setting_' + keyName;
- PWM_CFGEDIT.clearDivElements(parentDiv, true);
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- FormTableHandler.redraw(keyName);
- });
- };
- FormTableHandler.redraw = function(keyName) {
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- var parentDiv = 'table_setting_' + keyName;
- PWM_CFGEDIT.clearDivElements(parentDiv, false);
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- if (!PWM_MAIN.isEmpty(resultValue)) {
- var headerRow = document.createElement("tr");
- var rowHtml = '<td>Name</td><td>Label</td>';
- headerRow.innerHTML = rowHtml;
- parentDivElement.appendChild(headerRow);
- }
- for (var i in resultValue) {
- FormTableHandler.drawRow(parentDiv, keyName, i, resultValue[i]);
- }
- var buttonRow = document.createElement("tr");
- buttonRow.setAttribute("colspan","5");
- buttonRow.innerHTML = '<td><button class="btn" id="button-' + keyName + '-addRow"><span class="btn-icon fa fa-plus-square"></span>Add Form Item</button></td>';
- parentDivElement.appendChild(buttonRow);
- PWM_MAIN.addEventHandler('button-' + keyName + '-addRow','click',function(){
- FormTableHandler.addRow(keyName);
- });
- };
- FormTableHandler.drawRow = function(parentDiv, settingKey, iteration, value) {
- require(["dojo/json"], function(JSON){
- var itemCount = PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][settingKey]);
- var inputID = 'value_' + settingKey + '_' + iteration + "_";
- var options = PWM_SETTINGS['settings'][settingKey]['options'];
- var newTableRow = document.createElement("tr");
- newTableRow.setAttribute("style", "border-width: 0");
- var htmlRow = '';
- htmlRow += '<td><input style="width:180px" class="configStringInput" id="' + inputID + 'name" value="' + value['name'] + '"/></td>';
- 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>';
- htmlRow += '<td>';
- var userDNtypeAllowed = options['type-userDN'] == 'show';
- var optionList = PWM_GLOBAL['formTypeOptions'];
- if ('types' in options) {
- optionList = JSON.parse(options['types']);
- }
- if (!PWM_MAIN.isEmpty(optionList)) {
- htmlRow += '<select id="' + inputID + 'type">';
- for (var optionItem in optionList) {
- if (optionList[optionItem] != 'userDN' || userDNtypeAllowed) {
- var optionName = optionList[optionItem];
- var selected = (optionName == PWM_VAR['clientSettingCache'][settingKey][iteration]['type']);
- htmlRow += '<option value="' + optionName + '"' + (selected ? " selected" : "") + '>' + optionName + '</option>';
- }
- }
- htmlRow += '</select>';
- }
- htmlRow += '</td>';
- var hideOptions = PWM_SETTINGS['settings'][settingKey]['options']['hideOptions'] == 'true';
- if (!hideOptions) {
- htmlRow += '<td><button id="' + inputID + 'optionsButton"><span class="btn-icon fa fa-sliders"/> Options</button></td>';
- }
- htmlRow += '<td>';
- if (itemCount > 1 && iteration != (itemCount -1)) {
- htmlRow += '<span id="' + inputID + '-moveDown" class="action-icon fa fa-chevron-down"></span>';
- }
- htmlRow += '</td>';
- htmlRow += '<td>';
- if (itemCount > 1 && iteration != 0) {
- htmlRow += '<span id="' + inputID + '-moveUp" class="action-icon fa fa-chevron-up"></span>';
- }
- htmlRow += '</td>';
- htmlRow += '<td><span class="delete-row-icon action-icon fa fa-times" id="' + inputID + '-deleteRowButton"></span></td>';
- newTableRow.innerHTML = htmlRow;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- parentDivElement.appendChild(newTableRow);
- PWM_MAIN.addEventHandler(inputID + "-moveUp", 'click', function () {
- FormTableHandler.move(settingKey, true, iteration);
- });
- PWM_MAIN.addEventHandler(inputID + "-moveDown", 'click', function () {
- FormTableHandler.move(settingKey, false, iteration);
- });
- PWM_MAIN.addEventHandler(inputID + "-deleteRowButton", 'click', function () {
- FormTableHandler.removeRow(settingKey, iteration);
- });
- PWM_MAIN.addEventHandler(inputID + "label", 'click, keypress', function () {
- FormTableHandler.showLabelDialog(settingKey, iteration);
- });
- PWM_MAIN.addEventHandler(inputID + "optionsButton", 'click', function () {
- FormTableHandler.showOptionsDialog(settingKey, iteration);
- });
- PWM_MAIN.addEventHandler(inputID + "name", 'input', function () {
- PWM_VAR['clientSettingCache'][settingKey][iteration]['name'] = PWM_MAIN.getObject(inputID + "name").value;
- FormTableHandler.writeFormSetting(settingKey);
- });
- PWM_MAIN.addEventHandler(inputID + "type", 'click', function () {
- PWM_VAR['clientSettingCache'][settingKey][iteration]['type'] = PWM_MAIN.getObject(inputID + "type").value;
- FormTableHandler.writeFormSetting(settingKey);
- });
- });
- };
- FormTableHandler.writeFormSetting = function(settingKey, finishFunction) {
- var cachedSetting = PWM_VAR['clientSettingCache'][settingKey];
- PWM_CFGEDIT.writeSetting(settingKey, cachedSetting, finishFunction);
- };
- FormTableHandler.removeRow = function(keyName, iteration) {
- PWM_MAIN.showConfirmDialog({
- text:'Are you sure you wish to delete this item?',
- okAction:function(){
- var currentValues = PWM_VAR['clientSettingCache'][keyName];
- currentValues.splice(iteration,1);
- FormTableHandler.writeFormSetting(keyName,function(){
- FormTableHandler.init(keyName);
- });
- }
- });
- };
- FormTableHandler.move = function(settingKey, moveUp, iteration) {
- var currentValues = PWM_VAR['clientSettingCache'][settingKey];
- if (moveUp) {
- FormTableHandler.arrayMoveUtil(currentValues, iteration, iteration - 1);
- } else {
- FormTableHandler.arrayMoveUtil(currentValues, iteration, iteration + 1);
- }
- FormTableHandler.writeFormSetting(settingKey);
- FormTableHandler.redraw(settingKey);
- };
- FormTableHandler.arrayMoveUtil = function(arr, fromIndex, toIndex) {
- var element = arr[fromIndex];
- arr.splice(fromIndex, 1);
- arr.splice(toIndex, 0, element);
- };
- FormTableHandler.addRow = function(keyName) {
- var body='Name <input class="configStringInput" id="newFormFieldName" style="width:300px"/>';
- PWM_MAIN.showConfirmDialog({title:'New Form Field',text:body,showClose:true,loadFunction:function(){
- PWM_MAIN.getObject('dialog_ok_button').disabled = true;
- PWM_MAIN.addEventHandler('newFormFieldName','input',function(){
- PWM_VAR['newFormFieldName'] = PWM_MAIN.getObject('newFormFieldName').value;
- if (PWM_VAR['newFormFieldName'] && PWM_VAR['newFormFieldName'].length > 1) {
- PWM_MAIN.getObject('dialog_ok_button').disabled = false;
- }
- });
- },okAction:function(){
- var currentSize = PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][keyName]);
- PWM_VAR['clientSettingCache'][keyName][currentSize + 1] = FormTableHandler.newRowValue
- PWM_VAR['clientSettingCache'][keyName][currentSize + 1].name = PWM_VAR['newFormFieldName'];
- FormTableHandler.writeFormSetting(keyName,function(){
- FormTableHandler.init(keyName);
- });
- }});
- };
- FormTableHandler.showOptionsDialog = function(keyName, iteration) {
- var options = 'options' in PWM_SETTINGS['settings'][keyName] ? PWM_SETTINGS['settings'][keyName]['options'] : {};
- var showUnique = options['unique'] == 'show';
- require(["dijit/Dialog","dijit/form/Textarea","dijit/form/CheckBox","dijit/form/NumberSpinner"],function(){
- var inputID = 'value_' + keyName + '_' + iteration + "_";
- var bodyText = '<div style="max-height: 500px; overflow-y: auto"><table class="noborder">';
- bodyText += '<tr>';
- var descriptionValue = PWM_VAR['clientSettingCache'][keyName][iteration]['description'][''];
- bodyText += '<td id="' + inputID + '-label-description" class="key">Description</td><td>';
- bodyText += '<div class="noWrapTextBox" id="' + inputID + 'description"><span class="btn-icon fa fa-edit"></span><span>' + descriptionValue + '...</span></div>';
- bodyText += '</td>';
- bodyText += '</tr><tr>';
- if (options['required'] != 'hide') {
- bodyText += '<td id="' + inputID + '-label-required" class="key">Required</td><td><input type="checkbox" id="' + inputID + 'required' + '"/></td>';
- bodyText += '</tr><tr>';
- }
- bodyText += '<td id="' + inputID + '-label-confirm" class="key">Confirm</td><td><input type="checkbox" id="' + inputID + 'confirmationRequired' + '"/></td>';
- bodyText += '</tr><tr>';
- if (options['readonly'] == 'show') {
- bodyText += '<td id="' + inputID + '-label-readOnly" class="key">Read Only</td><td><input type="checkbox" id="' + inputID + 'readonly' + '"/></td>';
- bodyText += '</tr><tr>';
- }
- if (showUnique) {
- bodyText += '<td id="' + inputID + '-label-unique" class="key">Unique</td><td><input type="checkbox" id="' + inputID + 'unique' + '"/></td>';
- bodyText += '</tr><tr>';
- }
- bodyText += '<td class="key">Minimum Length</td><td><input type="number" id="' + inputID + 'minimumLength' + '"/></td>';
- bodyText += '</tr><tr>';
- bodyText += '<td class="key">Maximum Length</td><td><input type="number" id="' + inputID + 'maximumLength' + '"/></td>';
- bodyText += '</tr><tr>';
- { // regex
- bodyText += '<td id="' + inputID + '-label-regex" class="key">Regular Expression</td><td><input type="text" class="configStringInput" id="' + inputID + 'regex' + '"/></td>';
- bodyText += '</tr><tr>';
- var regexErrorValue = PWM_VAR['clientSettingCache'][keyName][iteration]['regexErrors'][''];
- bodyText += '<td id="' + inputID + '-label-regexError" class="key">Regular Expression<br/>Error Message</td><td>';
- bodyText += '<div class="noWrapTextBox" id="' + inputID + 'regexErrors"><span class="btn-icon fa fa-edit"></span><span>' + regexErrorValue + '...</span></div>';
- bodyText += '</td>';
- bodyText += '</tr><tr>';
- }
- bodyText += '<td id="' + inputID + '-label-placeholder" class="key">Placeholder</td><td><input type="text" id="' + inputID + 'placeholder' + '"/></td>';
- bodyText += '</tr><tr>';
- bodyText += '<td id="' + inputID + '-label-js" class="key">JavaScript</td><td><input type="text" id="' + inputID + 'javascript' + '"/></td>';
- bodyText += '</tr><tr>';
- if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'select') {
- bodyText += '<td class="key">Select Options</td><td><button id="' + inputID + 'editOptionsButton"><span class="btn-icon fa fa-list-ul"/> Edit</button></td>';
- bodyText += '</tr>';
- }
- bodyText += '</table></div>';
- var initDialogWidgets = function() {
- PWM_MAIN.showTooltip({
- id: inputID + '-label-description',
- text: PWM_CONFIG.showString('Tooltip_FormOptions_Description')
- });
- PWM_MAIN.showTooltip({
- id: inputID + '-label-required',
- text: PWM_CONFIG.showString('Tooltip_FormOptions_Required')
- });
- PWM_MAIN.showTooltip({
- id: inputID + '-label-confirm',
- text: PWM_CONFIG.showString('Tooltip_FormOptions_Confirm')
- });
- PWM_MAIN.showTooltip({
- id: inputID + '-label-readOnly',
- text: PWM_CONFIG.showString('Tooltip_FormOptions_ReadOnly')
- });
- PWM_MAIN.showTooltip({
- id: inputID + '-label-unique',
- text: PWM_CONFIG.showString('Tooltip_FormOptions_Unique')
- });
- PWM_MAIN.showTooltip({
- id: inputID + '-label-regex',
- text: PWM_CONFIG.showString('Tooltip_FormOptions_Regex')
- });
- PWM_MAIN.showTooltip({
- id: inputID + '-label-regexError',
- text: PWM_CONFIG.showString('Tooltip_FormOptions_RegexError')
- });
- PWM_MAIN.showTooltip({
- id: inputID + '-label-placeholder',
- text: PWM_CONFIG.showString('Tooltip_FormOptions_Placeholder')
- });
- PWM_MAIN.showTooltip({
- id: inputID + '-label-js',
- text: PWM_CONFIG.showString('Tooltip_FormOptions_Javascript')
- });
- PWM_MAIN.addEventHandler(inputID + 'editOptionsButton', 'click', function(){
- FormTableHandler.showSelectOptionsDialog(keyName,iteration);
- });
- PWM_MAIN.addEventHandler(inputID + 'description','click',function(){
- FormTableHandler.showDescriptionDialog(keyName, iteration);
- });
- PWM_MAIN.clearDijitWidget(inputID + "required");
- new dijit.form.CheckBox({
- checked: PWM_VAR['clientSettingCache'][keyName][iteration]['required'],
- onChange: function () {
- PWM_VAR['clientSettingCache'][keyName][iteration]['required'] = this.checked;
- FormTableHandler.writeFormSetting(keyName)
- }
- }, inputID + "required");
- PWM_MAIN.clearDijitWidget(inputID + "confirmationRequired");
- new dijit.form.CheckBox({
- checked: PWM_VAR['clientSettingCache'][keyName][iteration]['confirmationRequired'],
- onChange: function () {
- PWM_VAR['clientSettingCache'][keyName][iteration]['confirmationRequired'] = this.checked;
- FormTableHandler.writeFormSetting(keyName)
- }
- }, inputID + "confirmationRequired");
- if (PWM_SETTINGS['settings'][keyName]['options']['readonly'] == 'show') {
- PWM_MAIN.clearDijitWidget(inputID + "readonly");
- new dijit.form.CheckBox({
- checked: PWM_VAR['clientSettingCache'][keyName][iteration]['readonly'],
- onChange: function () {
- PWM_VAR['clientSettingCache'][keyName][iteration]['readonly'] = this.checked;
- FormTableHandler.writeFormSetting(keyName)
- }
- }, inputID + "readonly");
- }
- if (showUnique) {
- PWM_MAIN.clearDijitWidget(inputID + "unique");
- new dijit.form.CheckBox({
- checked: PWM_VAR['clientSettingCache'][keyName][iteration]['unique'],
- onChange: function () {
- PWM_VAR['clientSettingCache'][keyName][iteration]['unique'] = this.checked;
- FormTableHandler.writeFormSetting(keyName)
- }
- }, inputID + "unique");
- }
- if (PWM_SETTINGS['settings'][keyName]['options']['unique'] == 'show') {
- PWM_MAIN.clearDijitWidget(inputID + "unique");
- new dijit.form.CheckBox({
- checked: PWM_VAR['clientSettingCache'][keyName][iteration]['unique'],
- onChange: function () {
- PWM_VAR['clientSettingCache'][keyName][iteration]['unique'] = this.checked;
- FormTableHandler.writeFormSetting(keyName)
- }
- }, inputID + "unique");
- }
- PWM_MAIN.clearDijitWidget(inputID + "minimumLength");
- new dijit.form.NumberSpinner({
- value: PWM_VAR['clientSettingCache'][keyName][iteration]['minimumLength'],
- onChange: function () {
- PWM_VAR['clientSettingCache'][keyName][iteration]['minimumLength'] = this.value;
- FormTableHandler.writeFormSetting(keyName)
- },
- constraints: {min: 0, max: 5000},
- style: "width: 70px"
- }, inputID + "minimumLength");
- PWM_MAIN.clearDijitWidget(inputID + "maximumLength");
- new dijit.form.NumberSpinner({
- value: PWM_VAR['clientSettingCache'][keyName][iteration]['maximumLength'],
- onChange: function () {
- PWM_VAR['clientSettingCache'][keyName][iteration]['maximumLength'] = this.value;
- FormTableHandler.writeFormSetting(keyName)
- },
- constraints: {min: 0, max: 5000},
- style: "width: 70px"
- }, inputID + "maximumLength");
- PWM_MAIN.clearDijitWidget(inputID + "regex");
- new dijit.form.Textarea({
- value: PWM_VAR['clientSettingCache'][keyName][iteration]['regex'],
- onChange: function () {
- PWM_VAR['clientSettingCache'][keyName][iteration]['regex'] = this.value;
- FormTableHandler.writeFormSetting(keyName)
- }
- }, inputID + "regex");
- PWM_MAIN.addEventHandler(inputID + 'regexErrors','click',function(){
- FormTableHandler.showRegexErrorsDialog(keyName, iteration);
- });
- PWM_MAIN.clearDijitWidget(inputID + "placeholder");
- new dijit.form.Textarea({
- value: PWM_VAR['clientSettingCache'][keyName][iteration]['placeholder'],
- onChange: function () {
- PWM_VAR['clientSettingCache'][keyName][iteration]['placeholder'] = this.value;
- FormTableHandler.writeFormSetting(keyName)
- }
- }, inputID + "placeholder");
- PWM_MAIN.clearDijitWidget(inputID + "javascript");
- new dijit.form.Textarea({
- value: PWM_VAR['clientSettingCache'][keyName][iteration]['javascript'],
- onChange: function(){PWM_VAR['clientSettingCache'][keyName][iteration]['javascript'] = this.value;FormTableHandler.writeFormSetting(keyName)}
- },inputID + "javascript");
- };
- PWM_MAIN.showDialog({
- title: PWM_SETTINGS['settings'][keyName]['label'] + ' - ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'],
- text:bodyText,
- allowMove:true,
- loadFunction:initDialogWidgets,
- okAction:function(){
- FormTableHandler.redraw(keyName);
- }
- });
- });
- };
- FormTableHandler.showLabelDialog = function(keyName, iteration) {
- var finishAction = function(){ FormTableHandler.redraw(keyName); };
- var title = 'Label for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
- FormTableHandler.multiLocaleStringDialog(keyName, iteration, 'labels', finishAction, title);
- };
- FormTableHandler.multiLocaleStringDialog = function(keyName, iteration, settingType, finishAction, titleText) {
- require(["dijit/Dialog","dijit/form/Textarea","dijit/form/CheckBox"],function(){
- var inputID = 'value_' + keyName + '_' + iteration + "_" + "label_";
- var bodyText = '<table class="noborder" id="' + inputID + 'table">';
- bodyText += '<tr>';
- for (var localeName in PWM_VAR['clientSettingCache'][keyName][iteration][settingType]) {
- var value = PWM_VAR['clientSettingCache'][keyName][iteration][settingType][localeName];
- var localeID = inputID + localeName;
- bodyText += '<td>' + localeName + '</td>';
- bodyText += '<td><input style="width:445px" class="configStringInput" type="text" value="' + value + '" id="' + localeID + '-input"></input></td>';
- if (localeName != '') {
- bodyText += '<td><span class="delete-row-icon action-icon fa fa-times" id="' + localeID + '-removeLocaleButton"></span></td>';
- }
- bodyText += '</tr><tr>';
- }
- bodyText += '</tr></table>';
- PWM_MAIN.showDialog({
- title: titleText,
- text: bodyText,
- okAction:function(){
- finishAction();
- },
- loadFunction:function(){
- for (var iter in PWM_VAR['clientSettingCache'][keyName][iteration][settingType]) {
- (function(localeName) {
- var localeID = inputID + localeName;
- PWM_MAIN.addEventHandler(localeID + '-input', 'input', function () {
- var inputElement = PWM_MAIN.getObject(localeID + '-input');
- var value = inputElement.value;
- PWM_VAR['clientSettingCache'][keyName][iteration][settingType][localeName] = value;
- FormTableHandler.writeFormSetting(keyName);
- });
- PWM_MAIN.addEventHandler(localeID + '-removeLocaleButton', 'click', function () {
- delete PWM_VAR['clientSettingCache'][keyName][iteration]['labels'][localeName];
- FormTableHandler.writeFormSetting(keyName);
- FormTableHandler.multiLocaleStringDialog(keyName, iteration, settingType, finishAction, titleText);
- });
- }(iter));
- }
- PWM_CFGEDIT.addAddLocaleButtonRow(inputID + 'table', inputID, function(localeName){
- PWM_VAR['clientSettingCache'][keyName][iteration][settingType][localeName] = '';
- FormTableHandler.writeFormSetting(keyName);
- FormTableHandler.multiLocaleStringDialog(keyName, iteration, settingType, finishAction, titleText);
- });
- }
- });
- });
- };
- FormTableHandler.showRegexErrorsDialog = function(keyName, iteration) {
- var finishAction = function(){ FormTableHandler.showOptionsDialog(keyName, iteration); };
- var title = 'Regular Expression Error Message for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
- FormTableHandler.multiLocaleStringDialog(keyName, iteration, 'regexErrors', finishAction, title);
- };
- FormTableHandler.showSelectOptionsDialog = function(keyName, iteration) {
- var inputID = 'value_' + keyName + '_' + iteration + "_" + "selectOptions_";
- var bodyText = '';
- bodyText += '<table class="noborder" id="' + inputID + 'table"">';
- bodyText += '<tr>';
- bodyText += '<td><b>Value</b></td><td><b>Display Name</b></td>';
- bodyText += '</tr><tr>';
- for (var optionName in PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions']) {
- var value = PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions'][optionName];
- var optionID = inputID + optionName;
- bodyText += '<td>' + optionName + '</td><td>' + value + '</td>';
- bodyText += '<td style="border:0; width:15px">';
- bodyText += '<span id="' + optionID + '-removeButton" class="delete-row-icon action-icon fa fa-times"></span>';
- bodyText += '</td>';
- bodyText += '</tr><tr>';
- }
- bodyText += '</tr></table>';
- bodyText += '<br/><br/><br/>';
- bodyText += '<input class="configStringInput" style="width:200px" type="text" placeholder="Value" required id="addSelectOptionName"/>';
- bodyText += '<input class="configStringInput" style="width:200px" type="text" placeholder="Display Name" required id="addSelectOptionValue"/>';
- bodyText += '<button id="addSelectOptionButton"><span class="btn-icon fa fa-plus-square"/> Add</button>';
- PWM_MAIN.showDialog({
- title: 'Select Options for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'],
- text: bodyText,
- okAction: function(){
- FormTableHandler.showOptionsDialog(keyName,iteration);
- }
- });
- for (var optionName in PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions']) {
- var loopID = inputID + optionName;
- var optionID = inputID + optionName;
- PWM_MAIN.clearDijitWidget(loopID);
- PWM_MAIN.addEventHandler(optionID + '-removeButton','click',function(){
- FormTableHandler.removeSelectOptionsOption(keyName,iteration,optionName);
- });
- }
- PWM_MAIN.addEventHandler('addSelectOptionButton','click',function(){
- var value = PWM_MAIN.getObject('addSelectOptionName').value;
- var display = PWM_MAIN.getObject('addSelectOptionValue').value;
- FormTableHandler.addSelectOptionsOption(keyName, iteration, value, display);
- });
- };
- FormTableHandler.addSelectOptionsOption = function(keyName, iteration, optionName, optionValue) {
- if (optionName == null || optionName.length < 1) {
- alert('Name field is required');
- return;
- }
- if (optionValue == null || optionValue.length < 1) {
- alert('Value field is required');
- return;
- }
- PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions'][optionName] = optionValue;
- FormTableHandler.writeFormSetting(keyName);
- FormTableHandler.showSelectOptionsDialog(keyName, iteration);
- };
- FormTableHandler.removeSelectOptionsOption = function(keyName, iteration, optionName) {
- delete PWM_VAR['clientSettingCache'][keyName][iteration]['selectOptions'][optionName];
- FormTableHandler.writeFormSetting(keyName);
- FormTableHandler.showSelectOptionsDialog(keyName, iteration);
- };
- FormTableHandler.showDescriptionDialog = function(keyName, iteration) {
- var finishAction = function(){ FormTableHandler.showOptionsDialog(keyName, iteration); };
- var title = 'Description for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
- FormTableHandler.multiLocaleStringDialog(keyName, iteration, 'description', finishAction, title);
- };
- // -------------------------- change password handler ------------------------------------
- var ChangePasswordHandler = {};
- ChangePasswordHandler.init = function(settingKey) {
- var parentDiv = 'table_setting_' + settingKey;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- if (parentDivElement) {
- PWM_CFGEDIT.readSetting(settingKey,function(data){
- var hasPassword = !data['isDefault'];
- var htmlBody = '';
- if (hasPassword) {
- htmlBody += '<table><tr><td>Value stored.</td></tr></table>';
- htmlBody += '<button id="button-clearPassword-' + settingKey + '" class="btn"><span class="btn-icon fa fa-times"></span>Clear Value</button>';
- } else {
- htmlBody += '<button id="button-changePassword-' + settingKey + '" class="btn"><span class="btn-icon fa fa-plus-square"></span>Store Value</button>';
- }
- parentDivElement.innerHTML = htmlBody;
- PWM_MAIN.addEventHandler('button-changePassword-' + settingKey,'click',function(){
- ChangePasswordHandler.popup(settingKey,PWM_SETTINGS['settings'][settingKey]['label']);
- });
- PWM_MAIN.addEventHandler('button-clearPassword-' + settingKey,'click',function(){
- PWM_MAIN.showConfirmDialog({
- text:'Clear password for setting ' + PWM_SETTINGS['settings'][settingKey]['label'] + '?',
- okAction:function() {
- PWM_CFGEDIT.resetSetting(settingKey,function(){
- ChangePasswordHandler.init(settingKey);
- });
- }
- });
- });
- });
- }
- };
- ChangePasswordHandler.popup = function(settingKey,settingName,writeFunction) {
- if (!PWM_VAR['clientSettingCache'][settingKey]) {
- PWM_VAR['clientSettingCache'][settingKey] = {};
- }
- if (!PWM_VAR['clientSettingCache'][settingKey]['settings']) {
- PWM_VAR['clientSettingCache'][settingKey]['settings'] = {};
- }
- PWM_VAR['clientSettingCache'][settingKey]['settings']['name'] = settingName;
- if (writeFunction) {
- PWM_VAR['clientSettingCache'][settingKey]['settings']['writeFunction'] = writeFunction;
- } else {
- PWM_VAR['clientSettingCache'][settingKey]['settings']['writeFunction'] = function(passwordValue){
- ChangePasswordHandler.doChange(settingKey,passwordValue);
- }
- }
- PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields'] = false;
- ChangePasswordHandler.clear(settingKey);
- ChangePasswordHandler.changePasswordPopup(settingKey);
- };
- ChangePasswordHandler.validatePasswordPopupFields = function() {
- var password1 = PWM_MAIN.getObject('password1').value;
- var password2 = PWM_MAIN.getObject('password2').value;
- var matchStatus = "";
- PWM_MAIN.getObject('button-storePassword').disabled = true;
- if (password2.length > 0) {
- if (password1 == password2) {
- matchStatus = "MATCH";
- PWM_MAIN.getObject('button-storePassword').disabled = false;
- } else {
- matchStatus = "NO_MATCH";
- }
- }
- ChangePasswordHandler.markConfirmationCheck(matchStatus);
- };
- ChangePasswordHandler.markConfirmationCheck = function(matchStatus) {
- if (matchStatus == "MATCH") {
- PWM_MAIN.getObject("confirmCheckMark").style.visibility = 'visible';
- PWM_MAIN.getObject("confirmCrossMark").style.visibility = 'hidden';
- PWM_MAIN.getObject("confirmCheckMark").width = '15';
- PWM_MAIN.getObject("confirmCrossMark").width = '0';
- } else if (matchStatus == "NO_MATCH") {
- PWM_MAIN.getObject("confirmCheckMark").style.visibility = 'hidden';
- PWM_MAIN.getObject("confirmCrossMark").style.visibility = 'visible';
- PWM_MAIN.getObject("confirmCheckMark").width = '0';
- PWM_MAIN.getObject("confirmCrossMark").width = '15';
- } else {
- PWM_MAIN.getObject("confirmCheckMark").style.visibility = 'hidden';
- PWM_MAIN.getObject("confirmCrossMark").style.visibility = 'hidden';
- PWM_MAIN.getObject("confirmCheckMark").width = '0';
- PWM_MAIN.getObject("confirmCrossMark").width = '0';
- }
- };
- ChangePasswordHandler.doChange = function(settingKey, passwordValue) {
- PWM_MAIN.showWaitDialog({loadFunction:function(){
- PWM_CFGEDIT.writeSetting(settingKey,passwordValue,function(){
- ChangePasswordHandler.clear(settingKey);
- ChangePasswordHandler.init(settingKey);
- PWM_MAIN.closeWaitDialog();
- });
- }})
- };
- ChangePasswordHandler.clear = function(settingKey) {
- PWM_VAR['clientSettingCache'][settingKey]['settings']['p1'] = '';
- PWM_VAR['clientSettingCache'][settingKey]['settings']['p2'] = '';
- };
- ChangePasswordHandler.generateRandom = function(settingKey) {
- var length = PWM_VAR['passwordDialog-randomLength'];
- var special = PWM_VAR['passwordDialog-special'];
- if (!PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields']) {
- PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields'] = true;
- }
- var charMap = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
- if (special) {
- charMap += '~`!@#$%^&*()_-+=;:,.[]{}';
- }
- var postData = { };
- postData.maxLength = length;
- postData.minLength = length;
- postData.chars = charMap;
- postData.noUser = true;
- PWM_MAIN.getObject('button-storePassword').disabled = true;
- var url = PWM_GLOBAL['url-restservice'] + "/randompassword";
- var loadFunction = function(data) {
- ChangePasswordHandler.changePasswordPopup(settingKey);
- PWM_MAIN.getObject('password1').value = data['data']['password'];
- PWM_MAIN.getObject('password2').value = '';
- PWM_MAIN.getObject('button-storePassword').disabled = false;
- };
- PWM_MAIN.showWaitDialog({loadFunction:function(){
- PWM_MAIN.ajaxRequest(url,loadFunction,{content:postData});
- }});
- };
- ChangePasswordHandler.changePasswordPopup = function(settingKey) {
- var writeFunction = PWM_VAR['clientSettingCache'][settingKey]['settings']['writeFunction'];
- var showFields = PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields'];
- var p1 = PWM_VAR['clientSettingCache'][settingKey]['settings']['p1'];
- var p2 = PWM_VAR['clientSettingCache'][settingKey]['settings']['p2'];
- var length = 'passwordDialog-randomLength' in PWM_VAR ? PWM_VAR['passwordDialog-randomLength'] : 25;
- var special = 'passwordDialog-special' in PWM_VAR ? PWM_VAR['passwordDialog-special'] : false;
- var bodyText = '<table class="noborder">'
- + '<tr><td><span class="formFieldLabel">' + PWM_MAIN.showString('Field_NewPassword') + '</span></td></tr>'
- + '<tr><td>';
- if (showFields) {
- bodyText += '<textarea name="password1" id="password1" class="configStringInput" style="width: 400px; max-width: 400px; max-height:100px; overflow-y: auto" autocomplete="off">' + p1 + '</textarea>';
- } else {
- bodyText += '<input name="password1" id="password1" class="configStringInput" type="password" style="width: 400px;" autocomplete="off" value="' + p1 + '"></input>';
- }
- bodyText += '</td></tr>'
- + '<tr><td><span class="formFieldLabel">' + PWM_MAIN.showString('Field_ConfirmPassword') + '</span></td></tr>'
- + '<tr><td>';
- if (showFields) {
- bodyText += '<textarea name="password2" id="password2" class="configStringInput" style="width: 400px; max-width: 400px; max-height:100px; overflow-y: auto" autocomplete="off">' + p2 + '</textarea>';
- } else {
- bodyText += '<input name="password2" type="password" id="password2" class="configStringInput" style="width: 400px;" autocomplete="off" value="' + p2 + '"></input>';
- }
- bodyText += '</td>'
- + '<td><div style="margin:0;">'
- + '<img style="visibility:hidden;" id="confirmCheckMark" alt="checkMark" height="15" width="15" src="' + PWM_GLOBAL['url-resources'] + '/greenCheck.png">'
- + '<img style="visibility:hidden;" id="confirmCrossMark" alt="crossMark" height="15" width="15" src="' + PWM_GLOBAL['url-resources'] + '/redX.png">'
- + '</div></td>'
- + '</tr></table>'
- + '<br/><br/><div class="dialogSection" style="width: 400px"><span class="formFieldLabel">Generate Random Password </span><br/>'
- + '<label class="checkboxWrapper"><input id="input-special" type="checkbox"' + (special ? ' checked' : '') + '>Specials</input></label>'
- + ' <input id="input-randomLength" type="number" min="10" max="1000" value="' + length + '" style="width:45px">Length'
- + ' <button id="button-generateRandom" name="button-generateRandom"><span class="fa fa-random btn-icon"></span>Generate Random</button>'
- + '</div><br/><br/>'
- + '<button name="button-storePassword" class="btn" id="button-storePassword" disabled="true"/>'
- + '<span class="fa fa-forward btn-icon"></span>Store Password</button> '
- + '<label class="checkboxWrapper"><input id="show" type="checkbox"' + (showFields ? ' checked' : '') + '>Show Passwords</input></label>'
- + '</div><br/><br/>';
- PWM_MAIN.showDialog({
- title: 'Store Password - ' + PWM_VAR['clientSettingCache'][settingKey]['settings']['name'],
- text: bodyText,
- showOk: false,
- showClose: true,
- loadFunction:function(){
- PWM_MAIN.addEventHandler('button-storePassword','click',function() {
- var passwordValue = PWM_MAIN.getObject('password1').value;
- PWM_MAIN.closeWaitDialog();
- writeFunction(passwordValue);
- });
- PWM_MAIN.addEventHandler('button-generateRandom','click',function() {
- PWM_VAR['passwordDialog-randomLength'] = PWM_MAIN.getObject('input-randomLength').value;
- PWM_VAR['passwordDialog-special'] = PWM_MAIN.getObject('input-special').checked;
- ChangePasswordHandler.generateRandom(settingKey);
- });
- PWM_MAIN.addEventHandler('password1','input',function(){
- PWM_VAR['clientSettingCache'][settingKey]['settings']['p1'] = PWM_MAIN.getObject('password1').value;
- ChangePasswordHandler.validatePasswordPopupFields();
- PWM_MAIN.getObject('password2').value = '';
- });
- PWM_MAIN.addEventHandler('password2','input',function(){
- PWM_VAR['clientSettingCache'][settingKey]['settings']['p2'] = PWM_MAIN.getObject('password2').value;
- ChangePasswordHandler.validatePasswordPopupFields();
- });
- PWM_MAIN.addEventHandler('show','change',function(){
- PWM_VAR['clientSettingCache'][settingKey]['settings']['showFields'] = PWM_MAIN.getObject('show').checked;
- ChangePasswordHandler.changePasswordPopup(settingKey);
- });
- PWM_MAIN.getObject('password1').focus();
- ChangePasswordHandler.validatePasswordPopupFields();
- }
- });
- };
- // -------------------------- action handler ------------------------------------
- var ActionHandler = {};
- ActionHandler.defaultValue = {
- name:"",
- description:"",
- type:"webservice",
- method:"get",
- ldapMethod:"replace",
- url:"",
- body:"",
- headers:{},
- attributeName:"",
- attributeValue:""
- };
- ActionHandler.httpMethodOptions = [
- { label: "Delete", value: "delete" },
- { label: "Get", value: "get" },
- { label: "Post", value: "post" },
- { label: "Put", value: "put" }
- ];
- ActionHandler.ldapMethodOptions = [
- { label: "Replace", value: "replace" },
- { label: "Add", value: "add" },
- { label: "Remove", value: "remove" }
- ];
- ActionHandler.init = function(keyName) {
- console.log('ActionHandler init for ' + keyName);
- var parentDiv = 'table_setting_' + keyName;
- PWM_CFGEDIT.clearDivElements(parentDiv, true);
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- ActionHandler.redraw(keyName);
- });
- };
- ActionHandler.redraw = function(keyName) {
- console.log('ActionHandler redraw for ' + keyName)
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- var parentDiv = 'table_setting_' + keyName;
- PWM_CFGEDIT.clearDivElements(parentDiv, false);
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- if (!PWM_MAIN.isEmpty(resultValue)) {
- var headerRow = document.createElement("tr");
- headerRow.setAttribute("style", "border-width: 0");
- var header1 = document.createElement("td");
- header1.setAttribute("style", "border-width: 0;");
- header1.innerHTML = "Name";
- headerRow.appendChild(header1);
- var header2 = document.createElement("td");
- header2.setAttribute("style", "border-width: 0;");
- header2.innerHTML = "Description";
- headerRow.appendChild(header2);
- parentDivElement.appendChild(headerRow);
- }
- for (var i in resultValue) {
- ActionHandler.drawRow(parentDiv, keyName, i, resultValue[i]);
- }
- var newTableRow = document.createElement("tr");
- newTableRow.setAttribute("style", "border-width: 0");
- newTableRow.setAttribute("colspan", "5");
- var newTableData = document.createElement("td");
- newTableData.setAttribute("style", "border-width: 0");
- var addItemButton = document.createElement("button");
- addItemButton.setAttribute("type", "button");
- addItemButton.setAttribute("class", "btn");
- addItemButton.setAttribute("id", "button-" + keyName + "-addValue");
- addItemButton.innerHTML = '<span class="btn-icon fa fa-plus-square"></span>Add Value';
- newTableData.appendChild(addItemButton);
- newTableRow.appendChild(newTableData);
- parentDivElement.appendChild(newTableRow);
- require(["dojo/parser","dijit/form/Button","dijit/form/Select","dijit/form/Textarea"],function(dojoParser){
- dojoParser.parse(parentDiv);
- });
- PWM_MAIN.addEventHandler('button-' + keyName + '-addValue','click',function(){
- ActionHandler.addRow(keyName);
- });
- };
- ActionHandler.drawRow = function(parentDiv, settingKey, iteration, value) {
- var inputID = 'value_' + settingKey + '_' + iteration + "_";
- var optionList = PWM_GLOBAL['actionTypeOptions'];
- var newTableRow = document.createElement("tr");
- newTableRow.setAttribute("style", "border-width: 0");
- var htmlRow = '';
- htmlRow += '<td>';
- htmlRow += '<input id="input-' + inputID + '-name" class="configStringInput" style="width:180px" value="' + value['name'] + '"/>';
- htmlRow += '</td><td>';
- htmlRow += '<input id="input-' + inputID + '-description" class="configStringInput" style="width:180px" value="' + value['description'] + '"/>';
- htmlRow += '</td><td>';
- htmlRow += '<select id="select-' + inputID + '-type">';
- for (var optionItem in optionList) {
- var selected = optionList[optionItem] == PWM_VAR['clientSettingCache'][settingKey][iteration]['type'];
- htmlRow += '<option value="' + optionList[optionItem] + '"' + (selected ? ' selected' : '') + '>' + optionList[optionItem] + '</option>';
- }
- htmlRow += '</td><td>';
- htmlRow += '<button id="button-' + inputID + '-options"><span class="btn-icon fa fa-sliders"/> Options</button>';
- htmlRow += '</td>';
- htmlRow += '<td><span class="delete-row-icon action-icon fa fa-times" id="button-' + inputID + '-deleteRow"></span></td>';
- newTableRow.innerHTML = htmlRow;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- parentDivElement.appendChild(newTableRow);
- PWM_MAIN.addEventHandler('button-' + inputID + '-options','click',function(){
- ActionHandler.showOptionsDialog(settingKey, iteration);
- });
- PWM_MAIN.addEventHandler('input-' + inputID + '-name','input',function(){
- PWM_VAR['clientSettingCache'][settingKey][iteration]['name'] = PWM_MAIN.getObject('input-' + inputID + '-name').value;
- ActionHandler.writeFormSetting(settingKey);
- });
- PWM_MAIN.addEventHandler('input-' + inputID + '-description','input',function(){
- PWM_VAR['clientSettingCache'][settingKey][iteration]['description'] = PWM_MAIN.getObject('input-' + inputID + '-description').value;
- ActionHandler.writeFormSetting(settingKey);
- });
- PWM_MAIN.addEventHandler('select-' + inputID + '-type','input',function(){
- PWM_VAR['clientSettingCache'][settingKey][iteration]['type'] = PWM_MAIN.getObject('select-' + inputID + '-type').value;
- ActionHandler.writeFormSetting(settingKey);
- });
- PWM_MAIN.addEventHandler('button-' + inputID + '-deleteRow','click',function(){
- ActionHandler.removeRow(settingKey, iteration);
- });
- };
- ActionHandler.writeFormSetting = function(settingKey, finishFunction) {
- var cachedSetting = PWM_VAR['clientSettingCache'][settingKey];
- PWM_CFGEDIT.writeSetting(settingKey, cachedSetting, finishFunction);
- };
- ActionHandler.removeRow = function(keyName, iteration) {
- PWM_MAIN.showConfirmDialog({
- text:'Are you sure you wish to delete this item?',
- okAction:function(){
- delete PWM_VAR['clientSettingCache'][keyName][iteration];
- console.log("removed iteration " + iteration + " from " + keyName + ", cached keyValue=" + PWM_VAR['clientSettingCache'][keyName]);
- ActionHandler.writeFormSetting(keyName,function(){
- ActionHandler.init(keyName);
- });
- }
- })
- };
- ActionHandler.addRow = function(keyName) {
- var body='Name <input class="configStringInput" id="newActionName" style="width:300px"/>';
- PWM_MAIN.showConfirmDialog({title:'New Action',text:body,showClose:true,loadFunction:function(){
- PWM_MAIN.getObject('dialog_ok_button').disabled = true;
- PWM_MAIN.addEventHandler('newActionName','input',function(){
- PWM_VAR['newActionName'] = PWM_MAIN.getObject('newActionName').value;
- if (PWM_VAR['newActionName'] && PWM_VAR['newActionName'].length > 1) {
- PWM_MAIN.getObject('dialog_ok_button').disabled = false;
- }
- });
- },okAction:function(){
- var currentSize = PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][keyName]);
- PWM_VAR['clientSettingCache'][keyName][currentSize + 1] = ActionHandler.defaultValue;
- PWM_VAR['clientSettingCache'][keyName][currentSize + 1].name = PWM_VAR['newActionName'];
- ActionHandler.writeFormSetting(keyName,function(){
- ActionHandler.init(keyName);
- });
- }});
- };
- ActionHandler.showOptionsDialog = function(keyName, iteration) {
- require(["dojo/store/Memory","dijit/Dialog","dijit/form/Textarea","dijit/form/CheckBox","dijit/form/Select","dijit/form/ValidationTextBox"],function(Memory){
- var inputID = 'value_' + keyName + '_' + iteration + "_";
- var value = PWM_VAR['clientSettingCache'][keyName][iteration];
- var titleText = 'title';
- var bodyText = '<table class="noborder">';
- if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'webservice') {
- titleText = 'Web Service options for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
- bodyText += '<tr>';
- bodyText += '<td class="key">HTTP Method</td><td style="border:0;"><select id="select-' + inputID + '-method' + '">';
- for (var optionItem in ActionHandler.httpMethodOptions) {
- var label = ActionHandler.httpMethodOptions[optionItem]['label'];
- var optionValue = ActionHandler.httpMethodOptions[optionItem]['value'];
- var selected = optionValue == PWM_VAR['clientSettingCache'][keyName][iteration]['method'];
- bodyText += '<option value="' + optionValue + '"' + (selected ? ' selected' : '') + '>' + label + '</option>';
- }
- bodyText += '</td>';
- bodyText += '</tr><tr>';
- bodyText += '<td class="key">HTTP Headers</td><td><button id="button-' + inputID + '-headers"><span class="btn-icon fa fa-list-ul"/> Edit</button></td>';
- bodyText += '</tr><tr>';
- bodyText += '<td class="key">URL</td><td><input type="text" placeholder="http://www.example.com/service" id="input-' + inputID + '-url' + '" value="' + value['url'] + '"/></td>';
- bodyText += '</tr><tr>';
- bodyText += '<td class="key">Body</td><td><textarea style="max-width:300px; height:100px; max-height:100px" class="configStringInput" id="input-' + inputID + '-body' + '"/>' + value['body'] + '</textarea></td>';
- bodyText += '</tr>';
- } else if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'ldap') {
- titleText = 'LDAP options for ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'];
- bodyText += '<tr>';
- bodyText += '<td class="key">Attribute Name</td><td><input style="width:300px" class="configStringInput" type="text" id="input-' + inputID + '-attributeName' + '" value="' + value['attributeName'] + '"/></td>';
- bodyText += '</tr><tr>';
- bodyText += '<td class="key">Attribute Value</td><td><input style="width:300px" class="configStringInput" type="text" id="input-' + inputID + '-attributeValue' + '" value="' + value['attributeValue'] + '"/></td>';
- bodyText += '</tr>';
- bodyText += '<tr>';
- bodyText += '<td class="key">Operation Type</td><td style="border:0;"><select id="select-' + inputID + '-ldapMethod' + '">';
- for (var optionItem in ActionHandler.ldapMethodOptions) {
- var label = ActionHandler.ldapMethodOptions[optionItem]['label'];
- var optionValue = ActionHandler.ldapMethodOptions[optionItem]['value'];
- var selected = optionValue == PWM_VAR['clientSettingCache'][keyName][iteration]['ldapMethod'];
- bodyText += '<option value="' + optionValue + '"' + (selected ? ' selected' : '') + '>' + label + '</option>';
- }
- bodyText += '</td></tr>';
- }
- bodyText += '</table>';
- PWM_MAIN.showDialog({
- title: titleText,
- text: bodyText,
- loadFunction: function(){
- PWM_MAIN.addEventHandler('button-' + inputID + '-headers','click',function(){
- ActionHandler.showHeadersDialog(keyName,iteration);
- });
- if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'webservice') {
- PWM_MAIN.addEventHandler('select-' + inputID + '-method','input',function(){
- PWM_VAR['clientSettingCache'][keyName][iteration]['method'] = PWM_MAIN.getObject('select-' + inputID + '-method').value;
- ActionHandler.writeFormSetting(keyName);
- });
- PWM_MAIN.addEventHandler('input-' + inputID + '-url','input',function(){
- PWM_VAR['clientSettingCache'][keyName][iteration]['url'] = PWM_MAIN.getObject('input-' + inputID + '-url').value;
- ActionHandler.writeFormSetting(keyName);
- });
- PWM_MAIN.addEventHandler('input-' + inputID + '-body','input',function(){
- PWM_VAR['clientSettingCache'][keyName][iteration]['body'] = PWM_MAIN.getObject('input-' + inputID + '-body').value;
- ActionHandler.writeFormSetting(keyName);
- });
- } else if (PWM_VAR['clientSettingCache'][keyName][iteration]['type'] == 'ldap') {
- PWM_MAIN.addEventHandler('input-' + inputID + '-attributeName','input',function(){
- PWM_VAR['clientSettingCache'][keyName][iteration]['attributeName'] = PWM_MAIN.getObject('input-' + inputID + '-attributeName').value;
- ActionHandler.writeFormSetting(keyName);
- });
- PWM_MAIN.addEventHandler('input-' + inputID + '-attributeValue','input',function(){
- PWM_VAR['clientSettingCache'][keyName][iteration]['attributeValue'] = PWM_MAIN.getObject('input-' + inputID + '-attributeValue').value;
- ActionHandler.writeFormSetting(keyName);
- });
- PWM_MAIN.addEventHandler('select-' + inputID + '-ldapMethod','input',function(){
- PWM_VAR['clientSettingCache'][keyName][iteration]['ldapMethod'] = PWM_MAIN.getObject('select-' + inputID + '-ldapMethod').value;
- ActionHandler.writeFormSetting(keyName);
- });
- }
- }
- });
- });
- };
- ActionHandler.showHeadersDialog = function(keyName, iteration) {
- require(["dijit/Dialog","dijit/form/ValidationTextBox","dijit/form/Button","dijit/form/TextBox"],function(Dialog,ValidationTextBox,Button,TextBox){
- var inputID = 'value_' + keyName + '_' + iteration + "_" + "headers_";
- var bodyText = '';
- bodyText += '<table class="noborder">';
- bodyText += '<tr>';
- bodyText += '<td><b>Name</b></td><td><b>Value</b></td>';
- bodyText += '</tr><tr>';
- for (var headerName in PWM_VAR['clientSettingCache'][keyName][iteration]['headers']) {
- var value = PWM_VAR['clientSettingCache'][keyName][iteration]['headers'][headerName];
- var optionID = inputID + headerName;
- bodyText += '<td>' + headerName + '</td><td>' + value + '</td>';
- bodyText += '<td><span class="delete-row-icon action-icon fa fa-times" id="button-' + optionID + '-deleteRow"></span></td>';
- bodyText += '</tr><tr>';
- }
- bodyText += '</tr></table>';
- bodyText += '<br/>';
- bodyText += '<button id="button-' + inputID + '-addHeader" class="btn"><span class="btn-icon fa fa-plus-square"></span>Add Header</button>';
- PWM_MAIN.showDialog({
- title: 'Http Headers for webservice ' + PWM_VAR['clientSettingCache'][keyName][iteration]['name'],
- text: bodyText,
- okAction: function() {
- ActionHandler.showOptionsDialog(keyName,iteration);
- },
- loadFunction: function() {
- for (var headerName in PWM_VAR['clientSettingCache'][keyName][iteration]['headers']) {
- var headerID = inputID + headerName;
- PWM_MAIN.addEventHandler('button-' + headerID + '-deleteRow','click',function(){
- delete PWM_VAR['clientSettingCache'][keyName][iteration]['headers'][headerName];
- ActionHandler.writeFormSetting(keyName);
- ActionHandler.showHeadersDialog(keyName, iteration);
- });
- }
- PWM_MAIN.addEventHandler('button-' + inputID + '-addHeader','click',function(){
- ActionHandler.addHeader(keyName, iteration);
- });
- }
- });
- });
- };
- ActionHandler.addHeader = function(keyName, iteration) {
- var body = '<table class="noborder">';
- body += '<tr><td>Name</td><td><input class="configStringInput" id="newHeaderName" style="width:300px"/></td></tr>';
- body += '<tr><td>Value</td><td><input class="configStringInput" id="newHeaderValue" style="width:300px"/></td></tr>';
- body += '</table>';
- var updateFunction = function(){
- PWM_MAIN.getObject('dialog_ok_button').disabled = true;
- PWM_VAR['newHeaderName'] = PWM_MAIN.getObject('newHeaderName').value;
- PWM_VAR['newHeaderValue'] = PWM_MAIN.getObject('newHeaderValue').value;
- if (PWM_VAR['newHeaderName'].length > 1 && PWM_VAR['newHeaderValue'].length > 1) {
- PWM_MAIN.getObject('dialog_ok_button').disabled = false;
- }
- };
- PWM_MAIN.showConfirmDialog({
- title:'New Header',
- text:body,
- showClose:true,
- loadFunction:function(){
- PWM_MAIN.addEventHandler('newHeaderName','input',function(){
- updateFunction();
- });
- PWM_MAIN.addEventHandler('newHeaderValue','input',function(){
- updateFunction();
- });
- },okAction:function(){
- var headers = PWM_VAR['clientSettingCache'][keyName][iteration]['headers'];
- headers[PWM_VAR['newHeaderName']] = PWM_VAR['newHeaderValue'];
- ActionHandler.writeFormSetting(keyName);
- ActionHandler.showHeadersDialog(keyName, iteration);
- }
- });
- };
- // -------------------------- email table handler ------------------------------------
- var EmailTableHandler = {};
- EmailTableHandler.init = function(keyName) {
- console.log('EmailTableHandler init for ' + keyName);
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- EmailTableHandler.draw(keyName);
- });
- };
- EmailTableHandler.draw = function(keyName) {
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- var parentDiv = 'table_setting_' + keyName;
- PWM_CFGEDIT.clearDivElements(parentDiv, true);
- require(["dojo/parser","dojo/html","dijit/form/ValidationTextBox","dijit/form/Textarea"],
- function(dojoParser,dojoHtml,ValidationTextBox,Textarea){
- PWM_CFGEDIT.clearDivElements(parentDiv, false);
- for (var localeName in resultValue) {
- EmailTableHandler.drawRow(keyName,localeName,parentDiv)
- }
- if (PWM_MAIN.isEmpty(resultValue)) {
- var newTableRow = document.createElement("tr");
- newTableRow.setAttribute("style", "border-width: 0");
- newTableRow.setAttribute("colspan", "5");
- var newTableData = document.createElement("td");
- newTableData.setAttribute("style", "border-width: 0;");
- var addItemButton = document.createElement("button");
- addItemButton.setAttribute("type", "[button");
- addItemButton.setAttribute("onclick", "PWM_CFGEDIT.resetSetting('" + keyName + "',function(){PWM_CFGEDIT.loadMainPageBody()});");
- addItemButton.setAttribute("class", "btn");
- addItemButton.innerHTML = '<span class="btn-icon fa fa-plus-square"></span>Add Value';
- newTableData.appendChild(addItemButton);
- newTableRow.appendChild(newTableData);
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- parentDivElement.appendChild(newTableRow);
- } else {
- var addLocaleFunction = function(localeValue) {
- if (!PWM_VAR['clientSettingCache'][keyName][localeValue]) {
- PWM_VAR['clientSettingCache'][keyName][localeValue] = {};
- EmailTableHandler.writeSetting(keyName,true);
- }
- };
- PWM_CFGEDIT.addAddLocaleButtonRow(parentDiv, keyName, addLocaleFunction);
- }
- dojoParser.parse(parentDiv);
- });
- };
- EmailTableHandler.drawRow = function(keyName, localeName, parentDiv) {
- require(["dojo/parser","dojo/html","dijit/form/ValidationTextBox","dijit/form/Textarea"],
- function(dojoParser,dojoHtml,ValidationTextBox,Textarea){
- var localeTableRow = document.createElement("tr");
- localeTableRow.setAttribute("style", "border-width: 0;");
- var localeTdName = document.createElement("td");
- localeTdName.setAttribute("style", "border-width: 0; width:15px");
- localeTdName.innerHTML = localeName;
- localeTableRow.appendChild(localeTdName);
- var localeTdContent = document.createElement("td");
- localeTdContent.setAttribute("style", "border-width: 0; width: 520px");
- localeTableRow.appendChild(localeTdContent);
- var localeTableElement = document.createElement("table");
- localeTableElement.setAttribute("style", "border-width: 0px; width:515px; margin:0");
- localeTdContent.appendChild(localeTableElement);
- var idPrefix = "setting_" + localeName + "_" + keyName;
- var htmlBody = '';
- htmlBody += '<table class="noborder">';
- htmlBody += '<tr><td style="width:30px; text-align:right">To</td>';
- htmlBody += '<td><input id="' + idPrefix + '_to"/></td></tr>';
- htmlBody += '<tr><td style="width:30px; text-align:right">From</td>';
- htmlBody += '<td><input id="' + idPrefix + '_from"/></td></tr>';
- htmlBody += '<tr><td style="width:30px; text-align:right">Subject</td>';
- htmlBody += '<td><input id="' + idPrefix + '_subject"/></td></tr>';
- htmlBody += '<tr><td style="width:30px; text-align:right">Plain Body</td>';
- htmlBody += '<td><input id="' + idPrefix + '_bodyPlain"/></td></tr>';
- htmlBody += '<tr><td style="width:30px; text-align:right">HTML Body</td>';
- htmlBody += '<td><div style="border:2px solid #EAEAEA; background: white; width: 446px" onclick="EmailTableHandler.popupEditor(\'' + keyName + '\',\'' + localeName + '\')">';
- htmlBody += PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'] ? PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'] : " " ;
- htmlBody += '</div></td></tr>';
- htmlBody += "</table>"
- dojoHtml.set(localeTableElement,htmlBody);
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- parentDivElement.appendChild(localeTableRow);
- PWM_MAIN.clearDijitWidget(idPrefix + "_to");
- new ValidationTextBox({
- value: PWM_VAR['clientSettingCache'][keyName][localeName]['to'],
- style: 'width: 450px',
- required: true,
- onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['to'] = this.value;EmailTableHandler.writeSetting(keyName)}
- },idPrefix + "_to");
- PWM_MAIN.clearDijitWidget(idPrefix + "_from");
- new ValidationTextBox({
- value: PWM_VAR['clientSettingCache'][keyName][localeName]['from'],
- style: 'width: 450px',
- required: true,
- onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['from'] = this.value;EmailTableHandler.writeSetting(keyName)}
- },idPrefix + "_from");
- PWM_MAIN.clearDijitWidget(idPrefix + "_subject");
- new ValidationTextBox({
- value: PWM_VAR['clientSettingCache'][keyName][localeName]['subject'],
- style: 'width: 450px',
- required: true,
- onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['subject'] = this.value;EmailTableHandler.writeSetting(keyName)}
- },idPrefix + "_subject");
- PWM_MAIN.clearDijitWidget(idPrefix + "_bodyPlain");
- new Textarea({
- value: PWM_VAR['clientSettingCache'][keyName][localeName]['bodyPlain'],
- style: 'width: 450px',
- required: true,
- onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['bodyPlain'] = this.value;EmailTableHandler.writeSetting(keyName)}
- },idPrefix + "_bodyPlain");
- { // add a spacer row
- var spacerTableRow = document.createElement("tr");
- spacerTableRow.setAttribute("style", "border-width: 0");
- parentDivElement.appendChild(spacerTableRow);
- var spacerTableData = document.createElement("td");
- spacerTableData.setAttribute("style", "border-width: 0");
- spacerTableData.innerHTML = " ";
- spacerTableRow.appendChild(spacerTableData);
- }
- if (localeName != '' || PWM_MAIN.itemCount(PWM_VAR['clientSettingCache'][keyName])){ // add remove locale x
- var imgElement2 = document.createElement("div");
- imgElement2.setAttribute("style", "width: 10px; height: 10px;");
- imgElement2.setAttribute("class", "delete-row-icon action-icon fa fa-times");
- imgElement2.setAttribute("id", "button-" + keyName + "-" + localeName + "-deleteRow");
- //imgElement2.setAttribute("onclick", "delete PWM_VAR['clientSettingCache']['" + keyName + "']['" + localeName + "'];EmailTableHandler.writeSetting('" + keyName + "',true)");
- var tdElement = document.createElement("td");
- tdElement.setAttribute("style", "border-width: 0; text-align: left; vertical-align: top");
- localeTableRow.appendChild(tdElement);
- tdElement.appendChild(imgElement2);
- }
- PWM_MAIN.addEventHandler("button-" + keyName + "-" + localeName + "-deleteRow","click",function(){
- delete PWM_VAR['clientSettingCache'][keyName][localeName];
- EmailTableHandler.writeSetting(keyName,true);
- });
- });
- };
- EmailTableHandler.popupEditor = function(keyName, localeName) {
- require(["dijit/Editor","dijit/_editor/plugins/AlwaysShowToolbar","dijit/_editor/plugins/LinkDialog","dijit/_editor/plugins/ViewSource","dijit/_editor/plugins/FontChoice","dijit/_editor/plugins/TextColor"],
- function(Editor,AlwaysShowToolbar){
- var idValue = keyName + "_" + localeName + "_htmlEditor";
- var idValueDialog = idValue + "_Dialog";
- var bodyText = '';
- bodyText += '<div id="' + idValue + '" style="border:2px solid #EAEAEA; min-height: 200px;"></div>';
- PWM_MAIN.showDialog({
- title: "HTML Editor",
- text: bodyText,
- dialogClass: 'wide',
- loadFunction:function(){
- PWM_MAIN.clearDijitWidget(idValue);
- new Editor({
- extraPlugins: [
- AlwaysShowToolbar,"viewsource",
- {name:"dijit/_editor/plugins/LinkDialog",command:"createLink",urlRegExp:".*"},
- "fontName","foreColor"
- ],
- height: '',
- value: PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'],
- style: 'width: 100%',
- onChange: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'] = this.get('value')},
- onKeyUp: function(){PWM_VAR['clientSettingCache'][keyName][localeName]['bodyHtml'] = this.get('value')}
- },idValue).startup();
- },
- okAction:function(){
- EmailTableHandler.writeSetting(keyName,true);
- }
- });
- });
- };
- EmailTableHandler.writeSetting = function(settingKey, redraw) {
- var currentValues = PWM_VAR['clientSettingCache'][settingKey];
- PWM_CFGEDIT.writeSetting(settingKey, currentValues);
- if (redraw) {
- EmailTableHandler.draw(settingKey);
- }
- };
- // -------------------------- boolean handler ------------------------------------
- var BooleanHandler = {};
- BooleanHandler.init = function(keyName) {
- console.log('BooleanHandler init for ' + keyName);
- var parentDiv = 'table_setting_' + keyName;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- parentDivElement.innerHTML = '<label class="checkboxWrapper">'
- + '<input type="checkbox" id="value_' + keyName + '" value="false" disabled/>'
- + 'Enabled (True)</label>';
- PWM_CFGEDIT.readSetting(keyName,function(data){
- var checkElement = PWM_MAIN.getObject("value_" + keyName);
- checkElement.checked = data;
- checkElement.disabled = false;
- PWM_MAIN.addEventHandler("value_" + keyName, 'change', function(){
- PWM_CFGEDIT.writeSetting(keyName,checkElement.checked);
- });
- });
- };
- BooleanHandler.toggle = function(keyName,widget) {
- PWM_CFGEDIT.writeSetting(keyName,widget.checked);
- };
- // -------------------------- challenge handler ------------------------------------
- var ChallengeSettingHandler = {};
- ChallengeSettingHandler.defaultItem = {text:'Question',minLength:4,maxLength:200,adminDefined:true};
- ChallengeSettingHandler.init = function(keyName) {
- var parentDiv = "table_setting_" + keyName;
- console.log('ChallengeSettingHandler init for ' + keyName);
- PWM_CFGEDIT.clearDivElements(parentDiv, true);
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- ChallengeSettingHandler.draw(keyName);
- });
- };
- ChallengeSettingHandler.draw = function(keyName) {
- var parentDiv = "table_setting_" + keyName;
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- var bodyText = '';
- bodyText += '<table style="cursor: pointer; table-layout: fixed" class="noborder">';
- bodyText += '<col style="width:60px"/>';
- bodyText += '<col style="width:100%"/>';
- PWM_CFGEDIT.clearDivElements(parentDiv, false);
- for (var localeName in resultValue) {
- (function(localeKey) {
- var isDefaultLocale = localeKey == "";
- var multiValues = resultValue[localeKey];
- var rowCount = PWM_MAIN.itemCount(multiValues);
- var editJsText = 'ChallengeSettingHandler.editLocale(\'' + keyName + '\',\'' + localeKey + '\')';
- bodyText += '<tr><td style="" onclick="' + editJsText + '">';
- bodyText += isDefaultLocale ? "Default" : localeKey;
- bodyText += '</td>';
- bodyText += '<td onclick="' + editJsText + '"> ';
- bodyText += '<div style="text-overflow:ellipsis; white-space:nowrap; overflow:hidden">';
- if (rowCount > 0) {
- for (var iteration in multiValues) {
- (function (rowKey) {
- var questionText = multiValues[rowKey]['text'];
- var adminDefined = multiValues[rowKey]['adminDefined'];
- bodyText += '<div>' + (adminDefined ? questionText : '[User Defined]') + '</div>';
- }(iteration));
- }
- } else {
- bodyText += '[No Questions]';
- }
- bodyText += '</div>';
- //bodyText += '</td><td style="border:0; vertical-align: top">';
- //if (!isDefaultLocale) {
- // bodyText += '<span id="button-' + keyName + '-' + localeKey + '-deleteRow" style="top:0" class="delete-row-icon action-icon fa fa-times"/>';
- //}
- bodyText += '</td></tr>';
- bodyText += '<tr><td> </td></tr>';
- parentDivElement.innerHTML = bodyText;
- PWM_MAIN.addEventHandler('button-' + keyName + '-' + localeKey + '-deleteRow','click',function(){
- ChallengeSettingHandler.deleteLocale(keyName)
- });
- }(localeName));
- }
- bodyText += '</table>';
- var addLocaleFunction = function(localeValue) {
- if (localeValue in PWM_VAR['clientSettingCache'][keyName]) {
- PWM_MAIN.showDialog({title:PWM_MAIN.showString('Title_Error'),text:'Locale <i>' + localeValue + '</i> is already present.'});
- } else {
- PWM_VAR['clientSettingCache'][keyName][localeValue] = [];
- PWM_VAR['clientSettingCache'][keyName][localeValue][0] = ChallengeSettingHandler.defaultItem;
- ChallengeSettingHandler.write(keyName);
- ChallengeSettingHandler.editLocale(keyName,localeValue);
- }
- };
- var tableElement = document.createElement("table");
- parentDivElement.appendChild(tableElement);
- PWM_CFGEDIT.addAddLocaleButtonRow(tableElement, keyName, addLocaleFunction);
- };
- ChallengeSettingHandler.editLocale = function(keyName, localeKey) {
- var localeDisplay = localeKey == "" ? "Default" : localeKey;
- var dialogBody = '<div id="challengeLocaleDialogDiv" style="max-height:500px; overflow-x: auto">';
- var localeName = localeKey;
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- require(["dojo","dijit/registry","dojo/parser","dijit/form/Button","dijit/form/ValidationTextBox","dijit/form/Textarea","dijit/form/NumberSpinner","dijit/form/ToggleButton"],
- function(dojo,registry,dojoParser){
- var multiValues = resultValue[localeName];
- dialogBody += '<table class="noborder">';
- for (var iteration in multiValues) {
- (function(rowKey) {
- var isAdminDefined = multiValues[rowKey]['adminDefined'];
- var questionText = multiValues[rowKey]['text'];
- dialogBody += '<tr>';
- dialogBody += '<td colspan="200" style="border-width: 0;">';
- var inputID = "value-" + keyName + "-" + localeName + "-" + rowKey;
- PWM_MAIN.clearDijitWidget(inputID);
- dialogBody += '<textarea id="' + inputID + '" style="width: 700px" required="required"';
- dialogBody += ' data-dojo-type="dijit/form/Textarea' + '"';
- dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'text\'] = this.value"';
- if (!isAdminDefined) {
- dialogBody += ' disabled="disabled"';
- dialogBody += ' value="[User Defined]"';
- } else {
- dialogBody += ' value="' + questionText + '"';
- }
- dialogBody += '></textarea>';
- dialogBody += '<div class="delete-row-icon action-icon fa fa-times"';
- dialogBody += ' onclick="ChallengeSettingHandler.deleteRow(\'' + keyName + '\',\'' + localeKey + '\',\'' + rowKey + '\')");';
- dialogBody += '/>';
- dialogBody += '</td>';
- dialogBody += '</tr>';
- dialogBody += '<tr style="padding-bottom: 15px; border:0"><td style="padding-bottom: 15px; border:0">';
- dialogBody += '<button data-dojo-type="dijit/form/ToggleButton" data-dojo-props="iconClass:\'dijitCheckBoxIcon\',showLabel:true,label:\'Admin Defined\',checked:' + isAdminDefined + '"';
- dialogBody += ' onchange="ChallengeSettingHandler.toggleAdminDefinedRow(this,\'' + inputID + '\',\'' + keyName + '\',\'' + localeKey + '\',\'' + rowKey + '\')"';
- dialogBody += '></button>';
- dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
- 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}""';
- dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'minLength\'] = this.value"/><br/>Min Length';
- dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
- 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}""';
- dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'maxLength\'] = this.value"/><br/>Max Length';
- dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
- 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}""';
- dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'maxQuestionCharsInAnswer\'] = this.value"/><br/> Max Question Chars';
- dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
- var enforceWordlist = multiValues[rowKey]['enforceWordlist'];
- dialogBody += '<button data-dojo-type="dijit/form/ToggleButton" data-dojo-props="iconClass:\'dijitCheckBoxIcon\',showLabel:true,label:\'Enforce Wordlist\',checked:' + enforceWordlist + '"';
- dialogBody += ' onchange="PWM_VAR[\'clientSettingCache\'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'enforceWordlist\'] = this.checked"';
- dialogBody += '></button>';
- /*
- dialogBody += '</td><td style="padding-bottom: 15px; border:0">';
- dialogBody += '<input style="width: 50px" data-dojo-type="dijit/form/NumberSpinner" value="' +multiValues[rowKey]['points'] + '" data-dojo-props="constraints:{min:0,max:255,places:0}""';
- dialogBody += ' onchange="PWM_VAR['clientSettingCache'][\'' + keyName + '\'][\'' + localeKey + '\'][\'' + rowKey + '\'][\'points\'] = this.value"/><br/>Points';
- */
- dialogBody += '</td></tr>';
- }(iteration));
- }
- dialogBody += '</table></div>';
- dialogBody += '<br/><br/><button type="button" data-dojo-type="dijit/form/Button"';
- dialogBody += ' onclick="ChallengeSettingHandler.addRow(\'' + keyName + '\',\'' + localeKey + '\')"';
- dialogBody += '><span class="btn-icon fa fa-plus-square"></span>Add Value</button>';
- if (localeKey != "") {
- dialogBody += '<button type="button" data-dojo-type="dijit/form/Button"';
- dialogBody += ' onclick="ChallengeSettingHandler.deleteLocale(\'' + keyName + '\',\'' + localeKey + '\')"';
- dialogBody += '><span class="btn-icon fa fa-times"></span>Delete Locale ' + localeDisplay + '</button>';
- }
- var dialogTitle = PWM_SETTINGS['settings'][keyName]['label'] + ' - ' + localeDisplay;
- PWM_MAIN.showDialog({title:dialogTitle,text:dialogBody,showClose:true,dialogClass:'wide',loadFunction:function(){
- dojoParser.parse(PWM_MAIN.getObject('challengeLocaleDialogDiv'));
- },okAction:function(){
- ChallengeSettingHandler.write(keyName );
- ChallengeSettingHandler.draw(keyName);
- }});
- }
- );
- };
- ChallengeSettingHandler.deleteLocale = function(keyName,localeKey) {
- PWM_MAIN.showConfirmDialog({
- text: 'Are you sure you want to remove all the questions for the <i>' + localeKey + '</i> locale?',
- okAction:function(){
- PWM_MAIN.showWaitDialog();
- delete PWM_VAR['clientSettingCache'][keyName][localeKey];
- PWM_CFGEDIT.writeSetting(keyName, PWM_VAR['clientSettingCache'][keyName],function(){
- PWM_MAIN.closeWaitDialog();
- ChallengeSettingHandler.init(keyName);
- });
- }
- });
- };
- ChallengeSettingHandler.toggleAdminDefinedRow = function(toggleElement,inputID,keyName,localeKey,rowKey) {
- require(["dojo","dijit/registry"],function(dojo,registry){
- var currentSetting = toggleElement.checked;
- PWM_VAR['clientSettingCache'][keyName][localeKey][rowKey]['adminDefined'] = currentSetting;
- var inputElement = registry.byId(inputID);
- if (currentSetting) {
- inputElement.set('disabled',false);
- inputElement.set('value','Question');
- } else {
- inputElement.set('disabled',true);
- inputElement.set('value','[User Defined]');
- PWM_VAR['clientSettingCache'][keyName][localeKey][rowKey]['text'] = '';
- }
- });
- };
- ChallengeSettingHandler.deleteRow = function(keyName, localeKey, rowName) {
- delete PWM_VAR['clientSettingCache'][keyName][localeKey][rowName];
- ChallengeSettingHandler.editLocale(keyName, localeKey);
- };
- ChallengeSettingHandler.addRow = function(keyName, localeKey) {
- PWM_VAR['clientSettingCache'][keyName][localeKey].push(ChallengeSettingHandler.defaultItem);
- ChallengeSettingHandler.write(keyName);
- ChallengeSettingHandler.editLocale(keyName, localeKey);
- };
- ChallengeSettingHandler.write = function(keyName) {
- PWM_CFGEDIT.writeSetting(keyName, PWM_VAR['clientSettingCache'][keyName]);
- };
- // -------------------------- user permission handler ------------------------------------
- var UserPermissionHandler = {};
- UserPermissionHandler.defaultFilterValue = {type:'ldapFilter',ldapQuery:"(objectClass=*)",ldapBase:""};
- UserPermissionHandler.defaultGroupValue = {type:'ldapGroup',ldapBase:"cn=exampleGroup,ou=container,o=organization"};
- UserPermissionHandler.init = function(keyName) {
- console.log('UserPermissionHandler init for ' + keyName);
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- UserPermissionHandler.draw(keyName);
- });
- };
- UserPermissionHandler.draw = function(keyName) {
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- var parentDiv = 'table_setting_' + keyName;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- while (parentDivElement.firstChild) {
- parentDivElement.removeChild(parentDivElement.firstChild);
- }
- var htmlBody = '';
- for (var iteration in resultValue) {
- (function(rowKey) {
- var inputID = "value-" + keyName + "-" + rowKey;
- htmlBody += '<div class="setting_item_value_wrapper" style="float:left; width: 570px;"><div style="width:100%; text-align:center">';
- if (resultValue[rowKey]['type'] == 'ldapGroup') {
- htmlBody += 'LDAP Group';
- } else {
- htmlBody += 'LDAP Filter';
- }
- var currentProfileValue = ('ldapProfileID' in resultValue[rowKey]) ? resultValue[rowKey]['ldapProfileID'] : "";
- htmlBody += '</div><table class="noborder">'
- + '<td style="width:200px" id="' + inputID + '_profileHeader' + '">' + PWM_CONFIG.showString('Setting_Permission_Profile') + '</td>'
- + '<td><input style="width: 200px;" class="configStringInput" id="' + inputID + '-profile" list="' + inputID + '-datalist" value="' + currentProfileValue + '"/>'
- + '<datalist id="' + inputID + '-datalist"/></td>'
- + '</tr>';
- if (resultValue[rowKey]['type'] != 'ldapGroup') {
- var currentQueryValue = ('ldapQuery' in resultValue[rowKey]) ? resultValue[rowKey]['ldapQuery'] : "";
- htmlBody += '<tr>'
- + '<td><span id="' + inputID + '_FilterHeader' + '">' + PWM_CONFIG.showString('Setting_Permission_Filter') + '</span></td>'
- + '<td><input style="width: 420px;" class="configStringInput" id="' + inputID + '-query" value="' + currentQueryValue + '"></input></td>'
- + '</tr>';
- }
- var currentBaseValue = ('ldapBase' in resultValue[rowKey]) ? resultValue[rowKey]['ldapBase'] : "";
- htmlBody += '<tr>'
- + '<td><span id="' + inputID + '_BaseHeader' + '">'
- + PWM_CONFIG.showString((resultValue[rowKey]['type'] == 'ldapGroup') ? 'Setting_Permission_Base_Group' : 'Setting_Permission_Base')
- + '</span></td>'
- + '<td><input style="width: 420px;" class="configStringInput" id="' + inputID + '-base" value="' + currentBaseValue + '"></input></td>'
- + '</td>'
- + '</tr>';
- htmlBody += '</table></div><div id="button-' + inputID + '-deleteRow" style="float:right" class="delete-row-icon action-icon fa fa-times"></div>';
- }(iteration));
- }
- parentDivElement.innerHTML = parentDivElement.innerHTML + htmlBody;
- setTimeout(function(){
- for (var iteration in resultValue) {
- (function(rowKey) {
- var inputID = "value-" + keyName + "-" + rowKey;
- console.log('inputID-' + inputID);
- var profileSelectElement = PWM_MAIN.getObject(inputID + "-datalist");
- profileSelectElement.appendChild(new Option('all'));
- for (var i in PWM_VAR['ldapProfileIds']) {
- profileSelectElement.appendChild(new Option(PWM_VAR['ldapProfileIds'][i]));
- }
- PWM_MAIN.addEventHandler(inputID + '-profile','input',function(){
- console.log('write');
- PWM_VAR['clientSettingCache'][keyName][rowKey]['ldapProfileID'] = this.value;
- UserPermissionHandler.write(keyName);
- });
- if (resultValue[rowKey]['type'] != 'ldapGroup') {
- var queryInput = PWM_MAIN.getObject(inputID + "-query");
- queryInput.disabled = false;
- queryInput.required = true;
- PWM_MAIN.addEventHandler(inputID + "-query",'input',function(){
- PWM_VAR['clientSettingCache'][keyName][rowKey]['ldapQuery'] = this.value;
- UserPermissionHandler.write(keyName);
- });
- }
- var queryInput = PWM_MAIN.getObject(inputID + "-base");
- queryInput.disabled = false;
- queryInput.required = true;
- PWM_MAIN.addEventHandler(inputID + "-base",'input',function(){
- PWM_VAR['clientSettingCache'][keyName][rowKey]['ldapBase'] = this.value;
- UserPermissionHandler.write(keyName);
- });
- var deleteButtonID = 'button-' + inputID + '-deleteRow';
- var hasID = PWM_MAIN.getObject(deleteButtonID) ? "YES" : "NO";
- console.log("addEventHandler row: " + deleteButtonID + " rowKey=" + rowKey + " hasID="+hasID);
- PWM_MAIN.addEventHandler(deleteButtonID,'click',function(){
- console.log("delete row: " + inputID + " rowKey=" + rowKey + " hasID="+hasID);
- delete PWM_VAR['clientSettingCache'][keyName][rowKey];
- UserPermissionHandler.write(keyName,true);
- });
- PWM_MAIN.showTooltip({
- id:inputID +'_profileHeader',
- width: 300,
- text:PWM_CONFIG.showString('Tooltip_Setting_Permission_Profile')
- });
- PWM_MAIN.showTooltip({
- id:inputID +'_FilterHeader',
- width: 300,
- text:PWM_CONFIG.showString('Tooltip_Setting_Permission_Filter')
- });
- PWM_MAIN.showTooltip({
- id: inputID + '_BaseHeader',
- width: 300,
- text: PWM_CONFIG.showString('Tooltip_Setting_Permission_Base')
- });
- }(iteration));
- }
- },10);
- var options = PWM_SETTINGS['settings'][keyName]['options'];
- var buttonRowHtml = '<button class="btn" id="button-' + keyName + '-addFilterValue">'
- + '<span class="btn-icon fa fa-plus-square"></span>Add Filter</button>';
- var hideGroup = 'hideGroups' in options && options['hideGroups'] == "true";
- if (!hideGroup) {
- buttonRowHtml += '<button class="btn" id="button-' + keyName + '-addGroupValue">'
- + '<span class="btn-icon fa fa-plus-square"></span>Add Group</button>';
- }
- var hideMatch = 'hideMatch' in options && options['hideMatch'] == "true";
- if (!hideMatch) {
- buttonRowHtml += '<button id="button-' + keyName + '-viewMatches" class="btn">'
- + '<span class="btn-icon fa fa-eye"></span>View Matches</button>';
- }
- parentDivElement.innerHTML = parentDivElement.innerHTML + buttonRowHtml;
- PWM_MAIN.addEventHandler('button-' + keyName + '-viewMatches','click',function(){
- PWM_CFGEDIT.executeSettingFunction(keyName,'password.pwm.config.function.UserMatchViewerFunction')
- });
- PWM_MAIN.addEventHandler('button-' + keyName + '-addFilterValue','click',function(){
- PWM_VAR['clientSettingCache'][keyName].push(UserPermissionHandler.defaultFilterValue);
- UserPermissionHandler.write(keyName, true);
- });
- PWM_MAIN.addEventHandler('button-' + keyName + '-addGroupValue','click',function(){
- PWM_VAR['clientSettingCache'][keyName].push(UserPermissionHandler.defaultGroupValue);
- UserPermissionHandler.write(keyName, true);
- });
- };
- UserPermissionHandler.write = function(settingKey,redraw) {
- var nextFunction = function(){
- if (redraw) {
- UserPermissionHandler.draw(settingKey);
- }
- };
- PWM_CFGEDIT.writeSetting(settingKey, PWM_VAR['clientSettingCache'][settingKey], nextFunction);
- };
- // -------------------------- option list handler ------------------------------------
- var OptionListHandler = {};
- OptionListHandler.defaultItem = [];
- OptionListHandler.init = function(keyName) {
- console.log('OptionListHandler init for ' + keyName);
- var parentDiv = 'table_setting_' + keyName;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- var htmlBody = '';
- var options = PWM_SETTINGS['settings'][keyName]['options'];
- for (var key in options) {
- (function (optionKey) {
- var buttonID = keyName + "_button_" + optionKey;
- htmlBody += '<label class="checkboxWrapper" style="min-width:180px;">'
- + '<input type="checkbox" id="' + buttonID + '" disabled/>'
- + options[optionKey] + '</label>';
- })(key);
- }
- parentDivElement.innerHTML = htmlBody;
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- OptionListHandler.draw(keyName);
- });
- };
- OptionListHandler.draw = function(keyName) {
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- require(["dojo/_base/array"],function(array){
- var options = PWM_SETTINGS['settings'][keyName]['options'];
- for (var key in options) {
- (function (optionKey) {
- var buttonID = keyName + "_button_" + optionKey;
- var checked = array.indexOf(resultValue,optionKey) > -1;
- PWM_MAIN.getObject(buttonID).checked = checked;
- PWM_MAIN.getObject(buttonID).disabled = false;
- PWM_MAIN.addEventHandler(buttonID,'change',function(){
- OptionListHandler.toggle(keyName,optionKey);
- });
- })(key);
- }
- });
- };
- OptionListHandler.toggle = function(keyName,optionKey) {
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- require(["dojo/_base/array"],function(array){
- var checked = array.indexOf(resultValue,optionKey) > -1;
- if (checked) {
- var index = array.indexOf(resultValue, optionKey);
- while (index > -1) {
- resultValue.splice(index, 1);
- index = array.indexOf(resultValue, optionKey);
- }
- } else {
- resultValue.push(optionKey);
- }
- });
- PWM_CFGEDIT.writeSetting(keyName, resultValue);
- };
- // -------------------------- numeric value handler ------------------------------------
- var NumericValueHandler = {};
- NumericValueHandler.init = function(settingKey) {
- NumericValueHandler.impl(settingKey, 'number', 0, 100);
- };
- NumericValueHandler.impl = function(settingKey, type, defaultMin, defaultMax) {
- var parentDiv = 'table_setting_' + settingKey;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- var options = PWM_SETTINGS['settings'][settingKey]['options'];
- var pattern = PWM_SETTINGS['settings'][settingKey]['pattern'];
- var min = 'min' in options ? parseInt(options['min']) : defaultMin;
- var max = 'max' in options ? parseInt(options['max']) : defaultMax;
- var htmlBody = '<input type="number" id="value_' + settingKey + '" class="configNumericInput" min="'+min+'" max="'+max+'"/>';
- if (type == 'number') {
- htmlBody += '<span class="configNumericLimits">' + min + ' - ' + max + '</span>';
- } else if (type == 'duration') {
- htmlBody += '<span class="configNumericLimits">' + PWM_MAIN.showString('Display_Seconds') + '</span>'
- htmlBody += '<span style="margin-left:10px" id="display-' + settingKey + '-duration"></span>';
- }
- parentDivElement.innerHTML = htmlBody;
- PWM_CFGEDIT.readSetting(settingKey,function(data){
- PWM_MAIN.getObject('value_' + settingKey).value = data;
- PWM_VAR['clientSettingCache'][settingKey] = data;
- PWM_MAIN.addEventHandler('value_' + settingKey,'input',function(){
- var value = PWM_MAIN.getObject('value_' + settingKey).value;
- var valid = value.match(/[0-9]+/);
- if (valid) {
- console.log('valid');
- PWM_VAR['clientSettingCache'][settingKey] = data;
- PWM_CFGEDIT.writeSetting(settingKey, value);
- NumericValueHandler.updateDurationDisplay(settingKey,value);
- } else {
- console.log('invalid');
- PWM_MAIN.getObject('value_' + settingKey).value = PWM_VAR['clientSettingCache'][settingKey];
- }
- });
- PWM_MAIN.addEventHandler('value_' + settingKey,'mousewheel',function(e){ e.blur(); });
- NumericValueHandler.updateDurationDisplay(settingKey,data);
- });
- };
- NumericValueHandler.updateDurationDisplay = function(settingKey, numberValue) {
- var displayElement = PWM_MAIN.getObject('display-' + settingKey + '-duration');
- if (displayElement) {
- displayElement.innerHTML = (numberValue && numberValue != 0)
- ? PWM_MAIN.convertSecondsToDisplayTimeDuration(numberValue, true)
- : '';
- }
- };
- // -------------------------- duration value ---------------------------
- var DurationValueHandler = {};
- DurationValueHandler.init = function(settingKey) {
- NumericValueHandler.impl(settingKey, 'duration', -1, 365 * 24 * 60 * 60 );
- };
- // -------------------------- string value handler ------------------------------------
- var StringValueHandler = {};
- StringValueHandler.init = function(settingKey) {
- var parentDiv = 'table_setting_' + settingKey;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- parentDivElement.innerHTML = '<input class="configStringInput" id="value_' + settingKey + '" name="setting_' + settingKey + '" disabled/>'
- + ' <span id="icon-' + settingKey + '-warning" style="visibility:hidden; color:orange" class="btn-icon fa fa-warning"></span>';
- PWM_CFGEDIT.readSetting(settingKey,function(data){
- var inputElement = PWM_MAIN.getObject("value_" + settingKey);
- inputElement.value = data;
- if (PWM_SETTINGS['settings'][settingKey]['required']) {
- inputElement.required = true;
- }
- if (PWM_SETTINGS['settings'][settingKey]['pattern']) {
- inputElement.pattern = PWM_SETTINGS['settings'][settingKey]['pattern'];
- inputElement.title = PWM_CONFIG.showString('Warning_InvalidFormat');
- var validateValue = function() {
- var re = new RegExp(PWM_SETTINGS['settings'][settingKey]['pattern']);
- var matches = re.test(inputElement.value);
- PWM_MAIN.getObject('icon-' + settingKey + '-warning').style.visibility = matches ? 'hidden' : 'visible';
- };
- PWM_MAIN.addEventHandler("value_" + settingKey,"keyup",function(){
- validateValue();
- });
- validateValue();
- PWM_MAIN.showTooltip({id:'icon-'+settingKey+'-warning',text:PWM_CONFIG.showString('Warning_InvalidFormat')});
- }
- if (PWM_SETTINGS['settings'][settingKey]['placeholder']) {
- inputElement.placeholder = PWM_SETTINGS['settings'][settingKey]['placeholder'];
- }
- inputElement.disabled = false;
- PWM_MAIN.addEventHandler("value_" + settingKey,"input,change",function(){
- PWM_CFGEDIT.writeSetting(settingKey,inputElement.value);
- });
- });
- };
- // -------------------------- text area handler ------------------------------------
- var TextAreaValueHandler = {};
- TextAreaValueHandler.init = function(settingKey) {
- var parentDiv = 'table_setting_' + settingKey;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- parentDivElement.innerHTML = '<textarea style="max-height:300px; overflow-y: auto" id="value_' + settingKey + '" name="setting_' + settingKey + '"> </textarea>';
- PWM_MAIN.clearDijitWidget("value_" + settingKey);
- require(["dijit/form/Textarea"],function(Textarea){
- new Textarea({
- regExp: PWM_SETTINGS['settings'][settingKey]['pattern'],
- required: PWM_SETTINGS['settings'][settingKey]['required'],
- invalidMessage: PWM_CONFIG.showString('Warning_InvalidFormat'),
- style: "width: 550px; max-width:550px; max-height:300px; overflow:auto; white-space: nowrap",
- onChange: function() {
- PWM_CFGEDIT.writeSetting(settingKey, this.value);
- },
- placeholder: PWM_SETTINGS['settings'][settingKey]['placeholder'],
- value: PWM_MAIN.showString('Display_PleaseWait'),
- disabled: true,
- id: "value_" + settingKey
- }, "value_" + settingKey);
- PWM_CFGEDIT.readInitialTextBasedValue(settingKey);
- });
- };
- // -------------------------- select value handler ------------------------------------
- var SelectValueHandler = {};
- SelectValueHandler.init = function(settingKey) {
- var parentDiv = 'table_setting_' + settingKey;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- var htmlBody = '<select id="setting_' + settingKey + '" disabled="true">'
- + '<option value="' + PWM_MAIN.showString('Display_PleaseWait') + '">' + PWM_MAIN.showString('Display_PleaseWait') + '</option></select>';
- parentDivElement.innerHTML = htmlBody;
- PWM_MAIN.clearDijitWidget("value_" + settingKey);
- PWM_MAIN.clearDijitWidget("setting_" + settingKey);
- PWM_MAIN.addEventHandler('setting_' + settingKey,'change',function(){
- var settingElement = PWM_MAIN.getObject('setting_' + settingKey);
- var selectedValue = settingElement.options[settingElement.selectedIndex].value;
- PWM_CFGEDIT.writeSetting(settingKey,selectedValue)
- });
- PWM_CFGEDIT.readSetting(settingKey, function(dataValue) {
- var settingElement = PWM_MAIN.getObject('setting_' + settingKey);
- var optionsHtml = '';
- var options = PWM_SETTINGS['settings'][settingKey]['options'];
- for (var option in options) {
- var optionValue = options[option];
- optionsHtml += '<option value="' + option + '">' + optionValue + '</option>'
- }
- settingElement.innerHTML = optionsHtml;
- settingElement.value = dataValue;
- settingElement.disabled = false;
- });
- };
- // -------------------------- x509 setting handler ------------------------------------
- var X509CertificateHandler = {};
- X509CertificateHandler.init = function(keyName) {
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- X509CertificateHandler.draw(keyName);
- });
- };
- X509CertificateHandler.draw = function(keyName) {
- var parentDiv = 'table_setting_' + keyName;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- var htmlBody = '<div style="max-height: 300px; overflow-y: auto">';
- for (var certCounter in resultValue) {
- (function (counter) {
- var certificate = resultValue[counter];
- htmlBody += '<div style="max-width:100%; margin-bottom:8px"><table style="max-width:100%" id="table_certificate' + keyName + '-' + counter + '">';
- htmlBody += '<tr><td colspan="2" class="key" style="text-align: center">Certificate ' + counter + ' <a id="certTimestamp-detail-' + keyName + '-' + counter + '">(detail)</a></td></tr>';
- htmlBody += '<tr><td>Subject</td><td><div class="setting_table_value">' + certificate['subject'] + '</div></td></tr>';
- htmlBody += '<tr><td>Issuer</td><td><div class="setting_table_value">' + certificate['issuer'] + '</div></td></tr>';
- htmlBody += '<tr><td>Serial</td><td><div class="setting_table_value">' + certificate['serial'] + '</div></td></tr>';
- htmlBody += '<tr><td>Issue Date</td><td id="certTimestamp-issue-' + keyName + '-' + counter + '" class="setting_table_value timestamp">' + certificate['issueDate'] + '</td></tr>';
- htmlBody += '<tr><td>Expire Date</td><td id="certTimestamp-expire-' + keyName + '-' + counter + '" class="setting_table_value timestamp">' + certificate['expireDate'] + '</td></tr>';
- htmlBody += '<tr><td>MD5 Hash</td><td><div class="setting_table_value">' + certificate['md5Hash'] + '</div></td></tr>';
- htmlBody += '<tr><td>SHA1 Hash</td><td><div class="setting_table_value">' + certificate['sha1Hash'] + '</div></td></tr>';
- htmlBody += '<tr><td>SHA512 Hash</td><td><div class="setting_table_value">' + certificate['sha512Hash'] + '</div></td></tr>';
- htmlBody += '</table></div>'
- })(certCounter);
- }
- htmlBody += '</div>';
- if (!PWM_MAIN.isEmpty(resultValue)) {
- htmlBody += '<button id="' + keyName + '_ClearButton" class="btn"><span class="btn-icon fa fa-times"></span>Clear</button>'
- } else {
- htmlBody += 'No certificates stored.<br/><br/>'
- }
- htmlBody += '<button id="' + keyName + '_AutoImportButton" class="btn"><span class="btn-icon fa fa-download"></span>Import From Server</button>'
- parentDivElement.innerHTML = htmlBody;
- for (certCounter in resultValue) {
- (function (counter) {
- PWM_MAIN.TimestampHandler.initElement(PWM_MAIN.getObject('certTimestamp-issue-' + keyName + '-' + counter));
- PWM_MAIN.TimestampHandler.initElement(PWM_MAIN.getObject('certTimestamp-expire-' + keyName + '-' + counter));
- PWM_MAIN.addEventHandler('certTimestamp-detail-' + keyName + '-' + counter,'click',function(){
- PWM_MAIN.showDialog({
- title: 'Detail - ' + PWM_SETTINGS['settings'][keyName]['label'] + ' - Certificate ' + counter,
- text: '<pre>' + resultValue[counter]['detail'] + '</pre>',
- dialogClass: 'wide',
- showClose: true
- });
- });
- })(certCounter);
- }
- if (!PWM_MAIN.isEmpty(resultValue)) {
- PWM_MAIN.addEventHandler(keyName + '_ClearButton','click',function(){
- handleResetClick(keyName);
- });
- }
- PWM_MAIN.addEventHandler(keyName + '_AutoImportButton','click',function(){
- switch (keyName) {
- case 'ldap.serverCerts':
- PWM_CFGEDIT.executeSettingFunction(keyName,'password.pwm.config.function.LdapCertImportFunction');
- break;
- case 'audit.syslog.certificates':
- PWM_CFGEDIT.executeSettingFunction(keyName,'password.pwm.config.function.SyslogCertImportFunction');
- break;
- default:
- alert('unhandled cert-import request for key=' + keyName);
- }
- });
- };
- // -------------------------- file setting handler ------------------------------------
- var FileValueHandler = {};
- FileValueHandler.init = function(keyName) {
- PWM_CFGEDIT.readSetting(keyName, function(resultValue) {
- PWM_VAR['clientSettingCache'][keyName] = resultValue;
- FileValueHandler.draw(keyName);
- });
- };
- FileValueHandler.draw = function(keyName) {
- var parentDiv = 'table_setting_' + keyName;
- var parentDivElement = PWM_MAIN.getObject(parentDiv);
- var resultValue = PWM_VAR['clientSettingCache'][keyName];
- var htmlBody = '';
- if (PWM_MAIN.isEmpty(resultValue)) {
- htmlBody = '<p>No File Present</p>';
- } else {
- for (var fileCounter in resultValue) {
- (function (counter) {
- var fileInfo = resultValue[counter];
- htmlBody += '<table style="width:100%" id="table_file' + keyName + '-' + counter + '">';
- htmlBody += '<tr><td colspan="2" class="key" style="text-align: center">File' + '</td></tr>';
- htmlBody += '<tr><td>Name</td><td class="setting_table_value">' + fileInfo['name'] + '</td></tr>';
- htmlBody += '<tr><td>Size</td><td class="setting_table_value">' + fileInfo['size'] + '</td></tr>';
- htmlBody += '<tr><td>MD5 checksum</td><td class="setting_table_value">' + fileInfo['md5sum'] + '</td></tr>';
- htmlBody += '<tr><td>SHA1 checksum</td><td class="setting_table_value">' + fileInfo['sha1sum'] + '</td></tr>';
- htmlBody += '</table>'
- })(fileCounter);
- }
- }
- if (PWM_MAIN.isEmpty(resultValue)) {
- htmlBody += '<button class="btn" id="button-uploadFile-' + keyName + '"><span class="btn-icon fa fa-upload"></span>Upload File</button>';
- } else {
- htmlBody += '<button class="btn" id="button-removeFile-' + keyName + '"><span class="btn-icon fa fa-trash-o"></span>Remove File</button>';
- }
- parentDivElement.innerHTML = htmlBody;
- PWM_MAIN.addEventHandler('button-uploadFile-' + keyName,'click',function(){
- FileValueHandler.uploadFile(keyName);
- });
- PWM_MAIN.addEventHandler('button-removeFile-' + keyName,'click',function(){
- PWM_MAIN.showConfirmDialog({text:'Are you sure you want to remove the currently stored file?',okAction:function(){
- PWM_MAIN.showWaitDialog({loadFunction:function(){
- PWM_CFGEDIT.resetSetting(keyName,function(){
- FileValueHandler.init(keyName);
- PWM_MAIN.closeWaitDialog();
- });
- }});
- }});
- });
- };
- FileValueHandler.uploadFile = function(keyName) {
- var options = {};
- options['url'] = "ConfigEditor?processAction=uploadFile&key=" + keyName;
- options['nextFunction'] = function() {
- PWM_MAIN.showWaitDialog({loadFunction:function(){
- FileValueHandler.init(keyName);
- PWM_MAIN.closeWaitDialog();
- }});
- };
- PWM_CONFIG.uploadFile(options);
- };
|