suppression.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /********************************************************************************************************************************
  2. * Licensed Materials - Property of IBM *
  3. * *
  4. * IBM Cognos Products: AGS *
  5. * *
  6. * (C) Copyright IBM Corp. 2005, 2008 *
  7. * *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
  9. *********************************************************************************************************************************/
  10. var ACTION_MARKER = "ACTION_XX_MARKER";
  11. var ACTION_COUNT_NAME = "ACTION_COUNT";
  12. var ACTION_NAME_NAME = "name";
  13. var ACTION_ID_NAME = "id";
  14. var ACTION_TYPE_NAME = "type";
  15. var ACTION_PATH_NAME = "path";
  16. var ACTION_TASK_LEVEL_FILTER = "taskLevelFilter";
  17. var ACTION_RUN_CONDITION = "runCondition";
  18. var ACTION_NAME = "ACTION";
  19. var AGENT_PARAM = "AGENT_PARAM";
  20. var Filter_ongoing_changed = "Filter_changed";
  21. var Changed = "changed";
  22. var Filter_ongoing_unchanged = "Filter_unchanged";
  23. var Unchanged = "unchanged";
  24. var Filter_ongoing_group = "Filter_ongoing_group";
  25. var Filter_new = "Filter_new";
  26. var Filter_no_events = "Filter_nil";
  27. var Nu = "new";
  28. var Filter_stopped = "Filter_deleted";
  29. var Stopped = "deleted";
  30. var Action_topic_filter = "Action_topic_filter";
  31. var last_selected_action;
  32. var MAX_TASK_NAME_LENGTH = 50;
  33. // called only when we finish - this does the stack-down-save into
  34. // suppressionFinish - and writes out variables that that needs too
  35. function doFinish()
  36. {
  37. if (window.validate && window.validate()) {
  38. // we've passed validation - so do the do
  39. writeAgents();
  40. // now do the redirect and submit
  41. document.forms.pform.m.value='/ags/suppressionFinish.xts';
  42. document.forms.pform.ps_nav_op.value='stack-down-save';
  43. //reset the undo history now that the form has been submitted
  44. var redoUndoMgr = parent.getConfigFrame().getRedoUndoManager();
  45. redoUndoMgr.resetTreeAction();
  46. cf.changeMenu(cf.TAB_SOURCE);
  47. document.forms.pform.submit();
  48. }
  49. }
  50. function writeAgents(){
  51. var the_div = document.getElementById("hidden_div");
  52. the_div.innerHTML = "";
  53. writeActions(parent.getAgentDefinition(), "hidden_div");
  54. };
  55. function loadAgentsToPage() {
  56. var count = parent.getAgentDefinition().getActionCount();
  57. //set them to the screen
  58. for(var load_count = 0; load_count < count; load_count++){
  59. addActionToPage(parent.getAgentDefinition().getActionAt(load_count));
  60. }
  61. if(count > 0){
  62. document.pform.ad_select_display.selectedIndex = 0;
  63. onSelectAction(parent.getAgentDefinition().getActionAt(0));
  64. }
  65. }
  66. function setSelectedActionDisplay(name_id){
  67. for(var i=0; i < document.pform.ad_select_display.length ; i++){
  68. if(document.pform.ad_select_display.options[i].value == name_id){
  69. document.pform.ad_select_display.selectedIndex = i;
  70. break;
  71. }
  72. }
  73. }
  74. function onSelectAction() {
  75. var success = true;
  76. if(last_selected_action && !validateAgentAction(last_selected_action)){
  77. success = false;
  78. //stay on the old action... validate method diplays messages
  79. setSelectedActionDisplay(last_selected_action.name_id);
  80. } else {
  81. //Reset the action
  82. last_selected_action = getSelectedAction();
  83. doSelectAction(last_selected_action);
  84. }
  85. return success;
  86. }
  87. function doSelectAction(action){
  88. if(!action){
  89. window.alert("selected action is undefined ");
  90. return;
  91. }
  92. //register the form object as the listener target
  93. parent.getAgentItemsListener().registerField(Action_topic_filter, action.id, action.getParams().getParamValue(Action_topic_filter), window.name);
  94. var unchanged_param = action.getParams().getParamValue(Filter_ongoing_unchanged)!= undefined;
  95. var changed_param = action.getParams().getParamValue(Filter_ongoing_changed)!= undefined;
  96. var allOngoing = changed_param && unchanged_param;
  97. var selIndex = 0;
  98. if (changed_param && !allOngoing) {
  99. selIndex = 1;
  100. } else if (unchanged_param && !allOngoing) {
  101. selIndex = 2;
  102. }
  103. document.pform.Filter_ongoing_specified_value.selectedIndex = selIndex;
  104. if (selIndex == 0) {
  105. droppy.setDropZoneValue('','Action_topic_filter');
  106. action.getParams().setParam(Action_topic_filter, null);
  107. //Should be clear by now, but clear anyway
  108. action.nonDuplication.clear();
  109. } else {
  110. var topics = action.getParams().getParamValue(Action_topic_filter);
  111. action.nonDuplication.clear();
  112. action.nonDuplication.parseFromString(topics);
  113. }
  114. //new and stopped
  115. document.pform.Filter_new.checked = action.getParams().getParamValue(Filter_new) != undefined;
  116. document.pform.Filter_nil.checked = action.getParams().getParamValue(Filter_no_events) != undefined;
  117. document.pform.Filter_deleted.checked = action.getParams().getParamValue(Filter_stopped) != undefined;
  118. document.pform.Filter_ongoing_group.checked = allOngoing || changed_param || unchanged_param;
  119. document.pform.main_radio_group[0].checked = action.runCondition != "runOnFailure";
  120. document.pform.main_radio_group[1].checked = action.runCondition == "runOnFailure";
  121. document.getElementById('event_rules_table').disabled = action.runCondition == "runOnFailure";
  122. updateTaskLevelFilter(action.taskLevelFilter);
  123. changeTaskLevelFilterState();
  124. changeOngoingActionDetails(document.pform.Filter_ongoing_group.checked, selIndex);
  125. }
  126. function checkTheBox(box){
  127. var box_value = box.checked ? box.value : null;
  128. if (box.name == Filter_ongoing_group && box.checked) {
  129. document.pform.Filter_ongoing_specified_value.selectedIndex = 0;
  130. } else {
  131. getSelectedAction().setParam(box.name, box_value);
  132. }
  133. var cf = window.parent.getConfigFrame();
  134. if ( cf != null ) {
  135. // set agent state
  136. cf.agentHasChanged(true);
  137. }
  138. }
  139. function displayState(){
  140. if (!window.event.altKey){
  141. return;
  142. }
  143. var an_action = document.pform.ad_select_display.selectedIndex == -1 ? parent.getAgentDefinition().getActionAt(0) : parent.getAgentDefinition().getActionAt(document.pform.ad_select_display.selectedIndex);
  144. var buffer = "agent filter state for "+ an_action.name +"\n";
  145. buffer += "Summary_Event_Key = " + parent.getAgentDefinition().summaryEventKey.toString()+"\n";
  146. buffer += "Filter_ongoing_changed = " + an_action.getParams().getParamValue(Filter_ongoing_changed)+"\n";
  147. buffer += "Filter_ongoing_unchanged = " + an_action.getParams().getParamValue(Filter_ongoing_unchanged)+"\n";
  148. buffer += "Filter_new = " + an_action.getParams().getParamValue(Filter_new)+"\n";
  149. buffer += "Filter_no_events = " + an_action.getParams().getParamValue(Filter_no_events)+"\n";
  150. buffer += "Filter_stopped = " + an_action.getParams().getParamValue(Filter_stopped)+"\n";
  151. buffer += "Action_topic_filter = " + an_action.getParams().getParamValue(Action_topic_filter)+"\n";
  152. alert(buffer);
  153. }
  154. function changeOngoingActionDetails(checked, selIndex) {
  155. document.pform.Filter_ongoing_specified_value.disabled = !checked;
  156. if (selIndex == 0) {
  157. disableActionTopics();
  158. } else {
  159. enableActionTopics();
  160. }
  161. }
  162. function storeOngoingActionDetails() {
  163. var allOngoing = document.pform.Filter_ongoing_specified_value.selectedIndex == 0;
  164. var changed = document.pform.Filter_ongoing_specified_value.selectedIndex == 1;
  165. var unchanged = document.pform.Filter_ongoing_specified_value.selectedIndex == 2;
  166. if(allOngoing){
  167. getSelectedAction().getParams().setParam(Action_topic_filter, null);
  168. getSelectedAction().nonDuplication.clear();
  169. //Droppy should be available in the suppression Wizard.xts scripts.
  170. droppy.setDropZoneValue('','Action_topic_filter');
  171. parent.getAgentItemsListener().updateField(Action_topic_filter, "");
  172. }
  173. //all is selected set to ongoing changed or unchanged topic filter
  174. getSelectedAction().setParam(Filter_ongoing_changed,allOngoing || changed?Changed:null);
  175. getSelectedAction().setParam(Filter_ongoing_unchanged,allOngoing || unchanged?Unchanged:null);
  176. var cf = window.parent.getConfigFrame();
  177. if ( cf != null ) {
  178. // set agent state
  179. cf.agentHasChanged(true);
  180. }
  181. }
  182. function getSelectedAction(){
  183. var sel = document.pform.ad_select_display;
  184. var selected_id = sel.options[sel.selectedIndex].value;
  185. return parent.getAgentDefinition().getActionById(selected_id);
  186. }
  187. function selectActionImage(action){
  188. document.images.action_img.src = action.img_src;
  189. }
  190. function addActionToPage(action){
  191. var display = pad(action.name, action.type, 40);
  192. document.pform.ad_select_display.options[document.pform.ad_select_display.length] = new Option(display, action.name_id);
  193. //document.pform.Action_topic_filter.value = action.getParams().getParamValue(Action_topic_filter);
  194. var sTopics = action.getParams().getParamValue(Action_topic_filter);
  195. action.nonDuplication = new parent.NonDuplicationItems(sTopics);
  196. }
  197. function pad(sName, sType, length){
  198. var display_name = sName.length > MAX_TASK_NAME_LENGTH ? sName.substring(0, MAX_TASK_NAME_LENGTH) + "..." : sName;
  199. var l = length < MAX_TASK_NAME_LENGTH ? length : MAX_TASK_NAME_LENGTH;
  200. for(var v = sName.length; v < l; v++){
  201. sName = sName + " ";
  202. }
  203. display_name = display_name + " (" + sType +")"
  204. return display_name;
  205. }
  206. function onAddAction(){
  207. var action = getActionFromPage();
  208. if(!action){
  209. return;
  210. }
  211. if(parent.getAgentDefinition().addAction(action)){
  212. addActionToPage(action);
  213. }else{
  214. alert("must have unique name");
  215. }
  216. }
  217. function onRemoveAction(){
  218. parent.getAgentDefinition().removeActionAt(document.pform.ad_select_display.selectedIndex);
  219. removeActionFromPage();
  220. }
  221. /*
  222. write out our definitions to form fields
  223. */
  224. function writeActions (agent, div){
  225. //get the summary event key and make sure its valid
  226. var converted_key = agent.getSummaryEventKeyValueWithPortalStyleTopics();
  227. // always write out the information for the summary_event_key
  228. setHiddenField(AGENT_PARAM + "_" + "Summary_event_key", converted_key , div);
  229. // only do the others if we have actions.
  230. if (agent.getActionCount() > 0) {
  231. //write out stuff for each action
  232. for(var i = 1; i <= agent.getActionCount(); i++){
  233. var an_action = agent.getActionAt(i - 1);
  234. //first write in the marker for the action
  235. setHiddenField(ACTION_MARKER, ACTION_NAME + "_" + i , div);
  236. setHiddenField(makeActionName(ACTION_NAME_NAME, i), an_action.name, div);
  237. setHiddenField(makeActionName(ACTION_ID_NAME, i), an_action.id, div);
  238. setHiddenField(makeActionName(ACTION_TASK_LEVEL_FILTER, i), an_action.taskLevelFilter, div);
  239. setHiddenField(makeActionName(ACTION_RUN_CONDITION, i), an_action.runCondition, div);
  240. var action_params = an_action.getParams();
  241. for(var param_index = 0; param_index < action_params.getParamCount(); param_index++){
  242. var param = action_params.getParamAt(param_index);
  243. //if this has topics in it they are converted to portal style
  244. var converted_param_value = param.getPortalStyleValue();
  245. setHiddenField(makeActionName("PARAM_" + param.param_name, i), converted_param_value, div);
  246. }
  247. }
  248. }
  249. }
  250. function makeActionName(name, index){
  251. return ACTION_NAME + "_" + index + "_" + name;
  252. }
  253. /**
  254. * private function to write out a hidden form field value
  255. */
  256. function setHiddenField(field_name, value, div){
  257. var hidden_input = "<input type=\"hidden\" name=\""+field_name+"\" value=\""+value+"\"/>";
  258. var divObject = document.getElementById(div);
  259. //write hidden form fields to the supplied div... this may be browser specific
  260. divObject.innerHTML = divObject.innerHTML + hidden_input;
  261. }