agentItemsListenerObjects.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. //represents a form field... name and value
  11. function FieldContent(fieldName, id, fieldContent){
  12. this.fieldName = fieldName;
  13. this.fieldContent = fieldContent?fieldContent:'';
  14. this.topics = new Array();
  15. this.parameters = new Array();
  16. this.id = id;
  17. }
  18. //bung in another param
  19. FieldContent.prototype.setContent = function(fieldContent){
  20. this.fieldContent = fieldContent;
  21. }
  22. //bung in another param
  23. FieldContent.prototype.getContent = function(){
  24. return this.fieldContent;
  25. }
  26. //bung in another param
  27. FieldContent.prototype.addParameter = function(parameter){
  28. this.parameters.push(parameter);
  29. }
  30. //returns an array of strings, which are the topics (sorry... model items)
  31. FieldContent.prototype.getTopics = function(){
  32. return this.topics;
  33. }
  34. //add a topic to this fields topic array
  35. FieldContent.prototype.addTopic = function(topic){
  36. this.topics.push(topic);
  37. }
  38. //add a topic to this fields topic array
  39. FieldContent.prototype.removeTopic = function(topic){
  40. var new_topics;
  41. for(var i = 0; i < this.topics.length; i++){
  42. if(this.topics[i] != topic){
  43. new_topics.push(this.topics[i]);
  44. }
  45. }
  46. this.topics = new_topics;
  47. }
  48. //is a topic in this fields topic array
  49. FieldContent.prototype.containsTopic = function(topic){
  50. var contains = false;
  51. for(var i = 0; i < this.topics.length; i++){
  52. if(this.topics[i] == topic){
  53. contains = true;
  54. break;
  55. }
  56. }
  57. return contains;
  58. }
  59. //returns an array of strings, which are the parameters
  60. FieldContent.prototype.getParameters = function(){
  61. return this.parameters;
  62. }
  63. //returns an array of strings, which are the removed parameters
  64. //assumes that there is an updated content
  65. FieldContent.prototype.checkForRemovedParameters = function(){
  66. var removed = new Array();
  67. var retained = new Array();
  68. for(var i = 0; i < this.parameters.length; i++){
  69. if(!this.fieldContent || this.fieldContent.indexOf(this.parameters[i]) == -1){
  70. //we dont got this puppy no more
  71. removed.push(this.parameters[i]);
  72. }else{
  73. retained.push(this.parameters[i]);
  74. }
  75. }
  76. this.parameters = retained;
  77. return removed;
  78. }
  79. //returns an array of strings, which are the removed topics
  80. //assumes that there is an updated content
  81. FieldContent.prototype.checkForRemovedTopics = function(){
  82. var removed = new Array();
  83. var retained = new Array();
  84. for(var i = 0; i < this.topics.length; i++){
  85. if(!this.fieldContent || this.fieldContent.indexOf(this.topics[i]) == -1){
  86. //we dont got this puppy no more
  87. removed.push(this.topics[i]);
  88. }else{
  89. retained.push(this.topics[i]);
  90. }
  91. }
  92. this.topics = retained;
  93. return removed;
  94. }
  95. //represents a group of form fields that have names dynamically created
  96. //this is not a duplication of the normal storage of the fields
  97. // as this checks only the groupings, so that any dynamic deletions will be covered
  98. // I've only allowed for one dynamic field group per task id, ok for now
  99. function DynamicFieldGroup(fieldContents, groupId){
  100. this.groupId = groupId;
  101. this.fieldContents = fieldContents;
  102. }
  103. //any fields that are no longer present are treated as removed and the topic refereences
  104. //are ditched
  105. DynamicFieldGroup.prototype.update = function(){
  106. var current_dfg = getAgentItemsListener().dynamic_field_group[this.groupId];
  107. //now remove any removed fields from the group... no need to additions or updates as these are handled by the normal register field
  108. for(var old_contents_index = 0; old_contents_index < current_dfg.fieldContents.length; old_contents_index++){
  109. var found = false;
  110. for(var new_contents_index = 0; new_contents_index < this.fieldContents.length; new_contents_index++){
  111. if(this.fieldContents[new_contents_index].fieldName == current_dfg.fieldContents[old_contents_index].fieldName){
  112. //this is in the old and the new
  113. found = true;
  114. break;
  115. }
  116. }
  117. if(!found){
  118. //this is an old that is not in the new... destroy (this will remove references)
  119. getAgentItemsListener().removeField(current_dfg.fieldContents[old_contents_index].fieldName, current_dfg.fieldContents[old_contents_index].id);
  120. }
  121. }
  122. }
  123. /*
  124. * take a field name and topics array and parses them for a parameter name and a topic
  125. */
  126. function ParameterAssignment(fieldName, topicName){
  127. if(fieldName){
  128. var name = fieldName.match(/pv_dz_(.*)_pv_dz/);
  129. this.parameterName = name ? name[1] : "";
  130. }
  131. var topicMatch = topicName.match(/\[(.*)\]/);
  132. this.topic = topicMatch.length > 0 ? topicMatch[1] : topicMatch[0];
  133. }
  134. function ReportTaskAssignments(id, name, path){
  135. this.taskId = id;
  136. this.reportName = name;
  137. this.reportPath = path;
  138. this.parameterAssignments = new Array();
  139. this.toString = function(){
  140. return "Report Tasks " + this.taskId + ": " + this.reportPath;
  141. }
  142. this.containsTopic = function(topic){
  143. for(var i = 0; i < this.parameterAssignments.length; i++){
  144. if(topic && topic == this.parameterAssignments[i].topic){
  145. return true;
  146. }
  147. }
  148. return false;
  149. }
  150. }