var makeLinkedList = function() { /* * Creates an object with its * prototype referencing * methodsOfLinkedList */ var instanceOfLinkedList = Object.create(methodsOfLinkedList); /* * Sets the initial head of a * list to null */ instanceOfLinkedList.head = null; /* * Sets the initial tail of a * list to null */ instanceOfLinkedList.tail = null; /* * Returns an instance of a * linked list */ return instanceOfLinkedList; }; var methodsOfLinkedList = { add: function(value) { /* * Creates a new instance of a * node. */ var newNode = makeNode(value); /* * If the list is empty, * then assign the new node * as the head of the list. */ if (!this.head) { this.head = newNode; } /* * If the list contains a * tail, then assign the new * node as the next node in * the list. */ if (this.tail) { this.tail.next = newNode; } /* * Assigns the new node as the * tail of the list. */ newNode.prev = this.tail; this.tail = newNode; }, insertAfter: function(value, afterValue) { /* * Creates a new instance of a * node. */ var newNode = makeNode(value); var afterNode = this.getNode(afterValue) if(afterNode){ newNode.next = afterNode.next; newNode.prev = afterNode; afterNode.next = newNode; if(!newNode.next){ /* * Assigns the new node as the * tail of the list. */ this.tail = newNode; } } /* * If the list is empty, * then assign the new node * as the head of the list. */ if (!this.head) { this.head = newNode; /* * Assigns the new node as the * tail of the list. */ this.tail = newNode; } }, insertListAfter: function(newList, afterValue) { if(!newList.head){ return; } var afterNode = this.getNode(afterValue) /* * If the list is empty, * then assign the new node * as the head of the list. */ if (!this.head) { this.head = newList.head; /* * Assigns the new node as the * tail of the list. */ this.tail = newList.tail; }else{ if(!afterNode.next){ this.tail = newList.tail; }else{ newList.tail.next = afterNode.next; } afterNode.next = newList.head; if(newList.head){ newList.head.prev = afterNode; } } }, insertBefore: function(value, beforeValue) { /* * Creates a new instance of a * node. */ var newNode = makeNode(value); var beforeNode = this.getNode(beforeValue) if(beforeNode){ var prevNode = newNode.next = beforeNode; newNode.prev = beforeNode.prev; beforeNode.prev = newNode; if(!newNode.prev){ /* * Assigns the new node as the * tail of the list. */ this.head = newNode; }else{ newNode.prev.next = newNode; } } /* * If the list is empty, * then assign the new node * as the head of the list. */ if (!this.head) { this.head = newNode; /* * Assigns the new node as the * tail of the list. */ this.tail = newNode; } }, insertListBefore: function(newList, beforeValue) { if(!newList.head){ return; } var beforeNode = this.getNode(beforeValue) /* * If the list is empty, * then assign the new node * as the head of the list. */ if (!this.head) { this.head = newList.head; /* * Assigns the new node as the * tail of the list. */ this.tail = newList.tail; }else{ if(!beforeNode.prev){ this.head = newList.head; } beforeNode.prev = newList.tail; if(newList.tail){ newList.tail.next = beforeNode; } } }, remove: function() { /* * Creates a variable that * references the current * head of a list. */ var currentNode = this.head; /* * Assigns the head of the * list to the node next to * the current head. */ this.head = currentNode.next; if(this.head){ this.head.prev = null; } /* * Sets the initial head of * the list to null. */ currentNode = null; }, removeNode: function(value) { var deleteNode = this.getNode(value); if(!deleteNode){ return null; } if(deleteNode == this.head){ this.head = this.head.next; if(!this.head){ this.tail = null; }else{ this.head.prev = null; } return deleteNode.data; } if(deleteNode == this.tail){ this.tail = this.tail.prev; this.tail.next = null; return deleteNode.data; } var prevNode = deleteNode.prev; var nextNode = deleteNode.next; prevNode.next = nextNode; nextNode.prev = prevNode; return deleteNode.data; }, contains: function(value) { /* * Creates a variable that * references the current * head of a list. */ var currentNode = this.head; /* * Continues iteration while * there is a node in the * list. */ while (currentNode) { /* * If the current node matches * the target value, then * return true. */ if (currentNode.data === value) { return true; } /* * Assigns currentNode to * reference the next node * in the list. */ currentNode = currentNode.next; } /* * Returns false if there are * no matches in the list. */ return false; }, getNode: function(value) { /* * Creates a variable that * references the current * head of a list. */ var currentNode = this.head; /* * Continues iteration while * there is a node in the * list. */ while (currentNode) { /* * If the current node matches * the target value, then * return true. */ if (currentNode.data === value) { return currentNode; } /* * Assigns currentNode to * reference the next node * in the list. */ currentNode = currentNode.next; } /* * Returns false if there are * no matches in the list. */ return this.tail; } }; var makeNode = function(value) { /* * Creates an object with the * two properties of a node. */ var instanceOfNode = { data: value, prev: null, next: null }; /* * Returns an instance of a * node. */ return instanceOfNode; }; var createFormInfo = function(){ var formInfo = {}; /** * a sequence for new control id */ formInfo['ctrlIndex'] = 0; /** * a link list of all control */ formInfo['formCtrlList'] = new makeLinkedList(); /** * map from new control id to control xml * ex : formInfo['ctrlPropertiesMap'][2] = ctrlProperties object */ formInfo['ctrlPropertiesMap'] = {}; /** * map from new control id to control xml * ex : formInfo['ctrlsMap'][2] = a0.fn.a0.init[1] */ formInfo['ctrlsMap'] = {}; /** * map from parent class to new control * ex : formInfo['parentsMap']['group_loop_1'] = 2 */ formInfo['parentsMap'] = {}; /** * map from control id to new id when create form view * ex : formInfo['idsMap'][1] = {1,2,3} */ formInfo['idsMap'] = {}; return formInfo; } var addFormCtrl = function(formInfo, ctrl, ctrlPropreties){ var parrentClass = ctrlPropreties['parrentProperties']; if(!parrentClass){ parrentClass = 'data'; } var parentId = formInfo['parentsMap'][parrentClass]; if(!parentId){ var newId = formInfo['ctrlIndex']++; formInfo['parentsMap'][parrentClass] = newId; parentId = newId; var pos = parrentClass.lastIndexOf(' '); if(pos > 0){ var tmp = parrentClass.substring(0, pos); formInfo['formCtrlList'].insertBefore(newId, formInfo[tmp]); }else{ formInfo['formCtrlList'].add(newId); } } insertBeforeFormCtrl(formInfo, ctrl, ctrlPropreties, parentId); /*ctrlPropreties['newId'] = newId; formInfo['formCtrlList'].add(newId); formInfo['ctrlPropertiesMap'][newId] = ctrlPropreties; formInfo['ctrlsMap'][newId] = ctrl;*/ } var insertAfterFormCtrl = function(formInfo, ctrl, ctrlPropreties, afterId){ var newId = formInfo['ctrlIndex']++; ctrlPropreties['newId'] = newId; if(formInfo['idsMap'][ctrlPropreties.id] == undefined){ formInfo['idsMap'][ctrlPropreties.id] = []; formInfo['idsMap'][ctrlPropreties.id].push(newId); }else{ if(formInfo['idsMap'][ctrlPropreties.id].indexOf(newId) < 0){ formInfo['idsMap'][ctrlPropreties.id].push(newId); } } formInfo['formCtrlList'].insertAfter(newId, afterId); formInfo['ctrlPropertiesMap'][newId] = ctrlPropreties; formInfo['ctrlsMap'][newId] = ctrl; } var insertBeforeFormCtrl = function(formInfo, ctrl, ctrlPropreties, afterId){ var newId = formInfo['ctrlIndex']++; ctrlPropreties['newId'] = newId; if(formInfo['idsMap'][ctrlPropreties.id] == undefined){ formInfo['idsMap'][ctrlPropreties.id] = []; formInfo['idsMap'][ctrlPropreties.id].push(newId); }else{ if(formInfo['idsMap'][ctrlPropreties.id].indexOf(newId) < 0){ formInfo['idsMap'][ctrlPropreties.id].push(newId); } } formInfo['formCtrlList'].insertBefore(newId, afterId); formInfo['ctrlPropertiesMap'][newId] = ctrlPropreties; formInfo['ctrlsMap'][newId] = ctrl; } var getCtrlPropertiesByIdForCal = function(formInfo, id, calParentCtrlClass){ if(formInfo['idsMap'][id].length < 1){ return undefined; }else if(formInfo['idsMap'][id].length == 1){ return formInfo['ctrlPropertiesMap'][formInfo['idsMap'][id][0]]; }else{ for(var i=0; i params2.length){ return false; } for(var i=0; i