myinbox.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: HTS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2022 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. /*
  11. * Called when a task is skipped
  12. */
  13. function hts_skipTask(fragmentObj, fragmentName) {
  14. fragmentObj_retrieve(fragmentObj, "action=skipTask", null, true);
  15. return true;
  16. }
  17. /*
  18. * Called when a task is completed
  19. */
  20. function hts_complete(fragmentObj, fragmentName) {
  21. fragmentObj_retrieve(fragmentObj, "action=complete", null, true);
  22. return true;
  23. }
  24. function hts_claimTask(fragmentObj, fragmentName) {
  25. fragmentObj_retrieve(fragmentObj, "action=claim", null, true);
  26. return true;
  27. }
  28. function hts_releaseTask(fragmentObj, fragmentName) {
  29. fragmentObj_retrieve(fragmentObj, "action=release", null, true);
  30. return true;
  31. }
  32. /*
  33. */
  34. function hts_createNotificationTask(fragmentObj, fragmentName) {
  35. var iframe = $(fragmentName+'_notificationMessageValue_iframe');
  36. var bodytext = iframe.contentDocument? iframe.contentDocument.body.textContent : iframe.contentWindow.document.body.innerText;
  37. $(fragmentName+'_notificationMessageTextValue').value = bodytext;
  38. var params = new hts_taskUpdateParams("action=createNotificationTask");
  39. if (params)
  40. {
  41. var messages = hts_getMsgs(fragmentName);
  42. //the value entered for "To" field
  43. var recipients = document.getElementById(fragmentName + '_potentialOwners_value');
  44. //the value entered for "CC" field
  45. var stakeholders = document.getElementById(fragmentName + '_stakeHolders_value');
  46. if ((recipients.value == '' || recipients.value.indexOf('{"organizationalEntities":[]}') != -1) &&
  47. (stakeholders.value == '' || stakeholders.value.indexOf('{"organizationalEntities":[]}') != -1))
  48. {
  49. alert(messages['MSG_ERR_NOTIFICATION_RECIPIENT_NOT_SELECTED']);
  50. return false;
  51. }
  52. //check if the notification checkbox is selected or not
  53. var notificationCheckBox = document.getElementById(fragmentName + 'notification');
  54. if(notificationCheckBox.checked==true)
  55. {
  56. //only if the checkbox is checked, we have to set the notification deadline
  57. //validate the date
  58. if(hts_validateNotificationDate(fragmentName + 'taskOptions_dueDate', messages))
  59. {
  60. //if the date is valid, create the param
  61. params.createParamFromElement('dueDate', 'p_' + fragmentName + 'taskOptions_dueDate');
  62. }
  63. else
  64. {
  65. //the date is invalid so return
  66. return false;
  67. }
  68. }
  69. //create the update parameters
  70. params.createParamFromElement('priority',fragmentName + 'taskOptions_priority');
  71. params.createParamFromElement('stakeholderList',fragmentName + '_stakeHolders_value');
  72. params.createParamFromElement('recipientList',fragmentName + '_potentialOwners_value');
  73. params.createParamFromElement('subject', fragmentName + '_subject_value');
  74. params.createParamFromElement('message_HTML',fragmentName + '_notificationMessageValue');
  75. params.createParamFromElement('message_text', fragmentName + '_notificationMessageTextValue');
  76. params.createParamFromElement('reportLinks', fragmentName + '_linksList_value');
  77. params.createParamFromElement('reportLinksDisplay', fragmentName + '_linksList_display');
  78. var recordReadReceiptCheckbox = document.getElementById(fragmentName + 'recordReadReceipt');
  79. if (recordReadReceiptCheckbox)
  80. {
  81. params += ("&recordReadReceipt=" + recordReadReceiptCheckbox.checked);
  82. }
  83. //fire the update
  84. var paramStr = params.toString();
  85. fragmentObj_retrieve(fragmentObj, paramStr, null, true);
  86. }
  87. return params?true:false;
  88. }
  89. function hts_validateNotificationDate(notificationDate, msgs)
  90. {
  91. var htsDatePickerUtil = new hts_datePickerUtil(notificationDate);
  92. if(htsDatePickerUtil.isDateEmpty() || !htsDatePickerUtil.isDateValid())
  93. {
  94. //if the date is empty or the date is not valid
  95. alert(msgs['MSG_ERR_NOTIFICATION_DATE_INVALID']);
  96. return false;
  97. }
  98. if(!htsDatePickerUtil.isDateLaterThanOrEqualToCurrentDate())
  99. {
  100. alert(msgs['MSG_ERR_NOTIFICATION_DATE_IN_PAST']);
  101. return false;
  102. }
  103. return true;
  104. }
  105. function trim(s)
  106. {
  107. return s.replace(/^\s+|\s+$/, '');
  108. }
  109. function hts_createGenericTask(fragmentObj, fragmentName, subscriptions) {
  110. var iframe = $(fragmentName+'_taskMessageValue_iframe');
  111. var subject_val = $(fragmentName+'_subject_value');
  112. var bodytext = iframe.contentDocument? iframe.contentDocument.body.textContent : iframe.contentWindow.document.body.innerText;
  113. $(fragmentName+'_taskMessageTextValue').value = bodytext;
  114. var subjectText = trim(subject_val.value);
  115. var params = hts_getParams(fragmentName,"createGenericTask");
  116. var messages = hts_getMsgs(fragmentName);
  117. if (subjectText.length==0)
  118. {
  119. alert(messages['MSG_ERR_TASKVIEWER_WARN_GENERICTASK_NO_SUBJECT']);
  120. return false;
  121. }
  122. if (params)
  123. {
  124. var messages = hts_getMsgs(fragmentName);
  125. var assignedTo = document.getElementById(fragmentName + '_potentialOwners_value');
  126. var stakeholders = document.getElementById(fragmentName + '_stakeHolders_value');
  127. var regx = new RegExp("{\"organizationalEntities\":\\[\\]}");
  128. if (regx.test(assignedTo.value) && regx.test(stakeholders.value))
  129. {
  130. alert(messages['MSG_ERR_ASSIGNEDTO_OR_STAKEHOLDER_NOT_SELECTED']);
  131. return false;
  132. }
  133. params.createParamFromElement('subject', fragmentName + '_subject_value');
  134. params.createParamFromElement('message_text',fragmentName + '_taskMessageTextValue');
  135. params.createParamFromElement('message_HTML',fragmentName + '_taskMessageValue');
  136. params.createParamFromElement('reportLinks', fragmentName + '_linksList_value');
  137. params.createParamFromElement('reportLinksDisplay', fragmentName + '_linksList_display');
  138. //Attach the subscriptions.
  139. params = params + subscriptions;
  140. //fire the update
  141. var paramStr = params.toString();
  142. fragmentObj_retrieve(fragmentObj, paramStr, null, true);
  143. }
  144. return params?true:false;
  145. }
  146. /*
  147. * set the message to be set into the task options div that is displayed either when a task has been deselected or a task is loading
  148. */
  149. function hts_setMessage(fragmentName,message) {
  150. var node = $(fragmentName+"infoDiv_value");
  151. node.innerHTML=message;
  152. }
  153. /*
  154. * Called when a task is saved after editing
  155. */
  156. function hts_saveTaskOptions(fragmentObj, fragmentName) {
  157. var params = hts_getParams(fragmentName,"updateTask");
  158. if (params) {
  159. fragmentObj.raiseEvent('cognos.hts.showWait');
  160. params.createParamFromElement('actualOwner',fragmentName + '_assingnedTo_token');
  161. //fire the update
  162. var paramStr = params.toString();
  163. fragmentObj_retrieve(fragmentObj, paramStr, null, true);
  164. }
  165. return params?true:false;
  166. }
  167. function hts_getParams(fragmentName, action) {
  168. var params = new hts_taskUpdateParams("action="+ action);
  169. var dt = new hts_datetime(fragmentName + 'taskOptions_startBy',fragmentName + 'taskOptions_dueDate',hts_getMsgs(fragmentName));
  170. //create the update parameters
  171. params.createParamFromElement('hts_status', fragmentName + 'taskOptions_status');
  172. params.createParamFromElement('priority',fragmentName + 'taskOptions_priority');
  173. params.createParamFromElement('stakeholderList',fragmentName + '_stakeHolders_value');
  174. params.createParamFromElement('potentialOwnerList',fragmentName + '_potentialOwners_value');
  175. //check if the pickers have changed from the initial values when the fragment was loaded
  176. var fromPickerDirty = !dt.checkDate(true,eval(fragmentName+"dateFrom"));
  177. var toPickerDirty = !dt.checkDate(false,eval(fragmentName+"dateTo"));
  178. //if the pickers have the current date then no deadlines have been set on the task, check the dirty
  179. //flag, the user may have set the current date explicitly
  180. var datesValid = hts_validateDeadlines(dt,fromPickerDirty,toPickerDirty);
  181. //from deadline has been entered
  182. if (fromPickerDirty) {
  183. var elementName = 'p_' + fragmentName + 'taskOptions_startBy';
  184. //adjust the time if the start date is todays date
  185. if (dt.checkCurrentDate(dt.getDateFromValue())) {
  186. var element = document.getElementById(elementName);
  187. if (element) {
  188. var newValue = element.value.replace("00:00:00.000","23:59:00.000");
  189. element.value = newValue;
  190. }
  191. }
  192. params.createParamFromElement('startBy',elementName);
  193. }
  194. //to deadline has been entered
  195. if (toPickerDirty) {
  196. params.createParamFromElement('dueDate', 'p_' + fragmentName + 'taskOptions_dueDate');
  197. }
  198. return datesValid?params:datesValid;
  199. }
  200. function hts_validateDeadlines(dt,fromPickerDirty,toPickerDirty) {
  201. var datesValid = true;
  202. //from and to deadlines have been entered
  203. if (fromPickerDirty && toPickerDirty) {
  204. datesValid = dt.validateDates();
  205. }
  206. //from deadline has been entered
  207. else if (fromPickerDirty) {
  208. datesValid = dt.validateFromDate();
  209. }
  210. //to deadline has been entered
  211. else if (toPickerDirty) {
  212. datesValid = dt.validateToDate();
  213. }
  214. return datesValid;
  215. }
  216. function hts_getCurrentDate() {
  217. var currentDate = new Date();
  218. var day = currentDate.getDate();
  219. var month = currentDate.getMonth()+1;
  220. var year = currentDate.getFullYear();
  221. return year + "-" + month +"-" + day;
  222. }
  223. function hts_getMsgs(fragmentName) {
  224. return eval(fragmentName+"msg_array");
  225. }
  226. function hts_getDatePicker(fragmentName,pickerName) {
  227. return window['pickerControl' + fragmentName + pickerName];
  228. }
  229. function hts_setDatePickers(fragmentName,dateFromStr,dateToStr) {
  230. var dt = new hts_datetime(fragmentName + 'taskOptions_startBy',fragmentName + 'taskOptions_dueDate',hts_getMsgs(fragmentName));
  231. if (dateFromStr!=="") {
  232. dt.setDateFromValue(dateFromStr);
  233. }
  234. if (dateToStr!=="") {
  235. dt.setDateToValue(dateToStr);
  236. }
  237. }
  238. function hts_clearDatePickers(fragmentName) {
  239. var dt = new hts_datetime(fragmentName + 'taskOptions_startBy',fragmentName + 'taskOptions_dueDate',hts_getMsgs(fragmentName));
  240. dt.setDateFromValue("");
  241. dt.setDateToValue("");
  242. }
  243. /**
  244. This sets a couple of listeners for the click and mousedown events.
  245. It finds all buttons that generate a datepicker, and adds a mousdown event.
  246. The mousedown will close all open pickers.
  247. It adds onclick to the body of the main page. When the body is clicked, all
  248. pickers are closed.
  249. if adds mousedown listener to the iframe and body of the Dojo editor. This
  250. is because in IE the body responds to events and the body covers 100% of the
  251. iframe. In firefox the body does not cover the iframe and so we need to cater
  252. for clicking on the iframe itself.
  253. */
  254. function hts_datePickerListener() {
  255. // do it when the DOM is loaded
  256. dojo.addOnLoad( function() {
  257. // attach on click to id="textDiv"
  258. dojo.query('body').onclick( function(evt) {
  259. hts_hideDatePickers();
  260. });
  261. dojo.query("[id$='imgPicker']").onmousedown( function(evt) {
  262. hts_hideDatePickers();
  263. dojo.query('iframe[id$="_iframe"]').forEach (function(item, idx) {
  264. if (item.contentDocument) {
  265. var handle = dojo.connect(item.contentWindow, "onmousedown", function(e){
  266. hts_hideDatePickers();
  267. dojo.disconnect(handle);
  268. });
  269. } else {
  270. var handle = dojo.connect(item.contentWindow.document.body, "onmousedown", function(e) {
  271. hts_hideDatePickers();
  272. dojo.disconnect(handle);
  273. });
  274. }
  275. });
  276. });
  277. });
  278. }
  279. function hts_hideDatePickers() {
  280. for (var i in window) {
  281. //We need to do this to get the picker object
  282. if (i.indexOf('pickerControl')!= -1 && i.indexOf('iframe')== -1) {
  283. //This will hide it.
  284. window[i].gotFocus();
  285. }
  286. }
  287. }
  288. /**
  289. * The date pickers when clicked they create an iframe. On IE this Iframe
  290. * remains behind when the fragment is refreshed, this causes a problem
  291. * where when the picker is made visible again, both iframes become visible
  292. * and when hiding only one is hidden. The code below deleted the orphan
  293. * iframe if it is there.
  294. */
  295. function hts_clearDatePickersIframe(id) {
  296. dojo.query("[id*='pickerControl" + id + "iframe']").forEach(dojo.destroy);
  297. }
  298. function hts_toggler(imgExpand,imgCollapse) {
  299. this.imgExpand = imgExpand;
  300. this.imgCollapse = imgCollapse;
  301. }
  302. hts_toggler.prototype = {
  303. toggleDynamicSection: function (name) {
  304. if(document.getElementById(name).style.display == 'none') {
  305. this.showDynamicSection(name);
  306. }
  307. else {
  308. this.hideDynamicSection(name);
  309. }
  310. },
  311. showDynamicSection: function (name) {
  312. var node = document.getElementById(name);
  313. if (node) {
  314. node.style.display='block';
  315. var imgName = document.getElementById('img' + name);
  316. if (imgName) {
  317. imgName.src = this.imgCollapse;
  318. imgName.setAttribute('alt','Collapse');
  319. imgName.setAttribute('title','Collapse');
  320. }
  321. }
  322. },
  323. hideDynamicSection: function (name) {
  324. var node = document.getElementById(name);
  325. if (node) {
  326. node.style.display='none';
  327. var imgName = document.getElementById('img' + name);
  328. if (imgName) {
  329. imgName.src = this.imgExpand;
  330. imgName.setAttribute('alt','Expand');
  331. imgName.setAttribute('title','Expand');
  332. }
  333. }
  334. },
  335. isHidden: function(name) {
  336. return document.getElementById(name).style.display=='none';
  337. }
  338. }
  339. function hts_taskUpdateParams(prefix) {
  340. this.params = prefix;
  341. }
  342. hts_taskUpdateParams.prototype = {
  343. createParamFromElement: function (paramName, elementName) {
  344. var element = document.getElementById(elementName);
  345. if (dijit.byId(elementName)) {
  346. //Hack it in. bug: COGCQ00225777 The contents should be html encoded to avoid problems with external html i.e. user typed html.
  347. element.value = dijit.byId(elementName).getValue();
  348. }
  349. if (element)
  350. {
  351. this.params+="&"+_F_Strings.urlEncode(paramName)+"="+_F_Strings.urlEncode(element.value);
  352. }
  353. },
  354. toString: function() {
  355. return this.params;
  356. },
  357. contains: function(str) {
  358. return this.params.indexOf(str)>=0;
  359. }
  360. }
  361. function hts_selectCheckbox(id,frag) {
  362. //we have clicked the parent checkbox so select/deselect all state change options
  363. if (id==frag+'notification') {
  364. var cb = document.getElementById(id);
  365. hts_walk(document,frag,cb.checked);
  366. }
  367. //we have selected a state change option so select the parent checkbox too
  368. else {
  369. var parentCb = document.getElementById(frag+'notification');
  370. parentCb.checked= hts_checkStateChanges(document,frag);
  371. }
  372. }
  373. function hts_walk(node,frag,subscribe) {
  374. for (var i=0; i < node.childNodes.length; i++){
  375. var childNode = node.childNodes[i];
  376. if (childNode.nodeName=='INPUT' && childNode.type=='checkbox' && node.id != frag+'notification' && childNode.id.indexOf(frag+'sub_stateChange')==0) {
  377. if (childNode.checked != subscribe) {
  378. childNode.checked=subscribe;
  379. }
  380. }
  381. hts_walk(childNode,frag,subscribe);
  382. }
  383. }
  384. function hts_checkStateChanges(node,frag) {
  385. var found = true;
  386. var checkboxes = node.getElementsByTagName('INPUT');
  387. var cbName = frag+"sub_stateChange";
  388. for (var i=0;i < checkboxes.length;i++) {
  389. if (checkboxes[i].type =='checkbox' && checkboxes[i].id.indexOf(cbName) != -1 && checkboxes[i].id != frag+'notification') {
  390. found = checkboxes[i].checked;
  391. //found a selected state change option so break
  392. if (found) {
  393. break;
  394. }
  395. }
  396. }
  397. return found;
  398. }
  399. function hts_setCurrentUser(prefix, id, name){
  400. var oItemDisplay = document.getElementById(prefix + "_display");
  401. var oItemValue = document.getElementById(prefix + "_value");
  402. oItemDisplay.value = name;
  403. oItemValue.value = id;
  404. }
  405. function hts_selectUser(paramPrefix) {
  406. var sHeaderTitle = "taskpool";
  407. var select_scope = "adminconsole.users";
  408. var display_prop = "defaultName";
  409. //var value_prop = "id";
  410. var value_prop = "searchPath";
  411. var oItemDisplay = document.getElementById(paramPrefix + "_display");
  412. var oItemSearchPath = document.getElementById(paramPrefix + "_searchpath");
  413. var oItemValue = document.getElementById(paramPrefix + "_value");
  414. ccModalCallBack = function(cmd,sResponse) {
  415. if (cmd == "ok"){
  416. var xmlDoc = XMLBuilderLoadXMLFromString(xmldecode(sResponse));
  417. var item = xmlDoc.getElementsByTagName("item");
  418. var isItemSet = false;
  419. var itemDisplay = "";
  420. var itemValue = "";
  421. var itemSearchPath = "";
  422. for (var i=0; item.length > i; i++) {
  423. if (item[i].hasChildNodes()) {
  424. var children = item[i].childNodes;
  425. for (var j = 0; children.length > j; j++) {
  426. if (XMLHelper_GetText(children[j]) == display_prop) {
  427. itemDisplay = XMLHelper_GetText(children[1]);
  428. isItemSet = true;
  429. }
  430. if (XMLHelper_GetText(children[j]) == value_prop) {
  431. itemValue = XMLHelper_GetText(children[1]);
  432. }
  433. if (XMLHelper_GetText(children[j]) == 'searchPath') {
  434. itemSearchPath = XMLHelper_GetText(children[1]);
  435. }
  436. }
  437. }
  438. }
  439. }
  440. if (isItemSet == true) {
  441. hts_setText(oItemDisplay,_F_Strings.htmlEncode(itemDisplay));
  442. hts_setText(oItemValue,itemValue);
  443. hts_setText(oItemSearchPath,itemSearchPath);
  444. }
  445. ui_modal_dialog.close();
  446. }
  447. var defaultObject = '';
  448. if (oItemSearchPath.value != '')
  449. {
  450. defaultObject = '&so.defaultObject='+ oItemSearchPath.value;
  451. }
  452. ui_modal_dialog.open('?b_action=xts.run&m=portal/select/select.xts&so.select=' + select_scope + defaultObject + '&md.callBack=data&md.callBackMode=&m_name=' + sHeaderTitle, false, true, true);
  453. }
  454. // removes links
  455. function hts_removeLinks(cListObj, divObjId) {
  456. cListObj.removeSelected();
  457. hts_setFocusOnLink(divObjId);
  458. }
  459. // removes All links
  460. function hts_removeAllLinks(cListObj) {
  461. cListObj.removeAllNodes();
  462. }
  463. // adds links to the Clist div
  464. function hts_selectLinks(cListObj,parentId, divObjId, linksTabIndex) {
  465. ccModalCallBack = function (cmd, entries) {
  466. if (cmd == "ok") {
  467. var htsLinks = new HTSLinks(cListObj,$(parentId));
  468. for (var i = 0; i < entries.length; i++) {
  469. htsLinks.append(entries[i], linksTabIndex);
  470. }
  471. //update the dom
  472. htsLinks.commit();
  473. }
  474. ui_modal_dialog.close();
  475. hts_setFocusOnLink(divObjId);
  476. };
  477. // open the modal dialog to select one or more links
  478. ui_modal_dialog.open('?b_action=xts.run&m=myinbox/add_entries_links.xts&m_name=' + "", false, true, true);
  479. }
  480. //to set the focus on element within the Div
  481. function hts_setFocusOnLink(divObjId) {
  482. if (divObjId != null) {
  483. dojo.query("div#"+divObjId+ " a").forEach(
  484. function(node, index, arr) {
  485. node.focus();
  486. }
  487. );
  488. }
  489. }
  490. var counter = 0;
  491. function hts_selectRecipients(presentationName,msgs,stakeHoldersPrefix,potOwnersPrefix, dialogType, divObjId) {
  492. var stakeHolders = new HTSHumanRole(stakeHoldersPrefix);
  493. var potentialOwners = new HTSHumanRole(potOwnersPrefix);
  494. if (hts_productMode && hts_productMode.getMode() == hts_productMode.PLANNING) {
  495. var psWrapper = new myinbox.PSWrapper();
  496. //Get the securityMode first.
  497. psWrapper.getSecurityMode(function(response) {
  498. stakeHolders.setLogicalPeopleGroup(response);
  499. potentialOwners.setLogicalPeopleGroup(response);
  500. var appDialog = myinbox.ListApplicationDialog;
  501. var df = appDialog.openDialog(psWrapper);
  502. if (df ) {
  503. df.addCallback(dojo.hitch(this, function(result){
  504. if (result) {
  505. var recipientDialog = email.RecipientDialog;
  506. var args = {"applicationId":result,"endPointAddress":psWrapper._getServiceUrl()};
  507. var callBack = recipientDialog.openDialog(args);
  508. callBack.addCallback(dojo.hitch(this, function(recipients){
  509. var resultObj = dojo.fromJson(recipients);
  510. if (resultObj.length > 0) {
  511. for (var i = 0; i < resultObj.length; i++) {
  512. var camId = resultObj[i].id?resultObj[i].id:counter++;
  513. var name = resultObj[i].name;
  514. //always a group never a user for planning
  515. var isGroup = 'true';
  516. //get the 'to' and 'cc' flags
  517. var to = resultObj[i].to;
  518. var cc = resultObj[i].cc;
  519. //'to' recipient groups are assigned to potential owners
  520. if (to==true) {
  521. potentialOwners.append(camId,name,isGroup);
  522. }
  523. //'cc' recipient groups are assigned to stakeholders
  524. if (cc==true) {
  525. stakeHolders.append(camId,name,isGroup);
  526. }
  527. }
  528. //build the organisational entities
  529. stakeHolders.commit();
  530. potentialOwners.commit();
  531. }
  532. hts_setFocusOnLink(divObjId);
  533. potentialOwners.focus();
  534. }));
  535. }
  536. }));
  537. }
  538. });
  539. } else {
  540. ccModalCallBack = function(cmd, g_vEntries) {
  541. if (cmd == "ok") {
  542. potentialOwners.clear();
  543. potentialOwners.commit();
  544. stakeHolders.clear();
  545. stakeHolders.commit();
  546. if (g_vEntries.length > 0) {
  547. for (var i = 0; i < g_vEntries.length; i++) {
  548. var camId = g_vEntries[i].searchPath;
  549. var name = g_vEntries[i].defaultName;
  550. var type = g_vEntries[i].type.split(',');
  551. var isGroup = 'false';
  552. if(g_vEntries[i].objectClass == 'role' || g_vEntries[i].objectClass == 'group') {
  553. isGroup = 'true';
  554. }
  555. for (var j=0;j<type.length;j++) {
  556. if (type[j] == 'to') {
  557. potentialOwners.append(camId,name,isGroup);
  558. }
  559. if (type[j] == 'cc') {
  560. stakeHolders.append(camId,name,isGroup);
  561. }
  562. }
  563. }
  564. stakeHolders.commit();
  565. potentialOwners.commit();
  566. }
  567. }
  568. ui_modal_dialog.close();
  569. hts_setFocusOnLink(divObjId);
  570. potentialOwners.focus();
  571. }
  572. var fileName = "add_entries.xts";
  573. if (dialogType == "humanTask") {
  574. fileName = "add_entries_task.xts";
  575. }
  576. // open the modal dialog to select the users or groups
  577. ui_modal_dialog.open('?b_action=xts.run&m=myinbox/' + fileName + '&m_name=' + presentationName +
  578. '&selectedStakeHoldersCamIds='+ stakeHolders.getValues() +
  579. '&selectedPotentialOwnersCamIds='+potentialOwners.getValues(), false, true, true);
  580. }
  581. }
  582. function HTSProductMode(){
  583. this.PLANNING="planning";
  584. this.PLATFORM="platform";
  585. this.mode=this.PLATFORM;
  586. }
  587. HTSProductMode.prototype.getMode = function(){
  588. return this.mode;
  589. }
  590. HTSProductMode.prototype.setMode = function(modeIn){
  591. this.mode = modeIn;
  592. }
  593. function HTSTabDisabler() {
  594. this.fragId=null;
  595. }
  596. HTSTabDisabler.prototype.setParentFragment = function(fragment) {
  597. //only set once by the primary tab
  598. if (this.fragId == null) {
  599. this.fragId = fragment + "tabs";
  600. }
  601. }
  602. HTSTabDisabler.prototype.setEnabled = function(enabled) {
  603. //guard clause
  604. if (this.fragId==null) {
  605. return;
  606. }
  607. try {
  608. var tabObj = eval(this.fragId);
  609. for(var i in tabObj.tabs) {
  610. var tab = tabObj.tabs[i];
  611. if (tab != undefined) {
  612. this.replaceEventHandlers(tab,enabled);
  613. }
  614. }
  615. } catch(exception) {
  616. //nothing here
  617. }
  618. }
  619. HTSTabDisabler.prototype.replaceEventHandlers = function(tab,enabled) {
  620. var elem = $(tab.tabID);
  621. if (elem != null) {
  622. if (!enabled) {
  623. xRemoveEventListener(elem,"click",tab.onclick);
  624. xRemoveEventListener(elem,"keypress",tab.onkeypress);
  625. xAddEventListener(elem, "click", _F_Document.associate(elem,this, "onclick"));
  626. xAddEventListener(elem, "keypress", _F_Document.associate(elem,this, "onkeypress"));
  627. dojo.style(elem, "opacity", 0.4);
  628. }
  629. else {
  630. xRemoveEventListener(elem, "click",this.onclick);
  631. xRemoveEventListener(elem, "keypress", this.onkeypress);
  632. xAddEventListener(elem,"click",_F_Document.associate(elem, tab, "onclick"));
  633. xAddEventListener(elem,"keypress",_F_Document.associate(elem, tab, "onkeypress"));
  634. dojo.style(elem, "opacity", 1);
  635. }
  636. }
  637. }
  638. HTSTabDisabler.prototype.onclick = function(e, tag) {
  639. //nothing here
  640. }
  641. HTSTabDisabler.prototype.onkeypress = function(evt) {
  642. //nothing here
  643. }
  644. function HTSLocker(contentId) {
  645. this.locked=false;
  646. this.utils = new hts_utils();
  647. this.contentId = contentId;
  648. this.oCallBack=null;
  649. }
  650. HTSLocker.prototype.lock = function () {
  651. //guard, already locked, returns true if successfully locked
  652. if(this.locked == undefined || this.locked) {
  653. return false;
  654. }
  655. else {
  656. this.locked=true;
  657. var content = $(this.contentId);
  658. this.utils.setUIState(content,this.locked);
  659. if (typeof this.oCallBack == 'function') {
  660. this.oCallBack(this.locked);
  661. }
  662. }
  663. };
  664. HTSLocker.prototype.unlock = function () {
  665. //guard, already unlocked, returns true if successfully unlocked
  666. if(this.locked == undefined || this.locked==false) {
  667. return false;
  668. }
  669. else {
  670. this.locked=false;
  671. var content = $(this.contentId);
  672. this.utils.setUIState(content,this.locked);
  673. if (typeof this.oCallBack =='function') {
  674. this.oCallBack(this.locked);
  675. }
  676. }
  677. };
  678. HTSLocker.prototype.isLocked = function () {
  679. return this.locked;
  680. };
  681. HTSLocker.prototype.setCallBack = function (func) {
  682. this.oCallBack = func;
  683. };
  684. /*
  685. * HTS Links object
  686. */
  687. function HTSLinks(cListObj,parentDiv) {
  688. this.cListObj = cListObj;
  689. this.parent=parentDiv;
  690. //set the equality function if we do not already have one, this will ensure
  691. //that the containsItem() function works properly and that duplicate links are not added
  692. //when cListObj.add() is called
  693. if (this.cListObj.getEqualityFunc()===null) {
  694. var eqFunc = function(clist,itemValue) {
  695. //get the cid from the table element
  696. var cid = itemValue.id;
  697. //find the item with the attribute 'cid' which matches the id of the link we are adding
  698. var results = dojo.query("[cid='"+cid+"']",clist.getListElement());
  699. return results.length > 0;
  700. };
  701. this.cListObj.setEqualityFunc(eqFunc);
  702. }
  703. }
  704. HTSLinks.prototype.append = function (entry, linkTabIndex) {
  705. var dispValue = entry.defaultName;
  706. var itemValue = entry.key;
  707. var objectClass = entry.objectClass;
  708. var divElem;
  709. //get a perfectly formed and exquisitely crafted <img/> tag that contains the correct icon for the object type
  710. var img = entry.img;
  711. //create a div element
  712. //we always have an id but may not have an object class e.g. for agent condition report
  713. if (objectClass && objectClass!="") {
  714. divElem = dojo.create("div",{ id:itemValue,objectClass:objectClass});
  715. }
  716. else {
  717. divElem = dojo.create("div",{ id:itemValue});
  718. }
  719. //define link tabindex if it exists
  720. var tabIndex = 0;
  721. if(linkTabIndex != undefined && linkTabIndex != null && linkTabIndex != '') {
  722. tabIndex = linkTabIndex;
  723. }
  724. //cannot set the class using the dojo.create syntax above because IE will barf(reserved keyword)
  725. dojo.attr(divElem, "class","reportLink");
  726. //set the content into the div which consists of an image followed by a link
  727. dojo.html.set(divElem,
  728. '<span style="padding-left:3px;padding-right:3px;vertical-align:top;">'+img+'</span>'+
  729. '<a class="cognos-anchor" id="'+itemValue+'" tabindex="'+tabIndex+'" title="'+entry.linkTitle+'">'+_F_Strings.htmlEncode(dispValue)+'</a>'
  730. );
  731. //add the table element to the clist object
  732. this.cListObj.add(divElem, itemValue, dispValue);
  733. };
  734. HTSLinks.prototype.commit = function (parentId) {
  735. if (this.cListObj.childCount > 0) {
  736. //attach to the dom i.e. show it
  737. if (parentId!=undefined) {
  738. $(parentId).appendChild(this.cListObj.getListElement());
  739. }
  740. else {
  741. this.parent.appendChild(this.cListObj.getListElement());
  742. }
  743. this.cListObj.deSelectAll();
  744. }
  745. };
  746. HTSLinks.prototype.getValues = function () {
  747. var valueObj = new Object();
  748. var links = new Array();
  749. if (this.cListObj.size() > 0) {
  750. var nodesArray = this.cListObj.getAllNodes();
  751. dojo.forEach(nodesArray, function(item) {
  752. valueObj.id=dojo.attr(item, "cid");
  753. valueObj.objectClass=dojo.query("table[objectClass]",item).at(0).attr("objectClass").toString();
  754. var valueJson = dojo.toJson(valueObj);
  755. links.push(valueJson);
  756. });
  757. }
  758. return links.join(',');
  759. };
  760. HTSLinks.prototype.getDisplayValues = function () {
  761. var links = new Array();
  762. if (this.cListObj.size() > 0) {
  763. var nodesArray = this.cListObj.getAllNodes();
  764. dojo.forEach(nodesArray, function(item) {
  765. links.push(dojo.attr(item, "disp"));
  766. });
  767. }
  768. return links.join(',');
  769. };
  770. /*
  771. * HTS Human Role object
  772. */
  773. function HTSHumanRole(humanRolePrefix) {
  774. this.values = document.getElementById(humanRolePrefix + "_value");
  775. this.display = document.getElementById(humanRolePrefix + "_display");
  776. this.rawValues = {};
  777. this.rawValues.organizationalEntities = new Array();
  778. //Default to CAM,if in Planning we then reset it.
  779. this.rawValues.logicalPeopleGroup = new String("CAM");
  780. this.rawDisplayValues = new Array();
  781. }
  782. HTSHumanRole.prototype.focus =function() {
  783. this.display.focus();
  784. }
  785. HTSHumanRole.prototype.append = function (camId,name,bGroup) {
  786. this.addRawValue(camId,bGroup);
  787. this.addRawDisplayValue(name);
  788. };
  789. HTSHumanRole.prototype.parse = function (formatted,raw) {
  790. if (raw != undefined) {
  791. this.processRaw(raw.users);
  792. this.processRaw(raw.groups);
  793. }
  794. if (formatted != undefined) {
  795. this.processFormatted(formatted.users);
  796. this.processFormatted(formatted.groups);
  797. }
  798. };
  799. HTSHumanRole.prototype.processRaw = function (raw) {
  800. if (raw != undefined && raw.length === undefined) {
  801. if (raw.group != undefined) {
  802. this.addRawValue(raw.group,"true");
  803. } else if (raw.user != undefined) {
  804. this.addRawValue(raw.user,"false");
  805. }
  806. }
  807. for (var i=0;raw != undefined && i< raw.length;i++) {
  808. if (raw[i].group != undefined) {
  809. this.addRawValue(raw[i].group,"true");
  810. } else if (raw[i].user != undefined) {
  811. this.addRawValue(raw[i].user,"false");
  812. }
  813. }
  814. };
  815. HTSHumanRole.prototype.processFormatted = function (formatted) {
  816. if (formatted != undefined && formatted.length === undefined) {
  817. if (formatted.group != undefined) {
  818. this.addRawDisplayValue(formatted.group);
  819. } else if (formatted.user != undefined) {
  820. this.addRawDisplayValue(formatted.user);
  821. }
  822. }
  823. for (var i=0;formatted != undefined && i<formatted.length;i++) {
  824. if (formatted[i].group != undefined) {
  825. this.addRawDisplayValue(formatted[i].group);
  826. } else if (formatted[i].user != undefined) {
  827. this.addRawDisplayValue(formatted[i].user);
  828. }
  829. }
  830. };
  831. HTSHumanRole.prototype.commit = function () {
  832. this.setValues(dojo.toJson(this.getRawValues()));
  833. this.setDisplayValues(this.getRawDisplayValues().join(', '));
  834. };
  835. // clears the content of pot owner / stake holder does need further commit
  836. HTSHumanRole.prototype.clear =function() {
  837. this.rawValues = {};
  838. this.rawDisplayValues = new Array();
  839. this.rawValues.organizationalEntities = new Array();
  840. // effective blank values
  841. this.setValues('');
  842. this.setDisplayValues('');
  843. };
  844. HTSHumanRole.prototype.getValues = function () {
  845. var values = this.values.value;
  846. //backward compatibility - convert to comma separated list.
  847. if(values && values.indexOf('organizationalEntities') != -1){
  848. var valuesObj = dojo.fromJson(values);
  849. var valuesArr = new Array();
  850. dojo.forEach(valuesObj.organizationalEntities, function(value) {
  851. valuesArr.push(value.token);
  852. });
  853. values = valuesArr.join(',');
  854. }
  855. return values;
  856. };
  857. HTSHumanRole.prototype.getDisplayValues = function () {
  858. return this.displays.value;
  859. };
  860. HTSHumanRole.prototype.getRawValues = function () {
  861. return this.rawValues
  862. };
  863. HTSHumanRole.prototype.getRawDisplayValues = function () {
  864. return this.rawDisplayValues
  865. };
  866. HTSHumanRole.prototype.setValues = function (sValues) {
  867. hts_setText(this.values, sValues);
  868. };
  869. HTSHumanRole.prototype.setDisplayValues = function (sValues) {
  870. hts_setText(this.display, sValues);
  871. };
  872. HTSHumanRole.prototype.setRawValues = function (sRawValues) {
  873. this.rawValues = sRawValues;
  874. };
  875. HTSHumanRole.prototype.addRawValue = function (sRawValue,bGroup) {
  876. var obj = {};
  877. obj.token = sRawValue.toString();
  878. obj.isGroup = bGroup === "true" || bGroup === "false" ?bGroup:"false";
  879. this.rawValues.organizationalEntities.push(obj);
  880. };
  881. HTSHumanRole.prototype.setRawDisplayValues = function (sRawDisplayValues) {
  882. this.rawDisplayValues = sRawDisplayValues;
  883. };
  884. HTSHumanRole.prototype.addRawDisplayValue = function (sRawDisplayValue) {
  885. this.rawDisplayValues.push(sRawDisplayValue);
  886. };
  887. HTSHumanRole.prototype.setLogicalPeopleGroup = function (sLogicalPeopleGroup) {
  888. this.rawValues.logicalPeopleGroup = sLogicalPeopleGroup;
  889. };
  890. function hts_selectComboItem(comboBox,selectedValue) {
  891. for (var i=0;i<comboBox.options.length;i++) {
  892. if (comboBox.options[i].value==selectedValue) {
  893. comboBox.options[i].selected=true;
  894. }
  895. }
  896. }
  897. function hts_getButtonsInfo(taskInfo) {
  898. var infoButtons = null;
  899. if(taskInfo.capabilities) {
  900. infoButtons = taskInfo.capabilities;
  901. }
  902. return infoButtons;
  903. }
  904. function hts_populateStatusComboItem(comboBox,taskInfo, menuStrings){
  905. var currentStatus = false;
  906. comboBox.options.length = 0;
  907. var menus;
  908. if(taskInfo.menus && taskInfo.menus.length > 0){
  909. menus = taskInfo.menus;
  910. }else{
  911. menus = new Array();
  912. if(taskInfo.menus.menu){
  913. menus.push(taskInfo.menus);
  914. }
  915. }
  916. var idx = 0;
  917. var alreadyAdded = false;
  918. for (var i=0;i< menus.length;i++) {
  919. var status = menus[i].menu.targetStatus;
  920. var isReadyReserved = (status == 'READY' || status == 'RESERVED');
  921. if (isReadyReserved) {
  922. if (alreadyAdded) {
  923. continue;
  924. }
  925. //do not bother with both reserved and ready.
  926. //i.e. same UI status Not Started for both, so only add one
  927. alreadyAdded = true;
  928. }
  929. comboBox.options[idx] = new Option(menuStrings[status], menus[i].menu.operation);
  930. //We will get here if reserved or ready is encountered first. The second round will be handled by the
  931. //condition above.
  932. var isRealStatusReadyReserved = taskInfo.status && (taskInfo.status == 'READY' || taskInfo.status == 'RESERVED');
  933. var setSelected = (isRealStatusReadyReserved && isReadyReserved) || taskInfo.status == status;
  934. //We only want to set selectd if task status equals status or if real status is ready or reserved and status is either
  935. //ready or reserced as well.
  936. if (setSelected) {
  937. //shouldnt get in here
  938. currentStatus = true;
  939. comboBox.options[idx].selected=true;
  940. }
  941. idx++;
  942. }
  943. if(currentStatus != true ){
  944. var currentOption = new Option(menuStrings[taskInfo.status], "");
  945. //add the current status as a label
  946. comboBox.options[comboBox.options.length] = currentOption;
  947. comboBox.options[comboBox.options.length - 1].selected = true;
  948. }
  949. }
  950. function hts_getSelectedComboValue(node,comboName) {
  951. var combo = node.ownerDocument.getElementById(comboName);
  952. var comboValue = combo.options[combo.selectedIndex].value;
  953. return comboValue
  954. }
  955. function hts_showWait(elementId) {
  956. //this function accepts element ids and elements so check here
  957. var content = typeof elementId == "string"?$(elementId):elementId;
  958. if (content) {
  959. var theId = typeof elementId == "string"?elementId:content.id;
  960. var innerDivId = theId+"_value";
  961. var innerDivContent = innerDivId + "content";
  962. var progressMarkup= ui_templates.get(ui_templates.contentTemplate, 'CONTENTID', innerDivContent);
  963. $(innerDivId).innerHTML=progressMarkup;
  964. content.style.display="block";
  965. var cancelAnchor = $(theId + "_cancel");
  966. cancelAnchor.innerHTML = PFM.JS.IDS_JS_BUTTON_CANCEL;
  967. var cancelDiv = $(theId + "_cancel_div");
  968. var func = function() {
  969. if (dojo.byId(innerDivContent) != null){
  970. cancelDiv.style.display = "";
  971. }
  972. };
  973. setTimeout(func, 500);
  974. }
  975. }
  976. function hts_hideButtons(elementId, disable) {
  977. var display = "";
  978. var visibility = "visible";
  979. if (disable) {
  980. display = "none";
  981. visibility = "hidden";
  982. }
  983. dojo.style(elementId,{"display":display,"visibility":visibility});
  984. }
  985. function hts_hideWait(elementId) {
  986. }
  987. function hts_setUsersOrGroups(taskInfo,node) {
  988. var displayList="";
  989. var organisationalEntities;
  990. //get the list of either groups or users, only can have one or the other not both
  991. if (taskInfo.users) {
  992. organisationalEntities = taskInfo.users;
  993. }
  994. else if (taskInfo.groups) {
  995. organisationalEntities = taskInfo.groups;
  996. }
  997. if(!organisationalEntities)
  998. return;
  999. //if only one then it is not an array
  1000. if (organisationalEntities.length==undefined) {
  1001. if (organisationalEntities.group!=undefined) {
  1002. displayList = organisationalEntities.group;
  1003. }
  1004. else {
  1005. displayList = organisationalEntities.user;
  1006. }
  1007. }
  1008. //build the display string
  1009. for (var i=0;i<organisationalEntities.length;i++) {
  1010. var organisationalEntity = organisationalEntities[i];
  1011. if (organisationalEntity.group) {
  1012. displayList += organisationalEntity.group;
  1013. }
  1014. else if (organisationalEntity.user) {
  1015. displayList += organisationalEntity.user;
  1016. }
  1017. if ((i+1)<organisationalEntities.length) {
  1018. displayList+=",";
  1019. }
  1020. }
  1021. hts_setText(node,displayList);
  1022. }
  1023. // returns the KeyCode for any browser
  1024. function _hts_getKeyCode(e) {
  1025. var evtobj = window.event? event : e;
  1026. var charCode = (evtobj.keyCode) ? evtobj.keyCode : evtobj.which
  1027. return charCode;
  1028. }
  1029. //dynamically resize the text area.
  1030. function hts_resizeTextArea(t) {
  1031. text = t.value.split('\n');
  1032. if (text == "") {
  1033. rows_length = 1;
  1034. t.rows = rows_length;
  1035. }
  1036. else {
  1037. b=1;
  1038. for (x=0;x < text.length; x++) {
  1039. if (text[x].length >= t.cols) b+= Math.floor(text[x].length/t.cols);
  1040. }
  1041. b+= text.length;
  1042. if (b > t.rows) t.rows = b;
  1043. }
  1044. }
  1045. //set the notification deadline, if no deadline is found then reset the deadline label(it may contain a previous unexpired deadline from another notification)
  1046. function hts_setNotificationDeadline(taskInfo,deadlineLabel) {
  1047. if (taskInfo.formattedDeadlines) {
  1048. if(taskInfo.formattedDeadlines.length){
  1049. deadlines = taskInfo.formattedDeadlines;
  1050. }else {
  1051. deadlines = new Array();
  1052. deadlines.push(taskInfo.formattedDeadlines);
  1053. }
  1054. for (var i=0; i < deadlines.length;i++) {
  1055. var deadlineInstance = deadlines[i].deadlineInstance;
  1056. //notifications have one deadline
  1057. if (deadlineInstance.type=="START") {
  1058. hts_setText(deadlineLabel,deadlineInstance.date);
  1059. }
  1060. }
  1061. }
  1062. //no deadline
  1063. else {
  1064. hts_setText(deadlineLabel,"");
  1065. }
  1066. }
  1067. function hts_setText(elem,txt) {
  1068. //is it a SPAN or DIV?
  1069. if (elem && (elem.tagName=="SPAN" || elem.tagName=="DIV")) {
  1070. if (elem.childNodes.length == 0) {
  1071. var textNode = document.createTextNode(txt);
  1072. elem.appendChild(textNode)
  1073. } else {
  1074. elem.firstChild.nodeValue = txt;
  1075. }
  1076. } else if (elem) {
  1077. elem.value=txt;
  1078. }
  1079. }
  1080. function hts_createButton(labelParam,onClickFunction,placeHolderId) {
  1081. var params = {
  1082. label: labelParam,
  1083. onClick: onClickFunction
  1084. };
  1085. var button = new dijit.form.Button(
  1086. params,dojo.byId(placeHolderId)
  1087. );
  1088. return button
  1089. }
  1090. function hts_utils(fragObj) {
  1091. this.fragObj = fragObj;
  1092. }
  1093. function fragmentObj_retrieve(fragmentObj, sParams, dest, synchronous, excludeDescendantState) {
  1094. // Add hts_client_caf
  1095. sParams += "&" + _F_Strings.urlEncode("hts_client_caf") + "=";
  1096. fragmentObj.retrieve(sParams, dest, synchronous, excludeDescendantState);
  1097. }
  1098. hts_utils.prototype = {
  1099. refreshTaskViewer: function() {
  1100. //get the tabs object
  1101. var tabs = this.getTabsHolder('subbook');
  1102. //get the current tab object
  1103. tabObject = tabs.tabs[tabs.activeTabID];
  1104. //flag a refresh and do it
  1105. tabObject.refreshRequired=true;
  1106. //the tab refresh calls frag.retrieve(). see webapps\p2pd\WEB-INF\fragments\producers\viewers\booklet\view\htabs.xslt
  1107. tabObject.refresh();
  1108. },
  1109. /**
  1110. * This function will obliterate a transient param
  1111. * that may have over lived its required lifetime.
  1112. * This is because all transients end up as globals
  1113. * and they are never removed for the lifetime of a
  1114. * fragment. Some fragment interactions stages are not
  1115. * making good use of transient and they are picking
  1116. * interaction params instead. Using this function
  1117. * will delete an unwanted transient from all fragments.
  1118. */
  1119. deleteTransient: function(sName,sChannel) {
  1120. var sKey = sName + "[" + sChannel + "]";
  1121. for (var k in fragments) {
  1122. if (fragments[k].transientGlobal[sKey]) {
  1123. delete fragments[k].transientGlobal[sKey];
  1124. }
  1125. }
  1126. },
  1127. /*
  1128. * Find a fragment by id, returns null if the fragment could not be found
  1129. */
  1130. findById: function (fragId) {
  1131. var root = this.fragObj.getRoot();
  1132. return this.find(root,fragId);
  1133. },
  1134. find: function (parent,fragId) {
  1135. var found = false;
  1136. var fragment = null;
  1137. var children = parent.getChildren();
  1138. for (var i=0;(i<children.length && !found);i++) {
  1139. var child = children[i];
  1140. var parentId = child.parent.id;
  1141. var childId = child.id.replace(parentId,"");
  1142. var found = childId == fragId;
  1143. if (found) {
  1144. fragment = child;
  1145. }
  1146. else {
  1147. fragment = this.find(child,fragId);
  1148. }
  1149. }
  1150. return fragment;
  1151. },
  1152. /*
  1153. * Refresh a fragment with the given id, no action is taken if the fragment could not be found
  1154. */
  1155. refresh: function(fragId) {
  1156. var frag = this.findById(fragId);
  1157. if (frag != null) {
  1158. //frag.raiseEvent("fragment.refresh");
  1159. fragmentObj_retrieve(frag, null, null, false, false);
  1160. }
  1161. },
  1162. findFirstChildById: function(fragId) {
  1163. var child = null;
  1164. var frag = this.findById(fragId);
  1165. if (frag !== null) {
  1166. var children = frag.getChildren();
  1167. if (children.length > 0) {
  1168. child = children[0];
  1169. }
  1170. }
  1171. return child;
  1172. },
  1173. getTabsHolder: function(fragId) {
  1174. var tabs = null;
  1175. var firstChild = this.findFirstChildById(fragId);
  1176. if (firstChild !== null) {
  1177. var children = firstChild.getChildren();
  1178. //get the tabs object, catch any exceptions during the eval
  1179. try {
  1180. tabs = eval(firstChild.id+"tabs");
  1181. }
  1182. catch(ex){
  1183. //nothing here
  1184. }
  1185. }
  1186. return tabs;
  1187. },
  1188. getCurrentTab: function(fragId) {
  1189. //we should have been given a booklet which wraps the tabs, so get the first child
  1190. var tab = null;
  1191. var tabs = this.getTabsHolder(fragId);
  1192. var firstChild = this.findFirstChildById(fragId);
  1193. if (firstChild !== null) {
  1194. var children = firstChild.getChildren();
  1195. var found=false;
  1196. //all good, we have the tabs objects and the active tab id
  1197. if (tabs !=null && tabs && tabs.activeTabID) {
  1198. var activeTabID = tabs.activeTabID;
  1199. //loop through the tabs, find the active one
  1200. for (var i=0;i<children.length && !found;i++) {
  1201. tab = children[i];
  1202. //if the tab fragment id contains the active tab id then flag as found
  1203. if (tab.id.indexOf(activeTabID)!=-1) {
  1204. found = true;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. return tab;
  1210. },
  1211. refreshCurrentTab: function(fragId) {
  1212. //we should have been given a booklet which wraps the tabs, so get the first child
  1213. var tab = this.getCurrentTab(fragId);
  1214. //refresh the tab fragment
  1215. if (tab!=null) {
  1216. tab.raiseEvent("fragment.refresh");
  1217. }
  1218. },
  1219. getDays: function(nbrOfDays,future) {
  1220. var currentDate = new Date();
  1221. var millisPerDay = 24*60*60*1000;
  1222. var nbrOfHours = millisPerDay * nbrOfDays;
  1223. var dateMillis = future?(currentDate.getTime() + nbrOfHours):(currentDate.getTime() - nbrOfHours);
  1224. var theDate = new Date(dateMillis);
  1225. //set to midnight
  1226. theDate.setHours(0);
  1227. theDate.setMinutes(0);
  1228. theDate.setSeconds(0);
  1229. //get the milliseconds
  1230. var time = theDate.getTime();
  1231. //console.log('date filter applied : last '+nbrOfDays+' day(s), from '+theDate+' to '+currentDate);
  1232. return time;
  1233. },
  1234. getMonths: function(nbrOfMonths,future) {
  1235. /*
  1236. var currentDate = new Date();
  1237. var daysPerMonth = 365 / 12;
  1238. var millisPerDay = 24*60*60*1000;
  1239. var calculatedDays = nbrOfMonths * daysPerMonth;
  1240. var calculatedDaysMillis = millisPerDay * calculatedDays;
  1241. var pastDateMillis = future?(currentDate.getTime() + calculatedDaysMillis):(currentDate.getTime() - calculatedDaysMillis);
  1242. var pastDate = new Date(pastDateMillis);
  1243. //set to midnight
  1244. pastDate.setHours(0);
  1245. pastDate.setMinutes(0);
  1246. pastDate.setSeconds(0);
  1247. var time = pastDate.getTime();
  1248. //console.log('date filter applied : last '+nbrOfMonths+' month(s), from '+pastDate+' to '+currentDate);
  1249. return time;
  1250. */
  1251. nbrOfMonths = parseInt(nbrOfMonths,10);
  1252. var theDate = new Date();
  1253. var year = theDate.getFullYear();
  1254. var month = theDate.getMonth();
  1255. var day = theDate.getDate();
  1256. var newYear = year;
  1257. var newMonth = future==true?(month + nbrOfMonths):(month - nbrOfMonths);
  1258. //convert to integer
  1259. var additionalYears = parseInt(newMonth/12,10);
  1260. //add the carry over year(s) for a future date
  1261. if (newMonth > 0) {
  1262. newYear+=additionalYears;
  1263. }
  1264. //determine the new month and year for past dates
  1265. else {
  1266. newYear= (newYear + additionalYears)-1;
  1267. newMonth = 12 + newMonth;
  1268. }
  1269. //make the new date
  1270. theDate.setMonth(newMonth);
  1271. theDate.setFullYear(newYear);
  1272. //set to midnight
  1273. theDate.setHours(0);
  1274. theDate.setMinutes(0);
  1275. theDate.setSeconds(0);
  1276. //console.log('date filter applied : last '+nbrOfMonths+' month(s), calc date: '+theDate+', current: '+new Date());
  1277. return theDate.getTime();
  1278. },
  1279. /*
  1280. * Set the UI read only state
  1281. * node - the node contains the contents to be disabled or enabled, note this can be the id or an actual object.
  1282. * If it is an object then obj.id will be called to try and retrieve a valid id
  1283. * taskStatus - The UI will be disabled if the taskStatus is completed, error or exited.
  1284. * If the taskStatus value is boolean true then the ui will be disabled otherwise enabled, default is false
  1285. * buttonsOnly - (optional) If defined and true then only disable buttons, default is false
  1286. */
  1287. setUIState: function(node,taskStatus,buttonsOnly) {
  1288. var id=null;
  1289. var disabled = false;
  1290. if (buttonsOnly==undefined) {
  1291. buttonsOnly=false;
  1292. }
  1293. //check if object or string, if object then try and get id
  1294. if (typeof node == "string") {
  1295. id = node;
  1296. }
  1297. //check for null because a null is type 'object'
  1298. else if (node !== null && typeof node == "object" && node.id) {
  1299. id = node.id;
  1300. }
  1301. //set the disabled state
  1302. if (id !== null && taskStatus!==undefined) {
  1303. //check the task status
  1304. if (taskStatus=='COMPLETED' || taskStatus=='ERROR' || taskStatus=='EXITED' || taskStatus=='OBSOLETE') {
  1305. disabled=true;
  1306. }
  1307. //check for boolean
  1308. else if (typeof taskStatus == "boolean"){
  1309. disabled = taskStatus;
  1310. }
  1311. else if (taskStatus=='READY') {
  1312. disabled = false;
  1313. }
  1314. }
  1315. //if the utils has the fragment defined and the buttonsOnly boolean is true then disable all buttons
  1316. if (this.fragObj != undefined && buttonsOnly != undefined && buttonsOnly==true) {
  1317. var fragId = this.fragObj.id;
  1318. //check for a dojo widget by looking for the 'attr' function which is used to set the disabled attribute
  1319. //note the use of dijit.byId and not dojo.byId, the former returns a dojo object
  1320. var items = dojo.query('[id^= \"'+fragId+'button\"]').forEach(
  1321. function(item, index, array){
  1322. var widget = dijit.byId(item.id);
  1323. if (widget !== undefined) {
  1324. widget.attr("disabled",disabled);
  1325. }
  1326. }
  1327. );
  1328. }
  1329. else {
  1330. //the element may be a dojo widget so check here
  1331. var widget = dijit.byId(id);
  1332. if (widget !== undefined) {
  1333. widget.attr("disabled",disabled);
  1334. }
  1335. //the element is a the dom object so just set the disabled attribute
  1336. else {
  1337. var node = dojo.byId(id);
  1338. if (node!==undefined) {
  1339. node.disabled = disabled;
  1340. //set opacity, IE greys out correctly when the element is disabled but FF does not, so set the opacity here
  1341. if (disabled) {
  1342. dojo.style(node,"opacity","0.4");
  1343. }
  1344. else {
  1345. dojo.style(node,"opacity","1");
  1346. }
  1347. }
  1348. }
  1349. }
  1350. },
  1351. debug: function(message) {
  1352. var debugDivId = 'debugDiv';
  1353. var debugDiv = $(debugDivId);
  1354. var clearFunc = function clear() {
  1355. var debugDiv = document.getElementById(debugDivId);
  1356. if (debugDiv) {
  1357. debugDiv.innerHTML="";
  1358. }
  1359. };
  1360. //make the div once
  1361. if (debugDiv == null) {
  1362. debugDiv = xCreateElement("div");
  1363. debugDiv.id = "debugDiv";
  1364. debugDiv.style.width="1200px";
  1365. debugDiv.style.height="300px"
  1366. debugDiv.style.border="1px solid red";
  1367. debugDiv.style.overflow="auto";
  1368. debugDiv.style.display="block";
  1369. document.body.appendChild(debugDiv);
  1370. var btn = xCreateElement("input");
  1371. btn.type="button"
  1372. btn.value="Clear";
  1373. btn.onclick=clearFunc;
  1374. document.body.appendChild(btn);
  1375. }
  1376. if (debugDiv && document.createTextNode) {
  1377. var messageNode=document.createTextNode(new Date()+"->"+message);
  1378. var br = document.createElement('br');
  1379. debugDiv.appendChild(messageNode);
  1380. debugDiv.appendChild(br);
  1381. }
  1382. }
  1383. }
  1384. var dojoEditor = null;
  1385. function DOJOEditor(id,options) {
  1386. this.id = id;
  1387. this.editorHolder = dojo.byId(id);
  1388. this.options = options;
  1389. this.editor;
  1390. this.setup();
  1391. }
  1392. DOJOEditor.prototype.setup = function() {
  1393. var body = document.getElementsByTagName("body")[0];
  1394. var currClass = dojo.attr( body, "class" ) || "";
  1395. if (currClass.indexOf ("tundra") == -1){
  1396. dojo.attr( body, "class", currClass + " tundra" );
  1397. }
  1398. }
  1399. DOJOEditor.prototype.create = function () {
  1400. this.editor = new dijit.Editor(this.options, this.id);
  1401. this.editorHolder = dojo.byId(this.id);
  1402. };
  1403. DOJOEditor.prototype.destroy = function () {
  1404. if(this.editor) {
  1405. this.editor.destroyRecursive(true);
  1406. this.cleanup();
  1407. }
  1408. };
  1409. DOJOEditor.prototype.cleanup = function() {
  1410. this.editorHolder.innerHTML = "";
  1411. this.editorHolder=null;
  1412. this.editor=null;
  1413. //Hack #1: Bug in dojo TablePlugin.js where subscribe to 'available' is not been unsubscribed when Plugin is destroyed.
  1414. delete dojo._topics["available"];
  1415. //Hack #2: The plugin handler is global. So need to set it to uninitialised to get re-inited again.
  1416. //tablePluginHandler.initialized = false;
  1417. };
  1418. DOJOEditor.prototype.isEmpty = function () {
  1419. var value = this.editor.getValue();
  1420. return value == "" || /<br.*_moz_editor_bogus_node.*\/>/.test(value);
  1421. };
  1422. DOJOEditor.prototype.getValue = function () {
  1423. var value = this.editor.getValue();
  1424. if (this.isEmpty()) {
  1425. value = "";
  1426. }
  1427. return value;
  1428. };
  1429. DOJOEditor.prototype.setValue = function (value) {
  1430. this.editor.setValue(value);
  1431. };
  1432. var hts_tabDisabler = new HTSTabDisabler();
  1433. hts_productMode = new HTSProductMode();