123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- /********************************************************************************************************************************
- * Licensed Materials - Property of IBM *
- * *
- * IBM Cognos Products: AGS *
- * *
- * (C) Copyright IBM Corp. 2005, 2008 *
- * *
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *
- *********************************************************************************************************************************/
- //represents a form field... name and value
- function FieldContent(fieldName, id, fieldContent){
- this.fieldName = fieldName;
- this.fieldContent = fieldContent?fieldContent:'';
- this.topics = new Array();
- this.parameters = new Array();
- this.id = id;
- }
- //bung in another param
- FieldContent.prototype.setContent = function(fieldContent){
-
- this.fieldContent = fieldContent;
- }
- //bung in another param
- FieldContent.prototype.getContent = function(){
-
- return this.fieldContent;
- }
- //bung in another param
- FieldContent.prototype.addParameter = function(parameter){
-
- this.parameters.push(parameter);
- }
- //returns an array of strings, which are the topics (sorry... model items)
- FieldContent.prototype.getTopics = function(){
-
- return this.topics;
- }
- //add a topic to this fields topic array
- FieldContent.prototype.addTopic = function(topic){
-
- this.topics.push(topic);
- }
- //add a topic to this fields topic array
- FieldContent.prototype.removeTopic = function(topic){
-
- var new_topics;
- for(var i = 0; i < this.topics.length; i++){
- if(this.topics[i] != topic){
- new_topics.push(this.topics[i]);
- }
- }
- this.topics = new_topics;
- }
- //is a topic in this fields topic array
- FieldContent.prototype.containsTopic = function(topic){
-
- var contains = false;
- for(var i = 0; i < this.topics.length; i++){
- if(this.topics[i] == topic){
- contains = true;
- break;
- }
- }
- return contains;
- }
- //returns an array of strings, which are the parameters
- FieldContent.prototype.getParameters = function(){
-
- return this.parameters;
- }
- //returns an array of strings, which are the removed parameters
- //assumes that there is an updated content
- FieldContent.prototype.checkForRemovedParameters = function(){
- var removed = new Array();
- var retained = new Array();
-
- for(var i = 0; i < this.parameters.length; i++){
- if(!this.fieldContent || this.fieldContent.indexOf(this.parameters[i]) == -1){
- //we dont got this puppy no more
- removed.push(this.parameters[i]);
- }else{
- retained.push(this.parameters[i]);
- }
- }
-
- this.parameters = retained;
-
- return removed;
- }
- //returns an array of strings, which are the removed topics
- //assumes that there is an updated content
- FieldContent.prototype.checkForRemovedTopics = function(){
-
- var removed = new Array();
- var retained = new Array();
-
- for(var i = 0; i < this.topics.length; i++){
- if(!this.fieldContent || this.fieldContent.indexOf(this.topics[i]) == -1){
- //we dont got this puppy no more
- removed.push(this.topics[i]);
- }else{
- retained.push(this.topics[i]);
- }
- }
-
- this.topics = retained;
- return removed;
- }
- //represents a group of form fields that have names dynamically created
- //this is not a duplication of the normal storage of the fields
- // as this checks only the groupings, so that any dynamic deletions will be covered
- // I've only allowed for one dynamic field group per task id, ok for now
- function DynamicFieldGroup(fieldContents, groupId){
- this.groupId = groupId;
- this.fieldContents = fieldContents;
- }
- //any fields that are no longer present are treated as removed and the topic refereences
- //are ditched
- DynamicFieldGroup.prototype.update = function(){
- var current_dfg = getAgentItemsListener().dynamic_field_group[this.groupId];
-
- //now remove any removed fields from the group... no need to additions or updates as these are handled by the normal register field
- for(var old_contents_index = 0; old_contents_index < current_dfg.fieldContents.length; old_contents_index++){
- var found = false;
-
- for(var new_contents_index = 0; new_contents_index < this.fieldContents.length; new_contents_index++){
- if(this.fieldContents[new_contents_index].fieldName == current_dfg.fieldContents[old_contents_index].fieldName){
-
- //this is in the old and the new
- found = true;
- break;
- }
- }
-
- if(!found){
- //this is an old that is not in the new... destroy (this will remove references)
- getAgentItemsListener().removeField(current_dfg.fieldContents[old_contents_index].fieldName, current_dfg.fieldContents[old_contents_index].id);
- }
- }
- }
- /*
- * take a field name and topics array and parses them for a parameter name and a topic
- */
- function ParameterAssignment(fieldName, topicName){
- if(fieldName){
- var name = fieldName.match(/pv_dz_(.*)_pv_dz/);
- this.parameterName = name ? name[1] : "";
- }
-
- var topicMatch = topicName.match(/\[(.*)\]/);
- this.topic = topicMatch.length > 0 ? topicMatch[1] : topicMatch[0];
-
- }
-
- function ReportTaskAssignments(id, name, path){
- this.taskId = id;
- this.reportName = name;
- this.reportPath = path;
- this.parameterAssignments = new Array();
-
- this.toString = function(){
- return "Report Tasks " + this.taskId + ": " + this.reportPath;
- }
-
- this.containsTopic = function(topic){
- for(var i = 0; i < this.parameterAssignments.length; i++){
- if(topic && topic == this.parameterAssignments[i].topic){
- return true;
- }
- }
- return false;
- }
- }
|