Suspend.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cogadmin
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2010
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  11. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  12. //----------------------------------------------------------
  13. com.cognos.admin.ObjectFactory("com.cognos.admin.extension");
  14. /* This is a implementation of the extensive event handler. The impl need to have a method named "doAction" to
  15. * work as a mapping.
  16. * @param: env, context of the behaviour controller framework.
  17. *
  18. */
  19. com.cognos.admin.extension.Suspend = function (env) {
  20. this.fragment = env.fragment;
  21. this.context = env.context;
  22. this.scheduleEndDateId = this.fragment.id+"endDate";
  23. this.scheduleEndTimeId = this.fragment.id+"endTime";
  24. this.i18n = env.i18n
  25. var self = this;
  26. //register for shedule prompt notifications to provide an event to rectify schedule selection popup appearing behind this dialog
  27. this.scheduleDialogListener = function() {
  28. this.notify = function(iState, oNotifier) {
  29. //Because the compiled (ie. obfuscated) js version of the prompting libs are being used, we'll need to introspect (ie. loop thru) the oNotifier object to find the scheduler prompt
  30. for (name in oNotifier) {
  31. o = oNotifier[name];
  32. if (o && (o.id == 'dialogDatePicker'+self.fragment.id+'endDate')) {
  33. _o = o;
  34. setTimeout('_o.style.zIndex="9999"',1);
  35. return;
  36. }
  37. }
  38. }
  39. };
  40. this.onDialogOK = function(evt) {
  41. var frag = evt.source;
  42. var finite = $(frag.id+'suspend_finite').checked;
  43. var selections = document.pform[frag.id+"suspend_period"];
  44. var requestParms = ("finite="+encodeURIComponent(finite));
  45. if (finite) {
  46. if (!self.getDateControl().isValid()) {
  47. alert(self.i18n.IDS_FLT_MSG_INVALID_DATE);
  48. evt.preventDefault();
  49. return false;
  50. }
  51. if (!self.getTimeControl().isValid()) {
  52. alert(self.i18n.IDS_FLT_MSG_INVALID_TIME);
  53. evt.preventDefault();
  54. return false;
  55. }
  56. var date = self.getDateControl().sGetValue();
  57. var time = self.getTimeControl().sGetValue();
  58. requestParms+=("&release="+encodeURIComponent(date+"T"+time));
  59. }
  60. for (var name in self.context) {
  61. requestParms+=("&"+name+"="+self.context[name]);
  62. }
  63. requestParms+="&userClickedOk=true";
  64. frag.retrieve(requestParms);
  65. return true;
  66. };
  67. this.unload = function(evt) {
  68. self.fragment.removeEventListener("cognos.ui.dialog.show", self.onDialogShow);
  69. self.fragment.removeEventListener("fragment.unload", self.destroy);
  70. self.fragment.removeEventListener("cognos.ui.dialog.ok", self.onDialogOK);
  71. //clean up Prompting Date/Time instances
  72. var schedulePopup = $("dialogDatePicker"+this.scheduleEndDateId);
  73. while (schedulePopup) {
  74. var parent = schedulePopup.parentNode
  75. parent.removeChild(schedulePopup);
  76. schedulePopup = $("dialogDatePicker"+this.scheduleEndDateId);
  77. }
  78. var controlArray = getPreProcessControlArray();
  79. _F_Array.remove(controlArray,"pickerControl"+this.scheduleEndDateId);
  80. _F_Array.remove(controlArray,"timePicker"+this.scheduleEndTimeId);
  81. _F_Array.remove(datePickerObserverArray,"pickerControl"+this.scheduleEndDateId);
  82. };
  83. this.onDialogShow = function(evt) {
  84. var frag = evt.target;
  85. var scheduleEndDateId = self.scheduleEndDateId;
  86. var scheduleEndTimeId = self.scheduleEndTimeId
  87. var now = new Date();
  88. var firstDate = now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
  89. var defaultDate = now;
  90. var dateArgs = {formName:"pform",parameterName:"sched_"+scheduleEndDateId,submitType:"",prmtDefaultDate:defaultDate.toUTCString(),defaultValue:defaultDate,startOfWeek:"Sunday",calendar:"Gregorian",selectUI:"editBox",selectDateUI:"editBox",inputOrder:"YMD",firstDate:firstDate,lastDate:"",dateTime:1,initialState:RANGE_NO_VALUE,required:true,suppressDisabled:true,hideAdornments:true,suppressExtraPromptNames:false,multi:false,range:false,style:"",selectDateEditBoxStyle:"",selectDateYearsStyle:"",selectDateMonthsStyle:"",selectDateDaysOfWeekStyle:"",selectDateDaysStyle:"",CVId:frag.id,id:scheduleEndDateId};
  91. var defaultTimeValue = defaultDate.getHours()+":"+defaultDate.getMinutes()+":"+defaultDate.getSeconds();
  92. var timeArgs = {formName:"pform",parameterName:"sched_"+scheduleEndTimeId,submitType:"",defaultValue:defaultTimeValue,selectUI:"editBox",timeZone:"",hourFormat:"hh",minuteFormat:"mm",secondFormat:"ss",display:2,mode:0,initialState:RANGE_NO_VALUE,required:true,suppressDisabled:true,hideAdornments:true,suppressExtraPromptNames:false,multi:false,range:false,style:"",style:"",CVId:frag.id,id:scheduleEndTimeId}
  93. genSelectDateHTML(dateArgs);
  94. genSelectTimeHTML(timeArgs);
  95. var parent = frag.parent;
  96. if (null == parent) {
  97. parent = window; //default
  98. }
  99. if (null == parent.listenerRegistered) {
  100. parent.listenerRegistered = true;
  101. registerForNotications(new self.scheduleDialogListener());
  102. }
  103. };
  104. this.fragment.addEventListener("cognos.ui.dialog.show", this.onDialogShow);
  105. this.fragment.addEventListener("fragment.unload", this.unload);
  106. this.fragment.addEventListener("cognos.ui.dialog.ok", this.onDialogOK);
  107. };
  108. com.cognos.admin.extension.Suspend.VERSION = "0.1.0";
  109. com.cognos.admin.extension.Suspend.prototype = {
  110. getPromptControl : function(type, id) {
  111. return window[type+id]
  112. },
  113. getDateControl : function() {
  114. return this.getPromptControl("pickerControl",this.scheduleEndDateId);
  115. },
  116. getTimeControl : function() {
  117. return this.getPromptControl("timePicker",this.scheduleEndTimeId);
  118. }
  119. }