configeditor.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. /*
  2. * Password Management Servlets (PWM)
  3. * http://www.pwm-project.org
  4. *
  5. * Copyright (c) 2006-2009 Novell, Inc.
  6. * Copyright (c) 2009-2016 The PWM Project
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. "use strict";
  23. var PWM_CFGEDIT = PWM_CFGEDIT || {};
  24. var PWM_CONFIG = PWM_CONFIG || {};
  25. var PWM_MAIN = PWM_MAIN || {};
  26. var PWM_VAR = PWM_VAR || {};
  27. var PWM_SETTINGS = PWM_SETTINGS || {};
  28. PWM_VAR['outstandingOperations'] = 0;
  29. PWM_VAR['skippedSettingCount'] = 0;
  30. PWM_CFGEDIT.readSetting = function(keyName, valueWriter) {
  31. var modifiedOnly = PWM_CFGEDIT.readNavigationFilters()['modifiedSettingsOnly'];
  32. var maxLevel = parseInt(PWM_CFGEDIT.readNavigationFilters()['level']);
  33. PWM_VAR['outstandingOperations']++;
  34. PWM_CFGEDIT.handleWorkingIcon();
  35. var url = "editor?processAction=readSetting&key=" + keyName;
  36. if (PWM_CFGEDIT.readCurrentProfile()) {
  37. url = PWM_MAIN.addParamToUrl(url, 'profile', PWM_CFGEDIT.readCurrentProfile());
  38. }
  39. var loadFunction = function(data) {
  40. PWM_VAR['outstandingOperations']--;
  41. PWM_CFGEDIT.handleWorkingIcon();
  42. console.log('read data for setting ' + keyName);
  43. var resultValue = data['data']['value'];
  44. var isDefault = data['data']['isDefault'];
  45. var settingLevel = 0;
  46. if (PWM_SETTINGS['settings'][keyName] && PWM_SETTINGS['settings'][keyName]['level']) {
  47. settingLevel = PWM_SETTINGS['settings'][keyName]['level'];
  48. }
  49. var showSetting = (PWM_SETTINGS['settings'][keyName] && PWM_SETTINGS['settings'][keyName]['syntax'] == 'PROFILE') || (!modifiedOnly || !isDefault) && (maxLevel < 0 || settingLevel <= maxLevel );
  50. if (showSetting) {
  51. valueWriter(resultValue);
  52. PWM_MAIN.setStyle('outline_' + keyName,'display','inherit');
  53. PWM_CFGEDIT.updateSettingDisplay(keyName, isDefault);
  54. PWM_CFGEDIT.updateLastModifiedInfo(keyName, data);
  55. } else {
  56. PWM_MAIN.setStyle('outline_' + keyName,'display','none');
  57. PWM_VAR['skippedSettingCount']++;
  58. if (PWM_VAR['skippedSettingCount'] > 0 && PWM_MAIN.getObject('panel-skippedSettingInfo')) {
  59. PWM_MAIN.getObject('panel-skippedSettingInfo').innerHTML = "" + PWM_VAR['skippedSettingCount'] + " items are not shown due to filter settings."
  60. }
  61. }
  62. };
  63. var errorFunction = function(error) {
  64. PWM_VAR['outstandingOperations']--;
  65. PWM_CFGEDIT.handleWorkingIcon();
  66. PWM_MAIN.showDialog({title:PWM_MAIN.showString('Title_Error'),text:"Unable to communicate with server. Please refresh page."});
  67. console.log("error loading " + keyName + ", reason: " + error);
  68. };
  69. PWM_MAIN.ajaxRequest(url,loadFunction,{errorFunction:errorFunction});
  70. };
  71. PWM_CFGEDIT.updateLastModifiedInfo = function(keyName, data) {
  72. if (PWM_MAIN.getObject('panel-' + keyName + '-modifyTime')) {
  73. if (data['data']['modifyTime']) {
  74. PWM_MAIN.getObject('panel-' + keyName + '-modifyTime').innerHTML = 'Last Modified '
  75. + '<span id="panel-' + keyName + '-modifyTimestamp">' + data['data']['modifyTime'] + '</span>';
  76. PWM_MAIN.TimestampHandler.initElement(PWM_MAIN.getObject('panel-' + keyName + '-modifyTimestamp'));
  77. } else {
  78. PWM_MAIN.getObject('panel-' + keyName + '-modifyTime').innerHTML = '';
  79. }
  80. }
  81. if (PWM_MAIN.getObject('panel-' + keyName + '-modifyUser')) {
  82. if (data['data']['modifyUser']) {
  83. var output = 'Modified by ' + data['data']['modifyUser']['userDN'];
  84. if (data['data']['modifyUser']['ldapProfile'] && data['data']['modifyUser']['ldapProfile'] != "default") {
  85. output += ' [' + data['data']['modifyUser']['ldapProfile'] + ']';
  86. }
  87. PWM_MAIN.getObject('panel-' + keyName + '-modifyUser').innerHTML = output;
  88. } else {
  89. PWM_MAIN.getObject('panel-' + keyName + '-modifyUser').innerHTML = '';
  90. }
  91. }
  92. };
  93. PWM_CFGEDIT.writeSetting = function(keyName, valueData, nextAction) {
  94. PWM_VAR['outstandingOperations']++;
  95. PWM_CFGEDIT.handleWorkingIcon();
  96. var url = "editor?processAction=writeSetting&key=" + keyName;
  97. if (PWM_CFGEDIT.readCurrentProfile()) {
  98. url = PWM_MAIN.addParamToUrl(url,'profile',PWM_CFGEDIT.readCurrentProfile());
  99. }
  100. var loadFunction = function(data) {
  101. PWM_VAR['outstandingOperations']--;
  102. PWM_CFGEDIT.handleWorkingIcon();
  103. console.log('wrote data for setting ' + keyName);
  104. var isDefault = data['data']['isDefault'];
  105. PWM_CFGEDIT.updateSettingDisplay(keyName, isDefault);
  106. if (data['errorMessage']) {
  107. PWM_MAIN.showError(data['data']['errorMessage']);
  108. } else {
  109. PWM_MAIN.clearError();
  110. }
  111. if (nextAction !== undefined) {
  112. nextAction();
  113. }
  114. };
  115. var errorFunction = function(error) {
  116. PWM_VAR['outstandingOperations']--;
  117. PWM_CFGEDIT.handleWorkingIcon();
  118. PWM_MAIN.showDialog({title:PWM_MAIN.showString('Title_Error'),text:"Unable to communicate with server. Please refresh page."});
  119. console.log("error writing setting " + keyName + ", reason: " + error)
  120. };
  121. PWM_MAIN.ajaxRequest(url,loadFunction,{errorFunction:errorFunction,content:valueData});
  122. };
  123. PWM_CFGEDIT.resetSetting=function(keyName, nextAction) {
  124. var url = "editor?processAction=resetSetting&key=" + keyName;
  125. if (PWM_CFGEDIT.readCurrentProfile()) {
  126. url = PWM_MAIN.addParamToUrl(url,'profile',PWM_CFGEDIT.readCurrentProfile());
  127. }
  128. var loadFunction = function() {
  129. console.log('reset data for ' + keyName);
  130. if (nextAction !== undefined) {
  131. nextAction();
  132. }
  133. };
  134. PWM_MAIN.ajaxRequest(url,loadFunction);
  135. };
  136. PWM_CFGEDIT.handleWorkingIcon = function() {
  137. var iconElement = PWM_MAIN.getObject('working_icon');
  138. if (iconElement) {
  139. if (PWM_VAR['outstandingOperations'] > 0) {
  140. iconElement.style.visibility = 'visible';
  141. } else {
  142. iconElement.style.visibility = 'hidden';
  143. }
  144. }
  145. };
  146. PWM_CFGEDIT.updateSettingDisplay = function(keyName, isDefault) {
  147. require(["dojo"],function(dojo){
  148. var resetImageButton = PWM_MAIN.getObject('resetButton-' + keyName);
  149. var modifiedIcon = PWM_MAIN.getObject('modifiedNoticeIcon-' + keyName);
  150. var settingSyntax = '';
  151. try {
  152. settingSyntax = PWM_SETTINGS['settings'][keyName]['syntax'];
  153. } catch (e) { /* noop */ } //setting keys may not be loaded
  154. if (PWM_MAIN.JSLibrary.arrayContains(PWM_SETTINGS['settings'][keyName]['flags'],'NoDefault')) {
  155. isDefault = true;
  156. }
  157. if (!isDefault) {
  158. resetImageButton.style.visibility = 'visible';
  159. modifiedIcon.style.display = 'inline';
  160. try {
  161. dojo.addClass('title_' + keyName,"modified");
  162. dojo.addClass('titlePane_' + keyName,"modified");
  163. } catch (e) { /* noop */ }
  164. } else {
  165. resetImageButton.style.visibility = 'hidden';
  166. modifiedIcon.style.display = 'none';
  167. try {
  168. dojo.removeClass('title_' + keyName,"modified");
  169. dojo.removeClass('titlePane_' + keyName,"modified");
  170. } catch (e) { /* noop */ }
  171. }
  172. });
  173. };
  174. PWM_CFGEDIT.getSettingValueElement = function(settingKey) {
  175. var parentDiv = 'table_setting_' + settingKey;
  176. return PWM_MAIN.getObject(parentDiv);
  177. };
  178. PWM_CFGEDIT.clearDivElements = function(parentDiv) {
  179. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  180. if (parentDivElement != null) {
  181. if (parentDivElement.hasChildNodes()) {
  182. while (parentDivElement.childNodes.length >= 1) {
  183. var firstChild = parentDivElement.firstChild;
  184. parentDivElement.removeChild(firstChild);
  185. }
  186. }
  187. }
  188. };
  189. PWM_CFGEDIT.addValueButtonRow = function(parentDiv, keyName, addFunction) {
  190. var buttonId = keyName + '-addValueButton';
  191. var newTableRow = document.createElement("tr");
  192. newTableRow.setAttribute("style", "border-width: 0");
  193. newTableRow.setAttribute("colspan", "5");
  194. var newTableData = document.createElement("td");
  195. newTableData.setAttribute("style", "border-width: 0;");
  196. var addItemButton = document.createElement("button");
  197. addItemButton.setAttribute("type", "button");
  198. addItemButton.setAttribute("id", buttonId);
  199. addItemButton.setAttribute("class", "btn");
  200. addItemButton.onclick = addFunction;
  201. addItemButton.innerHTML = "Add Value";
  202. newTableData.appendChild(addItemButton);
  203. var parentDivElement = PWM_MAIN.getObject(parentDiv);
  204. parentDivElement.appendChild(newTableRow);
  205. newTableRow.appendChild(newTableData);
  206. };
  207. PWM_CFGEDIT.readInitialTextBasedValue = function(key) {
  208. require(["dijit/registry"],function(registry){
  209. PWM_CFGEDIT.readSetting(key, function(dataValue) {
  210. PWM_MAIN.getObject('value_' + key).value = dataValue;
  211. PWM_MAIN.getObject('value_' + key).disabled = false;
  212. registry.byId('value_' + key).set('disabled', false);
  213. registry.byId('value_' + key).startup();
  214. try {registry.byId('value_' + key).validate(false);} catch (e) {}
  215. try {registry.byId('value_verify_' + key).validate(false);} catch (e) {}
  216. });
  217. });
  218. };
  219. PWM_CFGEDIT.saveConfiguration = function() {
  220. PWM_VAR['cancelHeartbeatCheck'] = true;
  221. PWM_MAIN.preloadAll(function(){
  222. var confirmText = PWM_CONFIG.showString('MenuDisplay_SaveConfig');
  223. var confirmFunction = function(){
  224. var url = "editor?processAction=finishEditing";
  225. var loadFunction = function(data) {
  226. if (data['error'] == true) {
  227. PWM_MAIN.showErrorDialog(data);
  228. } else {
  229. console.log('save completed');
  230. PWM_MAIN.showWaitDialog({title:'Save complete, restarting application...',loadFunction:function(){
  231. PWM_CONFIG.waitForRestart({location:'/'});
  232. }});
  233. }
  234. };
  235. PWM_MAIN.showWaitDialog({title:'Saving...',loadFunction:function(){
  236. PWM_MAIN.ajaxRequest(url,loadFunction);
  237. }});
  238. };
  239. PWM_CFGEDIT.showChangeLog(confirmText,confirmFunction);
  240. });
  241. };
  242. PWM_CFGEDIT.setConfigurationPassword = function(password) {
  243. if (password) {
  244. var url = "editor?processAction=setConfigurationPassword";
  245. var loadFunction = function(data) {
  246. if (data['error']) {
  247. PWM_MAIN.closeWaitDialog();
  248. PWM_MAIN.showDialog({title: PWM_MAIN.showString('Title_Error'), text: data['errorMessage']});
  249. } else {
  250. PWM_MAIN.closeWaitDialog();
  251. PWM_MAIN.showDialog({title: PWM_MAIN.showString('Title_Success'), text: data['successMessage']});
  252. }
  253. };
  254. var errorFunction = function(errorObj) {
  255. PWM_MAIN.closeWaitDialog();
  256. PWM_MAIN.showDialog ({title:PWM_MAIN.showString('Title_Error'),text:"error saving configuration password: " + errorObj});
  257. };
  258. PWM_MAIN.clearDijitWidget('dialogPopup');
  259. PWM_MAIN.showWaitDialog({loadFunction:function(){
  260. PWM_MAIN.ajaxRequest(url,loadFunction,{errorFunction:errorFunction,content:{password:password}});
  261. }});
  262. return;
  263. }
  264. var writeFunction = function(passwordValue) {
  265. PWM_CFGEDIT.setConfigurationPassword(passwordValue);
  266. };
  267. ChangePasswordHandler.popup('configPw','Configuration Password',writeFunction);
  268. };
  269. function handleResetClick(settingKey) {
  270. var label = PWM_SETTINGS['settings'][settingKey] ? PWM_SETTINGS['settings'][settingKey]['label'] : ' ';
  271. var dialogText = PWM_CONFIG.showString('Warning_ResetSetting',{value1:label});
  272. var titleText = 'Reset ' + label ? label : '';
  273. PWM_MAIN.showConfirmDialog({title:titleText,text:dialogText,okAction:function(){
  274. PWM_CFGEDIT.resetSetting(settingKey,function(){
  275. PWM_CFGEDIT.loadMainPageBody();
  276. });
  277. }});
  278. }
  279. PWM_CFGEDIT.initConfigEditor = function(nextFunction) {
  280. PWM_MAIN.addEventHandler('homeSettingSearch',['input','focus'],function(){PWM_CFGEDIT.processSettingSearch(PWM_MAIN.getObject('searchResults'));});
  281. PWM_MAIN.addEventHandler('button-navigationExpandAll','click',function(){PWM_VAR['navigationTree'].expandAll()});
  282. PWM_MAIN.addEventHandler('button-navigationCollapseAll','click',function(){PWM_VAR['navigationTree'].collapseAll()});
  283. PWM_MAIN.addEventHandler('cancelButton_icon','click',function(){PWM_CFGEDIT.cancelEditing()});
  284. PWM_MAIN.addEventHandler('saveButton_icon','click',function(){PWM_CFGEDIT.saveConfiguration()});
  285. PWM_MAIN.addEventHandler('setPassword_icon','click',function(){PWM_CFGEDIT.setConfigurationPassword()});
  286. PWM_MAIN.addEventHandler('referenceDoc_icon','click',function(){
  287. PWM_MAIN.newWindowOpen(PWM_GLOBAL['url-context'] + '/public/reference/','referencedoc');
  288. });
  289. PWM_MAIN.addEventHandler('macroDoc_icon','click',function(){ PWM_CFGEDIT.showMacroHelp(); });
  290. PWM_MAIN.addEventHandler('settingFilter_icon','click',function(){ PWM_CFGEDIT.showSettingFilter(); });
  291. PWM_MAIN.addEventHandler('button-closeMenu','click',function(){
  292. PWM_CFGEDIT.closeMenuPanel();
  293. });
  294. PWM_MAIN.addEventHandler('button-openMenu','click',function(){
  295. PWM_CFGEDIT.openMenuPanel();
  296. });
  297. PWM_CONFIG.heartbeatCheck();
  298. PWM_CFGEDIT.loadMainPageBody();
  299. console.log('completed initConfigEditor');
  300. if (nextFunction) {
  301. nextFunction();
  302. }
  303. };
  304. PWM_CFGEDIT.executeSettingFunction = function (setting, name, resultHandler, extraData) {
  305. var jsonSendData = {};
  306. jsonSendData['setting'] = setting;
  307. jsonSendData['function'] = name;
  308. jsonSendData['extraData'] = extraData;
  309. resultHandler = resultHandler !== undefined ? resultHandler : function(data) {
  310. var msgBody = '<div style="max-height: 400px; overflow-y: auto">' + data['successMessage'] + '</div>';
  311. PWM_MAIN.showDialog({width:700,title: 'Results', text: msgBody, okAction: function () {
  312. PWM_CFGEDIT.loadMainPageBody();
  313. }});
  314. };
  315. var requestUrl = "editor?processAction=executeSettingFunction";
  316. if (PWM_CFGEDIT.readCurrentProfile()) {
  317. requestUrl = PWM_MAIN.addParamToUrl(requestUrl,'profile',PWM_CFGEDIT.readCurrentProfile());
  318. }
  319. PWM_MAIN.showWaitDialog({loadFunction:function() {
  320. var loadFunction = function(data) {
  321. if (data['error']) {
  322. PWM_MAIN.showErrorDialog(data);
  323. } else {
  324. resultHandler(data);
  325. }
  326. };
  327. PWM_MAIN.ajaxRequest(requestUrl, loadFunction, {content:jsonSendData});
  328. }});
  329. };
  330. PWM_CFGEDIT.showChangeLog=function(confirmText, confirmFunction) {
  331. var url = "editor?processAction=readChangeLog";
  332. var loadFunction = function(data) {
  333. PWM_MAIN.closeWaitDialog();
  334. if (data['error']) {
  335. PWM_MAIN.showDialog({title: PWM_MAIN.showString("Title_Error"), text: data['errorMessage']});
  336. } else {
  337. var bodyText = '<div class="changeLogViewBox">';
  338. bodyText += data['data']['html'];
  339. bodyText += '</div>';
  340. if (confirmText != undefined) {
  341. bodyText += '<br/><div>' + confirmText + '</div>';
  342. }
  343. if (confirmFunction == undefined) {
  344. PWM_MAIN.showDialog({title: "Unsaved Configuration Editor Changes", text: bodyText, dialogClass:'wide', showClose: true});
  345. } else {
  346. PWM_MAIN.showConfirmDialog({title: "Unsaved Configuration Editor Changes", text: bodyText, dialogClass:'wide', showClose: true, okAction:confirmFunction});
  347. }
  348. }
  349. };
  350. PWM_MAIN.showWaitDialog({loadFunction: function () {
  351. PWM_MAIN.ajaxRequest(url, loadFunction);
  352. }});
  353. };
  354. PWM_CFGEDIT.processSettingSearch = function(destinationDiv) {
  355. var iteration = 'settingSearchIteration' in PWM_VAR ? PWM_VAR['settingSearchIteration'] + 1 : 0;
  356. var startTime = new Date().getTime();
  357. PWM_VAR['settingSearchIteration'] = iteration;
  358. var resetDisplay = function() {
  359. PWM_MAIN.getObject('indicator-noResults').style.display = 'none';
  360. PWM_MAIN.getObject('indicator-searching').style.display = 'none';
  361. destinationDiv.style.visibility = 'hidden';
  362. destinationDiv.innerHTML = '';
  363. };
  364. var readSearchTerm = function() {
  365. if (!PWM_MAIN.getObject('homeSettingSearch') || !PWM_MAIN.getObject('homeSettingSearch') || PWM_MAIN.getObject('homeSettingSearch').value.length < 1) {
  366. return null;
  367. }
  368. return PWM_MAIN.getObject('homeSettingSearch').value;
  369. };
  370. console.log('beginning search #' + iteration);
  371. var url = "editor?processAction=search";
  372. var loadFunction = function(data) {
  373. resetDisplay();
  374. if (!readSearchTerm()) {
  375. resetDisplay();
  376. return;
  377. }
  378. if (!data) {
  379. console.log('search #' + iteration + ", no data returned");
  380. return;
  381. }
  382. if (data['error']) {
  383. console.log('search #' + iteration + ", error returned: " + data);
  384. PWM_MAIN.showErrorDialog(data);
  385. } else {
  386. var bodyText = '';
  387. var resultCount = 0;
  388. var elapsedTime = (new Date().getTime()) - startTime;
  389. if (PWM_MAIN.JSLibrary.isEmpty(data['data'])) {
  390. PWM_MAIN.getObject('indicator-noResults').style.display = 'inline';
  391. console.log('search #' + iteration + ', 0 results, ' + elapsedTime + 'ms');
  392. } else {
  393. for (var categoryIter in data['data']) {
  394. var category = data['data'][categoryIter];
  395. bodyText += '<div class="panel-searchResultCategory">' + categoryIter + '</div>';
  396. for (var settingIter in category) {
  397. var setting = category[settingIter];
  398. var profileID = setting['profile'];
  399. var linkID = 'link-' + setting['category'] + '-' + settingIter + (profileID ? profileID : '');
  400. var settingID = "search_" + (profileID ? profileID + '_' : '') + settingIter;
  401. bodyText += '<div><span id="' + linkID + '" class="panel-searchResultItem">';
  402. bodyText += PWM_SETTINGS['settings'][settingIter]['label'];
  403. bodyText += '</span>&nbsp;<span id="' + settingID + '_popup" class="btn-icon pwm-icon pwm-icon-info-circle"></span>';
  404. if (!setting['default']) {
  405. bodyText += '<span class="pwm-icon pwm-icon-pencil-square modifiedNoticeIcon" title="' + PWM_CONFIG.showString('Tooltip_ModifiedNotice') + '">&nbsp;</span>';
  406. }
  407. bodyText += '</div>';
  408. resultCount++;
  409. }
  410. }
  411. console.log('search #' + iteration + ', ' + resultCount + ' results, ' + elapsedTime + 'ms');
  412. destinationDiv.style.visibility = 'visible';
  413. destinationDiv.innerHTML = bodyText;
  414. for (var categoryIter in data['data']) {
  415. var category = data['data'][categoryIter];
  416. for (var iter in category) {
  417. (function (settingKey) {
  418. var setting = category[settingKey];
  419. var profileID = setting['profile'];
  420. var settingID = "search_" + (profileID ? profileID + '_' : '') + settingKey;
  421. var value = setting['value'];
  422. var toolBody = '<span style="font-weight: bold">Setting</span>';
  423. toolBody += '<br/>' + PWM_SETTINGS['settings'][settingKey]['label'] + '<br/><br/>';
  424. toolBody += '<span style="font-weight: bold">Description</span>';
  425. toolBody += '<br/>' + PWM_SETTINGS['settings'][settingKey]['description'] + '<br/><br/>';
  426. toolBody += '<span style="font-weight: bold">Value</span>';
  427. toolBody += '<br/>' + value.replace('\n', '<br/>') + '<br/>';
  428. PWM_MAIN.showDijitTooltip({
  429. id: settingID + '_popup',
  430. text: toolBody,
  431. width: 500
  432. });
  433. var linkID = 'link-' + setting['category'] + '-' + settingKey + (profileID ? profileID : '');
  434. PWM_MAIN.addEventHandler(linkID ,'click',function(){
  435. resetDisplay();
  436. PWM_CFGEDIT.gotoSetting(setting['category'],settingKey,profileID);
  437. });
  438. }(iter));
  439. }
  440. }
  441. }
  442. }
  443. };
  444. var validationProps = {};
  445. validationProps['serviceURL'] = url;
  446. validationProps['readDataFunction'] = function(){
  447. resetDisplay();
  448. PWM_MAIN.getObject('indicator-searching').style.display = 'inline';
  449. var value = readSearchTerm();
  450. return {search:value,key:value};
  451. };
  452. validationProps['completeFunction'] = function() {
  453. PWM_MAIN.getObject('indicator-searching').style.display = 'none';
  454. };
  455. validationProps['processResultsFunction'] = loadFunction;
  456. PWM_MAIN.pwmFormValidator(validationProps);
  457. };
  458. PWM_CFGEDIT.gotoSetting = function(category,settingKey,profile) {
  459. console.log('going to setting... category=' + category + " settingKey=" + settingKey + " profile=" + profile);
  460. if (!category) {
  461. if (settingKey) {
  462. var settingInfo = PWM_SETTINGS['settings'][settingKey];
  463. if (settingInfo) {
  464. category = settingInfo['category'];
  465. }
  466. }
  467. }
  468. if (!settingKey && !category) {
  469. alert('unable to goto setting: settingKey and category parameter are not specified');
  470. return;
  471. }
  472. if (settingKey && !(settingKey in PWM_SETTINGS['settings'])) {
  473. alert('unable to goto setting: settingKey parameter "' + settingKey + '" is not valid');
  474. return;
  475. }
  476. if (!(category in PWM_SETTINGS['categories'])) {
  477. alert('unable to goto setting: category parameter "' + category + '" is not valid');
  478. return;
  479. }
  480. PWM_CFGEDIT.setCurrentProfile(profile);
  481. PWM_CFGEDIT.displaySettingsCategory(category);
  482. if (PWM_SETTINGS['categories'][category]['label']) {
  483. PWM_MAIN.getObject('currentPageDisplay').innerHTML = ' - ' + PWM_SETTINGS['categories'][category]['label'];
  484. }
  485. var item = {};
  486. item['id'] = category;
  487. item['type'] = 'category';
  488. if (settingKey) {
  489. setTimeout(function(){
  490. var settingElement = PWM_CFGEDIT.getSettingValueElement(settingKey);
  491. console.log('navigating and highlighting setting ' + settingKey);
  492. //location.href = "#setting-" + settingKey;
  493. settingElement.scrollIntoView(true);
  494. if (settingElement.getBoundingClientRect().top < 100) {
  495. window.scrollBy(0, -100);
  496. }
  497. PWM_MAIN.flashDomElement('red','title_' + settingKey, 5000);
  498. },1000);
  499. }
  500. };
  501. PWM_CFGEDIT.cancelEditing = function() {
  502. var url = "editor?processAction=readChangeLog";
  503. PWM_MAIN.showWaitDialog({loadFunction:function(){
  504. var loadFunction = function(data) {
  505. if (data['error']) {
  506. PWM_MAIN.showDialog({title: PWM_MAIN.showString("Title_Error"), text: data['errorMessage']});
  507. } else {
  508. if (data['data']['modified'] == true) {
  509. var bodyText = '<div class="changeLogViewBox">';
  510. bodyText += data['data']['html'];
  511. bodyText += '</div><br/><div>';
  512. bodyText += PWM_CONFIG.showString('MenuDisplay_CancelConfig');
  513. bodyText += '</div>';
  514. PWM_MAIN.closeWaitDialog();
  515. PWM_MAIN.showConfirmDialog({dialogClass:'wide',showClose:true,allowMove:true,text:bodyText,okAction:
  516. function () {
  517. PWM_MAIN.showWaitDialog({loadFunction: function () {
  518. PWM_MAIN.ajaxRequest('editor?processAction=cancelEditing',function(){
  519. PWM_MAIN.goto('manager', {addFormID: true});
  520. });
  521. }});
  522. }
  523. });
  524. } else {
  525. PWM_MAIN.goto('manager', {addFormID: true});
  526. }
  527. }
  528. };
  529. PWM_MAIN.ajaxRequest(url, loadFunction);
  530. }});
  531. };
  532. PWM_CFGEDIT.showMacroHelp = function() {
  533. require(["dijit/Dialog"],function(Dialog) {
  534. var idName = 'macroPopup';
  535. PWM_MAIN.clearDijitWidget(idName);
  536. var theDialog = new Dialog({
  537. id: idName,
  538. title: 'Macro Help',
  539. style: "width: 750px",
  540. href: PWM_GLOBAL['url-resources'] + "/text/macroHelp.html"
  541. });
  542. var attempts = 0;
  543. // iframe takes indeterminate amount of time to load, so just retry till it apperas
  544. var loadFunction = function() {
  545. if (PWM_MAIN.getObject('input-testMacroInput')) {
  546. console.log('connected to macroHelpDiv');
  547. setTimeout(function(){
  548. PWM_MAIN.getObject('input-testMacroInput').focus();
  549. },500);
  550. PWM_MAIN.addEventHandler('button-testMacro','click',function(){
  551. PWM_MAIN.getObject('panel-testMacroOutput').innerHTML = PWM_MAIN.showString('Display_PleaseWait');
  552. var sendData = {};
  553. sendData['input'] = PWM_MAIN.getObject('input-testMacroInput').value;
  554. var url = "editor?processAction=testMacro";
  555. var loadFunction = function(data) {
  556. PWM_MAIN.getObject('panel-testMacroOutput').innerHTML = data['data'];
  557. };
  558. PWM_MAIN.ajaxRequest(url,loadFunction,{content:sendData});
  559. });
  560. } else {
  561. if (attempts < 50) {
  562. attempts++;
  563. setTimeout(loadFunction,100);
  564. }
  565. }
  566. };
  567. theDialog.show();
  568. loadFunction();
  569. });
  570. };
  571. PWM_CFGEDIT.showTimezoneList = function() {
  572. require(["dijit/Dialog"],function(Dialog) {
  573. var idName = 'timezonePopup';
  574. PWM_MAIN.clearDijitWidget(idName);
  575. var theDialog = new Dialog({
  576. id: idName,
  577. title: 'Timezones',
  578. style: "width: 750px",
  579. href: PWM_GLOBAL['url-context'] + "/public/reference/timezones.jsp"
  580. });
  581. theDialog.show();
  582. });
  583. };
  584. PWM_CFGEDIT.showDateTimeFormatHelp = function() {
  585. require(["dijit/Dialog"],function(Dialog) {
  586. var idName = 'dateTimePopup';
  587. PWM_MAIN.clearDijitWidget(idName);
  588. var theDialog = new Dialog({
  589. id: idName,
  590. title: 'Macro Help',
  591. style: "width: 700px",
  592. href: PWM_GLOBAL['url-resources'] + "/text/datetimeFormatHelp.html"
  593. });
  594. theDialog.show();
  595. });
  596. };
  597. PWM_CFGEDIT.ldapHealthCheck = function() {
  598. PWM_MAIN.showWaitDialog({loadFunction:function() {
  599. var url = "editor?processAction=ldapHealthCheck";
  600. url = PWM_MAIN.addParamToUrl(url,'profile',PWM_CFGEDIT.readCurrentProfile());
  601. var loadFunction = function(data) {
  602. PWM_MAIN.closeWaitDialog();
  603. if (data['error']) {
  604. PWM_MAIN.showDialog({title: PWM_MAIN.showString("Title_Error"), text: data['errorMessage']});
  605. } else {
  606. var bodyText = PWM_ADMIN.makeHealthHtml(data['data'],false,false);
  607. var profileName = PWM_CFGEDIT.readCurrentProfile();
  608. var titleText = PWM_MAIN.showString('Field_LdapProfile') + ": " + profileName;
  609. PWM_MAIN.showDialog({text:bodyText,title:titleText});
  610. }
  611. };
  612. PWM_MAIN.ajaxRequest(url,loadFunction);
  613. }});
  614. };
  615. PWM_CFGEDIT.databaseHealthCheck = function() {
  616. PWM_MAIN.showWaitDialog({title:'Checking database connection...',loadFunction:function(){
  617. var url = "editor?processAction=databaseHealthCheck";
  618. var loadFunction = function(data) {
  619. PWM_MAIN.closeWaitDialog();
  620. if (data['error']) {
  621. PWM_MAIN.showDialog({title: PWM_MAIN.showString("Title_Error"), text: data['errorMessage']});
  622. } else {
  623. var bodyText = PWM_ADMIN.makeHealthHtml(data['data'],false,false);
  624. var titleText = 'Database Connection Status';
  625. PWM_MAIN.showDialog({text:bodyText,title:titleText});
  626. }
  627. };
  628. PWM_MAIN.ajaxRequest(url,loadFunction);
  629. }});
  630. };
  631. PWM_CFGEDIT.httpsCertificateView = function() {
  632. PWM_MAIN.showWaitDialog({title:'Parsing...',loadFunction:function(){
  633. var url = "editor?processAction=httpsCertificateView";
  634. var loadFunction = function(data) {
  635. PWM_MAIN.closeWaitDialog();
  636. if (data['error']) {
  637. PWM_MAIN.showErrorDialog(data);
  638. } else {
  639. var bodyText = '<pre>' + data['data'] + '</pre>';
  640. var titleText = 'HTTPS Certificate';
  641. PWM_MAIN.showDialog({text:bodyText,title:titleText});
  642. }
  643. };
  644. PWM_MAIN.ajaxRequest(url,loadFunction);
  645. }});
  646. };
  647. PWM_CFGEDIT.smsHealthCheck = function() {
  648. require(["dojo/dom-form"], function(domForm){
  649. var dialogBody = '<p>' + PWM_CONFIG.showString('Warning_SmsTestData') + '</p><form id="smsCheckParametersForm"><table>';
  650. dialogBody += '<tr><td>To</td><td><input name="to" type="text" value="555-1212"/></td></tr>';
  651. dialogBody += '<tr><td>Message</td><td><input name="message" type="text" value="Test Message"/></td></tr>';
  652. dialogBody += '</table></form>';
  653. PWM_MAIN.showDialog({text:dialogBody,showCancel:true,title:'Test SMS connection',closeOnOk:false,okAction:function(){
  654. var formElement = PWM_MAIN.getObject("smsCheckParametersForm");
  655. var formData = domForm.toObject(formElement);
  656. var url = "editor?processAction=smsHealthCheck";
  657. PWM_MAIN.showWaitDialog({loadFunction:function(){
  658. var loadFunction = function(data) {
  659. if (data['error']) {
  660. PWM_MAIN.showErrorDialog(data);
  661. } else {
  662. var bodyText = PWM_ADMIN.makeHealthHtml(data['data'],false,false);
  663. var titleText = 'SMS Send Message Status';
  664. PWM_MAIN.showDialog({text:bodyText,title:titleText,showCancel:true});
  665. }
  666. };
  667. PWM_MAIN.ajaxRequest(url,loadFunction,{content:formData});
  668. }});
  669. }});
  670. });
  671. };
  672. PWM_CFGEDIT.selectTemplate = function(newTemplate) {
  673. PWM_MAIN.showConfirmDialog({
  674. text: PWM_CONFIG.showString('Warning_ChangeTemplate'),
  675. okAction: function () {
  676. PWM_MAIN.showWaitDialog({loadFunction: function () {
  677. var url = "editor?processAction=setOption&template=" + newTemplate;
  678. PWM_MAIN.ajaxRequest(url, function(){ PWM_MAIN.goto('editor'); });
  679. }});
  680. }
  681. });
  682. };
  683. PWM_CFGEDIT.loadMainPageBody = function() {
  684. PWM_CFGEDIT.drawNavigationMenu();
  685. var lastSelected = PWM_MAIN.Preferences.readSessionStorage('configEditor-lastSelected',null);
  686. if (lastSelected) {
  687. PWM_CFGEDIT.dispatchNavigationItem(lastSelected);
  688. } else {
  689. PWM_CFGEDIT.dispatchNavigationItem({id:'TEMPLATES',type:'category'});
  690. }
  691. require(["dojo/io-query"],function(ioQuery){
  692. var uri = window.location.href;
  693. var queryString = uri.substring(uri.indexOf("?") + 1, uri.length);
  694. var queryParams = ioQuery.queryToObject(queryString);
  695. if (queryParams['processAction'] == 'gotoSetting') {
  696. PWM_CFGEDIT.gotoSetting(queryParams['category'],queryParams['settingKey'],queryParams['profile']);
  697. return;
  698. }
  699. });
  700. };
  701. PWM_CFGEDIT.displaySettingsCategory = function(category) {
  702. var settingsPanel = PWM_MAIN.getObject('settingsPanel');
  703. settingsPanel.innerHTML = '';
  704. console.log('loadingSettingsCategory: ' + category);
  705. if (!category) {
  706. settingsPanel.innerHTML = '';
  707. console.log('no selected category');
  708. return;
  709. }
  710. var htmlSettingBody = '';
  711. /*
  712. htmlSettingBody += '<button id="button-expandAllHelp">Awesome</button>';
  713. PWM_MAIN.addEventHandler('button-expandAllHelp','click',function(){
  714. PWM_MAIN.doQuery('.pane-help',function(element){
  715. console.log('hit!' );
  716. });
  717. });
  718. */
  719. if (category == 'LDAP_PROFILE') {
  720. htmlSettingBody += '<div style="width: 100%; text-align: center">'
  721. + '<button class="btn" id="button-test-LDAP_PROFILE"><span class="btn-icon pwm-icon pwm-icon-bolt"></span>Test LDAP Profile</button>'
  722. + '</div>';
  723. } else if (category == 'DATABASE_SETTINGS') {
  724. htmlSettingBody += '<div style="width: 100%; text-align: center">'
  725. + '<button class="btn" id="button-test-DATABASE_SETTINGS"><span class="btn-icon pwm-icon pwm-icon-bolt"></span>Test Database Connection</button>'
  726. + '</div>';
  727. } else if (category == 'SMS_GATEWAY') {
  728. htmlSettingBody += '<div style="width: 100%; text-align: center">'
  729. + '<button class="btn" id="button-test-SMS"><span class="btn-icon pwm-icon pwm-icon-bolt"></span>Test SMS Settings</button>'
  730. + '</div>';
  731. }
  732. PWM_VAR['skippedSettingCount'] = 0;
  733. for (var loopSetting in PWM_SETTINGS['settings']) {
  734. (function(settingKey) {
  735. var settingInfo = PWM_SETTINGS['settings'][settingKey];
  736. if (settingInfo['category'] == category && !settingInfo['hidden']) {
  737. htmlSettingBody += PWM_CFGEDIT.drawHtmlOutlineForSetting(settingInfo);
  738. }
  739. })(loopSetting);
  740. }
  741. htmlSettingBody += '<div class="footnote" id="panel-skippedSettingInfo">';
  742. settingsPanel.innerHTML = htmlSettingBody;
  743. for (var loopSetting in PWM_SETTINGS['settings']) {
  744. (function(settingKey) {
  745. var settingInfo = PWM_SETTINGS['settings'][settingKey];
  746. if (settingInfo['category'] == category && !settingInfo['hidden']) {
  747. PWM_CFGEDIT.initSettingDisplay(settingInfo);
  748. }
  749. })(loopSetting);
  750. }
  751. if (category == 'LDAP_PROFILE') {
  752. PWM_MAIN.addEventHandler('button-test-LDAP_PROFILE', 'click', function(){PWM_CFGEDIT.ldapHealthCheck();});
  753. } else if (category == 'DATABASE_SETTINGS') {
  754. PWM_MAIN.addEventHandler('button-test-DATABASE_SETTINGS', 'click', function(){PWM_CFGEDIT.databaseHealthCheck();});
  755. } else if (category == 'SMS_GATEWAY') {
  756. PWM_MAIN.addEventHandler('button-test-SMS', 'click', function(){PWM_CFGEDIT.smsHealthCheck();});
  757. } else if (category == 'HTTPS_SERVER') {
  758. PWM_MAIN.addEventHandler('button-test-HTTPS_SERVER', 'click', function(){PWM_CFGEDIT.httpsCertificateView();});
  759. }
  760. PWM_CFGEDIT.applyGotoSettingHandlers();
  761. };
  762. PWM_CFGEDIT.drawProfileEditorPage = function(settingKey) {
  763. var settingsPanel = PWM_MAIN.getObject('settingsPanel');
  764. settingsPanel.innerHTML = '';
  765. var settingInfo = PWM_SETTINGS['settings'][settingKey];
  766. console.log('drawing profile-editor for setting-' + settingKey);
  767. settingsPanel.innerHTML = PWM_CFGEDIT.drawHtmlOutlineForSetting(settingInfo);
  768. PWM_CFGEDIT.initSettingDisplay(settingInfo);
  769. };
  770. PWM_CFGEDIT.drawHtmlOutlineForSetting = function(settingInfo, options) {
  771. options = options === undefined ? {} : options;
  772. var settingKey = settingInfo['key'];
  773. var settingLabel = settingInfo['label'];
  774. var htmlBody = '<div id="outline_' + settingKey + '" class="setting_outline" style="display:none">'
  775. + '<div class="setting_title" id="title_' + settingKey + '">'
  776. + '<a id="setting-' + settingKey + '" class="text">' + settingLabel + '</a>'
  777. + '<div class="pwm-icon pwm-icon-pencil-square modifiedNoticeIcon" title="' + PWM_CONFIG.showString('Tooltip_ModifiedNotice') + '" id="modifiedNoticeIcon-' + settingKey + '" style="display: none" ></div>';
  778. if (settingInfo['description']) {
  779. htmlBody += '<div class="pwm-icon pwm-icon-question-circle icon_button" title="' + PWM_CONFIG.showString('Tooltip_HelpButton') + '" id="helpButton-' + settingKey + '"></div>';
  780. }
  781. htmlBody += '<div style="visibility: hidden" class="pwm-icon pwm-icon-undo icon_button" title="' + PWM_CONFIG.showString('Tooltip_ResetButton') + '" id="resetButton-' + settingKey + '"></div>'
  782. + '</div>' // close title
  783. + '<div id="titlePane_' + settingKey + '" class="setting_body">';
  784. if (settingInfo['description']) {
  785. var prefs = PWM_MAIN.Preferences.readSessionStorage('helpExpanded',{});
  786. var expandHelp = settingKey in prefs;
  787. htmlBody += '<div class="pane-help" id="pane-help-' + settingKey + '" style="display:' + (expandHelp ? 'inherit' : 'none') + '">'
  788. + settingInfo['description'] + '</div>';
  789. }
  790. htmlBody += '<div class="pane-settingValue noborder" id="table_setting_' + settingKey + '">'
  791. + '</div>' // close setting;
  792. + '</div>' // close body
  793. + '<div class="footnote" style="width:100%"><span id="panel-' + settingKey + '-modifyTime"></span></div>'
  794. + '<div class="footnote" style="width:100%"><span id="panel-' + settingKey + '-modifyUser"></span></div>'
  795. + '</div>'; // close outline
  796. return htmlBody;
  797. };
  798. PWM_CFGEDIT.initSettingDisplay = function(setting, options) {
  799. var settingKey = setting['key'];
  800. options = options === undefined ? {} : options;
  801. PWM_MAIN.addEventHandler('helpButton-' + settingKey, 'click', function () {
  802. PWM_CFGEDIT.displaySettingHelp(settingKey);
  803. });
  804. PWM_MAIN.addEventHandler('setting-' + settingKey, 'click', function () {
  805. PWM_CFGEDIT.displaySettingHelp(settingKey);
  806. });
  807. PWM_MAIN.addEventHandler('resetButton-' + settingKey, 'click', function () {
  808. handleResetClick(settingKey);
  809. });
  810. switch (setting['syntax']) {
  811. case 'FORM':
  812. FormTableHandler.init(settingKey,{});
  813. break;
  814. case 'OPTIONLIST':
  815. OptionListHandler.init(settingKey);
  816. break;
  817. case 'EMAIL':
  818. EmailTableHandler.init(settingKey);
  819. break;
  820. case 'ACTION':
  821. ActionHandler.init(settingKey);
  822. break;
  823. case 'PASSWORD':
  824. ChangePasswordHandler.init(settingKey);
  825. break;
  826. case 'NUMERIC':
  827. NumericValueHandler.init(settingKey);
  828. break;
  829. case 'DURATION':
  830. DurationValueHandler.init(settingKey);
  831. break;
  832. case 'STRING':
  833. StringValueHandler.init(settingKey);
  834. break;
  835. case 'TEXT_AREA':
  836. TextAreaValueHandler.init(settingKey);
  837. break;
  838. case 'SELECT':
  839. SelectValueHandler.init(settingKey);
  840. break;
  841. case 'BOOLEAN':
  842. BooleanHandler.init(settingKey);
  843. break;
  844. case 'LOCALIZED_STRING_ARRAY':
  845. MultiLocaleTableHandler.initMultiLocaleTable(settingKey);
  846. break;
  847. case 'STRING_ARRAY':
  848. case 'PROFILE':
  849. StringArrayValueHandler.init(settingKey);
  850. break;
  851. case 'LOCALIZED_STRING':
  852. case 'LOCALIZED_TEXT_AREA':
  853. LocalizedStringValueHandler.init(settingKey);
  854. break;
  855. case 'USER_PERMISSION':
  856. UserPermissionHandler.init(settingKey);
  857. break;
  858. case 'CHALLENGE':
  859. ChallengeSettingHandler.init(settingKey);
  860. break;
  861. case 'X509CERT':
  862. X509CertificateHandler.init(settingKey);
  863. break;
  864. case 'PRIVATE_KEY':
  865. PrivateKeyHandler.init(settingKey);
  866. break;
  867. case 'FILE':
  868. FileValueHandler.init(settingKey);
  869. break;
  870. case 'VERIFICATION_METHOD':
  871. VerificationMethodHandler.init(settingKey);
  872. break;
  873. case 'NONE':
  874. break;
  875. default:
  876. alert('unknown setting syntax type: ' + setting['syntax']);
  877. }
  878. };
  879. PWM_CFGEDIT.drawNavigationMenu = function() {
  880. PWM_MAIN.getObject('navigationTree').innerHTML = '';
  881. PWM_MAIN.setStyle('navigationTreeWrapper','display','none');
  882. var detectFirstDisplay = function() {
  883. var ca = document.cookie.split(';');
  884. for(var i=0; i<ca.length; i++) {
  885. var c = ca[i];
  886. while (c.charAt(0)==' ') c = c.substring(1);
  887. if (c.indexOf('navigationTreeSaveStateCookie') != -1) {
  888. return false;
  889. }
  890. }
  891. return true;
  892. };
  893. var makeTreeFunction = function(menuTreeData) {
  894. require(["dojo/_base/window", "dojo/store/Memory", "dijit/tree/ObjectStoreModel", "dijit/Tree","dijit","dojo/domReady!"],
  895. function(win, Memory, ObjectStoreModel, Tree)
  896. {
  897. PWM_MAIN.clearDijitWidget('navigationTree');
  898. // Create test store, adding the getChildren() method required by ObjectStoreModel
  899. var myStore = new Memory({
  900. data: menuTreeData,
  901. getChildren: function(object){
  902. return this.query({parent: object.id});
  903. }
  904. });
  905. // Create the model
  906. var model = new ObjectStoreModel({
  907. store: myStore,
  908. query: {id: 'ROOT'}
  909. });
  910. var virginNavTree = detectFirstDisplay();
  911. // Create the Tree.
  912. var tree = new Tree({
  913. model: model,
  914. persist: true,
  915. getIconClass: function(/*dojo.store.Item*/ item, /*Boolean*/ opened){
  916. return 'tree-noicon';
  917. },
  918. showRoot: false,
  919. openOnClick: true,
  920. id: 'navigationTree',
  921. onClick: function(item){
  922. PWM_MAIN.Preferences.writeSessionStorage('configEditor-lastSelected',item);
  923. PWM_CFGEDIT.dispatchNavigationItem(item);
  924. }
  925. });
  926. if (virginNavTree) {
  927. console.log('first time nav menu loaded');
  928. tree.expandAll();
  929. setTimeout(function(){
  930. tree.collapseAll();
  931. },1000);
  932. } else {
  933. console.log('detected previous nav menu cookie');
  934. }
  935. PWM_MAIN.getObject('navigationTree').innerHTML = '';
  936. tree.placeAt(PWM_MAIN.getObject('navigationTree'));
  937. tree.startup();
  938. PWM_VAR['navigationTree'] = tree; // used for expand/collapse button events;
  939. PWM_MAIN.setStyle('navigationTreeWrapper','display','inherit');
  940. }
  941. );
  942. };
  943. var url = 'editor?processAction=menuTreeData';
  944. var filterParams = PWM_CFGEDIT.readNavigationFilters();
  945. PWM_MAIN.ajaxRequest(url,function(data){
  946. var menuTreeData = data['data'];
  947. makeTreeFunction(menuTreeData);
  948. },{content:filterParams});
  949. };
  950. PWM_CFGEDIT.readNavigationFilters = function() {
  951. var result = {};
  952. result['modifiedSettingsOnly'] = 'settingFilter_modifiedSettingsOnly' in PWM_VAR ? PWM_VAR['settingFilter_modifiedSettingsOnly'] : false;
  953. result['level'] = 'settingFilter_level' in PWM_VAR ? PWM_VAR['settingFilter_level'] : 2;
  954. result['text'] = 'settingFilter_text' in PWM_VAR ? PWM_VAR['settingFilter_text'] : '';
  955. return result;
  956. };
  957. PWM_CFGEDIT.dispatchNavigationItem = function(item) {
  958. var currentID = item['id'];
  959. var type = item['type'];
  960. if (type == 'navigation') {
  961. /* not used, nav tree set to auto-expand */
  962. } else if (type == 'category') {
  963. PWM_CFGEDIT.gotoSetting(currentID);
  964. } else if (type == 'displayText') {
  965. var keys = item['keys'];
  966. PWM_CFGEDIT.drawDisplayTextPage(currentID,keys);
  967. } else if (type == 'profile') {
  968. var category = item['category'];
  969. PWM_CFGEDIT.gotoSetting(category,null,currentID);
  970. } else if (type == 'profileDefinition') {
  971. var profileSettingKey = item['profileSetting'];
  972. PWM_CFGEDIT.drawProfileEditorPage(profileSettingKey);
  973. }
  974. if (item['name']) {
  975. PWM_MAIN.getObject('currentPageDisplay').innerHTML = ' - ' + item['name'];
  976. }
  977. };
  978. PWM_CFGEDIT.drawDisplayTextPage = function(settingKey, keys) {
  979. var settingsPanel = PWM_MAIN.getObject('settingsPanel');
  980. var remainingLoads = keys.length;
  981. settingsPanel.innerHTML = '<div id="displaytext-loading-panel" style="width:100%; text-align: center">'
  982. + PWM_MAIN.showString('Display_PleaseWait') + '&nbsp;<span id="remainingCount"></div>';
  983. console.log('drawing displaytext-editor for setting-' + settingKey);
  984. var htmlBody = '<div id="localetext-editor-wrapper" style="display:none">';
  985. for (var key in keys) {
  986. var displayKey = 'localeBundle-' + settingKey + '-' + keys[key];
  987. var settingInfo = {};
  988. settingInfo['key'] = displayKey;
  989. settingInfo['label'] = keys[key];
  990. htmlBody += PWM_CFGEDIT.drawHtmlOutlineForSetting(settingInfo,{showHelp:false});
  991. }
  992. settingsPanel.innerHTML = settingsPanel.innerHTML + htmlBody;
  993. var initSetting = function(keyCounter) {
  994. if (PWM_VAR['outstandingOperations'] > 5) {
  995. setTimeout(function () { initSetting(keyCounter); }, 50);
  996. return;
  997. }
  998. var displayKey = 'localeBundle-' + settingKey + '-' + keys[keyCounter];
  999. var settingInfo = {};
  1000. settingInfo['key'] = displayKey;
  1001. settingInfo['label'] = keys[keyCounter];
  1002. settingInfo['syntax'] = 'NONE';
  1003. PWM_CFGEDIT.initSettingDisplay(settingInfo);
  1004. LocalizedStringValueHandler.init(displayKey,{required:true});
  1005. remainingLoads--;
  1006. PWM_MAIN.getObject('remainingCount').innerHTML = remainingLoads > 0 ? remainingLoads : '';
  1007. };
  1008. var delay = 5;
  1009. for (var key in keys) {
  1010. (function(keyCounter) {
  1011. setTimeout(function(){
  1012. initSetting(keyCounter);
  1013. },delay);
  1014. delay = delay + 5;
  1015. })(key);
  1016. }
  1017. var checkForFinishFunction = function() {
  1018. console.log('checking for finish function...');
  1019. setTimeout(function(){
  1020. if (PWM_VAR['outstandingOperations'] == 0) {
  1021. PWM_MAIN.getObject('displaytext-loading-panel').style.display = 'none';
  1022. PWM_MAIN.getObject('localetext-editor-wrapper').style.display = 'inherit';
  1023. } else {
  1024. setTimeout(checkForFinishFunction,100);
  1025. }
  1026. },100);
  1027. };
  1028. checkForFinishFunction();
  1029. };
  1030. PWM_CFGEDIT.initConfigSettingsDefinition=function(nextFunction) {
  1031. var clientConfigUrl = PWM_GLOBAL['url-context'] + "/private/config/editor?processAction=settingData";
  1032. var loadFunction = function(data) {
  1033. if (data['error'] == true) {
  1034. console.error('unable to load ' + clientConfigUrl + ', error: ' + data['errorDetail'])
  1035. } else {
  1036. for (var settingKey in data['data']) {
  1037. PWM_SETTINGS[settingKey] = data['data'][settingKey];
  1038. }
  1039. }
  1040. console.log('loaded client-configsettings data');
  1041. if (nextFunction) nextFunction();
  1042. };
  1043. var errorFunction = function(error) {
  1044. var errorMsg = 'unable to read config settings app-data: ' + error;
  1045. console.log(errorMsg);
  1046. if (!PWM_VAR['initError']) PWM_VAR['initError'] = errorMsg;
  1047. if (nextFunction) nextFunction();
  1048. };
  1049. PWM_MAIN.ajaxRequest(clientConfigUrl, loadFunction, {method:'GET',errorFunction:errorFunction});
  1050. };
  1051. PWM_CFGEDIT.displaySettingHelp = function(settingKey) {
  1052. console.log('toggle help for ' + settingKey);
  1053. var helpExpandedPrefs = PWM_MAIN.Preferences.readSessionStorage('helpExpanded',{});
  1054. var element = PWM_MAIN.getObject('pane-help-' + settingKey);
  1055. if (element) {
  1056. if (element.style.display == 'none') {
  1057. element.style.display = 'inherit';
  1058. helpExpandedPrefs[settingKey] = true;
  1059. } else {
  1060. element.style.display = 'none';
  1061. delete helpExpandedPrefs[settingKey];
  1062. }
  1063. PWM_MAIN.Preferences.writeSessionStorage('helpExpanded',helpExpandedPrefs);
  1064. }
  1065. };
  1066. PWM_CFGEDIT.showSettingFilter = function() {
  1067. var currentValues = PWM_CFGEDIT.readNavigationFilters();
  1068. var dialogBody = '<div><form id="form-settingFilter"><table class="" style="table-layout: fixed">';
  1069. dialogBody += '<tr><td>Setting Level</td><td><label>';
  1070. dialogBody += '<input type="range" min="0" max="2" name="input-settingLevel" id="input-settingLevel" value="' + currentValues['level'] + '" style="width:100px"/>';
  1071. dialogBody += '<span id="panel-settingLevelDescription"></span></label></td></tr>';
  1072. dialogBody += '<tr><td>Modified</td><td>';
  1073. dialogBody += '<input type="radio" name="input-modifiedSettingsOnly" id="input-modifiedSettingsOnly-all" ' + (!currentValues['modifiedSettingsOnly'] ? 'checked' : '') + '>All';
  1074. dialogBody += '<input type="radio" name="input-modifiedSettingsOnly" id="input-modifiedSettingsOnly-modified" ' + (currentValues['modifiedSettingsOnly'] ? 'checked' : '') + '>Modified';
  1075. //dialogBody += '</td></tr><tr><td>Text';
  1076. //dialogBody += '</td><td><input type="text" id="input-settingFilterText" class="inputfield" id="input-settingFilterText"/>';
  1077. dialogBody += '</td></tr>';
  1078. dialogBody += '</table></div></div>';
  1079. var updateSettingLevelDescription = function() {
  1080. var value = parseInt(PWM_MAIN.getObject('input-settingLevel').value);
  1081. var descriptionText = PWM_CONFIG.showString('Display_SettingFilter_Level_' + value);
  1082. PWM_MAIN.getObject('panel-settingLevelDescription').innerHTML = descriptionText;
  1083. };
  1084. var updateIcon = function() {
  1085. var isDefault = PWM_VAR['settingFilter_modifiedSettingsOnly'] == false && PWM_VAR['settingFilter_level'] == 2;
  1086. if (isDefault) {
  1087. PWM_MAIN.removeCssClass('settingFilter_icon', "modified");
  1088. } else {
  1089. PWM_MAIN.addCssClass('settingFilter_icon', "modified");
  1090. }
  1091. };
  1092. var updateVars = function() {
  1093. PWM_VAR['settingFilter_modifiedSettingsOnly'] = PWM_MAIN.getObject('input-modifiedSettingsOnly-modified').checked;
  1094. PWM_VAR['settingFilter_level'] = parseInt(PWM_MAIN.getObject('input-settingLevel').value);
  1095. //PWM_VAR['settingFilter_text'] = PWM_MAIN.getObject('input-settingFilterText').value;
  1096. updateSettingLevelDescription();
  1097. };
  1098. PWM_MAIN.showDialog({title:'Setting Filters',text:dialogBody,loadFunction:function(){
  1099. //PWM_MAIN.getObject('input-settingFilterText').value = currentValues['text'];
  1100. PWM_MAIN.addEventHandler('form-settingFilter','change',function(){
  1101. updateVars();
  1102. });
  1103. updateSettingLevelDescription();
  1104. },okAction:function(){
  1105. updateIcon();
  1106. PWM_CFGEDIT.loadMainPageBody();
  1107. }});
  1108. };
  1109. PWM_CFGEDIT.readCurrentProfile = function() {
  1110. return PWM_VAR['currentProfile'];
  1111. };
  1112. PWM_CFGEDIT.setCurrentProfile = function(profile) {
  1113. if (profile) {
  1114. PWM_VAR['currentProfile'] = profile;
  1115. } else {
  1116. delete PWM_VAR['currentProfile'];
  1117. }
  1118. };
  1119. PWM_CFGEDIT.applyGotoSettingHandlers = function() {
  1120. PWM_MAIN.doQuery('[data-gotoSettingLink]',function(element){
  1121. PWM_MAIN.addEventHandler(element,'click',function(){
  1122. var linkValue = element.getAttribute('data-gotoSettingLink');
  1123. PWM_CFGEDIT.gotoSetting(null,linkValue,null);
  1124. })
  1125. });
  1126. };
  1127. PWM_CFGEDIT.closeMenuPanel = function() {
  1128. console.log('action closeHeader');
  1129. PWM_MAIN.addCssClass('header-warning','nodisplay');
  1130. PWM_MAIN.removeCssClass('button-openMenu','nodisplay');
  1131. };
  1132. PWM_CFGEDIT.openMenuPanel = function() {
  1133. console.log('action openHeader');
  1134. PWM_MAIN.removeCssClass('header-warning','nodisplay');
  1135. PWM_MAIN.addCssClass('button-openMenu','nodisplay');
  1136. };