124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
itemController.setListID(this.listID);
itemController.setListItemID(this.nextItemID);
itemController.setListModel(listModel);
this.nextItemID++;
itemController.createElement(document, this.containerElement);
itemController.drawed();
this.itemControllers[i] = itemController;
}
listModel.addListener(this);
};
/**
|
>
>
>
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
itemController.setListID(this.listID);
itemController.setListItemID(this.nextItemID);
itemController.setListModel(listModel);
this.nextItemID++;
itemController.createElement(document, this.containerElement);
itemController.drawed();
this.itemControllers[i] = itemController;
this.informListeners('listItemControllerAdded',[this,
itemController,
i]);
}
listModel.addListener(this);
};
/**
|
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
};
ListController.deleteItemEvent = function(source, item, index) {
var itemController = this.itemControllers[index];
if(itemController) {
this.itemControllers.splice(index, 1);
itemController.deleted();
this.showOrHideZeroLengthElement();
}
};
/**
* React to 'insertBefore' event coming from model.
|
>
>
|
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
};
ListController.deleteItemEvent = function(source, item, index) {
var itemController = this.itemControllers[index];
if(itemController) {
this.itemControllers.splice(index, 1);
itemController.deleted();
this.informListeners('listItemControllerDeleted',
[this, itemController]);
this.showOrHideZeroLengthElement();
}
};
/**
* React to 'insertBefore' event coming from model.
|
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
/*console.log(this.containerElement);*/
itemController.createElement(document, this.containerElement);
this.itemControllers.push(itemController);
}
itemController.setListModel(this.model);
itemController.drawed();
/*console.log("insertBeforeEvent - itemControllers.length: " +
this.itemControllers.length);*/
this.showOrHideZeroLengthElement();
};
|
>
>
>
>
|
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
/*console.log(this.containerElement);*/
itemController.createElement(document, this.containerElement);
this.itemControllers.push(itemController);
}
itemController.setListModel(this.model);
itemController.drawed();
this.informListeners('listItemControllerAdded',[this,
itemController,
index]);
/*console.log("insertBeforeEvent - itemControllers.length: " +
this.itemControllers.length);*/
this.showOrHideZeroLengthElement();
};
|
976
977
978
979
980
981
982
|
/**
* Get the item model for the given 'itemNumber' (an index into the item list).
*/
ListModel.getItemModel = function(itemNumber) {
return this.items[itemNumber];
};
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
|
/**
* Get the item model for the given 'itemNumber' (an index into the item list).
*/
ListModel.getItemModel = function(itemNumber) {
return this.items[itemNumber];
};
/** ***********************************************************************
* implements a list with filtering of its items
**************************************************************************/
var FilteredListModel = clone(ListModel);
/**
* abstract method to determine if an item must be included. The method returns
* true to include item (in same fashion as django does).
*
* @param {Object} item the item to evaluate
* @return {Boolean} true if the item should be included
*/
FilteredListModel._applyFilter = function(item){
return this.filterFn(item);
};
FilteredListModel.filterFn = function(item){
return true;
}
/**
* takes all the items from a list model and applies filter over them. Makes
* the items for the filtered list the ones that match the filter
* function.
*
* @param {ListModel} listModel list model to filter
*/
FilteredListModel._setItemsFromListModel = function(listModel){
var i, len, item;
// make the filtering
this.items = [];
for (i=0,len=listModel.getLength(); i<len; i++){
item = listModel.getItemModel(i);
if (this._applyFilter(item)===true){
this._pushObject(item);
}
}
this.informListeners("resetEvent", [this]);
};
/**
* sets the list model to filter
*/
FilteredListModel.setListModel = function(listModel){
var me = this;
if (this._listModel){
this.unsetListModel();
}
this._listModel = listModel;
this._setItemsFromListModel(listModel);
this._listModelListeners = {
resetEvent:function(listModel){
me._setItemsFromListModel(listModel);
},
insertBeforeEvent: function(listModel, model, index){
var lastItem=null, newIndex, i, len;
if (me._applyFilter(model)===true){
// find the position in the filtered array
// if the model is added at the end
if (index == (listModel.getLength() - 1)){
me._pushObject(model);
return;
}else if (index <= 0){
// if the index points to the first position,
// add it at the beginning
me._insertObjectBefore(model, 0);
return;
}
newIndex = index - 1;
lastItem = listModel.getItemModel(newIndex);
while (me._applyFilter(lastItem)!==true && newIndex>0){
newIndex--;
lastItem = listModel.getItemModel(newIndex);
}
// if the index points to the first position,
// add it at the beginning
if (newIndex === 0){
me._insertObjectBefore(model, 0);
return;
}
// finally find the index in the current array for the found
// item and add it after it (i + 1).
for (i=0, len=me.items.length; i<len; i++){
if (lastItem == me.items[i]){
me._insertObjectBefore(model, i+1);
break;
}
}
}
},
deleteItemEvent: function(listModel, model, index){
var i,len;
for (i=0, len=me.items.length; i<len; i++){
if (model == me.items[i]){
me._deleteIndex(i);
break;
}
}
}
};
this._listModel.addListener(this._listModelListeners);
};
FilteredListModel.unsetListModel = function(){
if (this._listModel){
this._listModel.removeListener(this._listModelListeners);
this._listModel = null;
}
};
//override
FilteredListModel._insertObjectBefore = function(model, index) {
this.items.splice(index, 0, model);
this.informListeners("insertBeforeEvent", [this, model, index]);
return model;
};
//override
FilteredListModel._pushObject = function(model) {
this.items.push(model);
this.informListeners("insertBeforeEvent",
[this, model, this.items.length-1]);
return model;
};
FilteredListModel._deleteIndex = FilteredListModel.deleteIndex;
FilteredListModel.throwReadOnlyError = function(){
throw Error("Method not available in read only FilteredListModel instance");
};
FilteredListModel.pushObject = FilteredListModel.throwReadOnlyError;
FilteredListModel.setItemsFromArray = FilteredListModel.throwReadOnlyError;
FilteredListModel.insertObjectBefore = FilteredListModel.throwReadOnlyError;
FilteredListModel.deleteItem = FilteredListModel.throwReadOnlyError;
FilteredListModel.deleteIndex = FilteredListModel.throwReadOnlyError;
/** ***********************************************************************
* implements a list with exclusion of its items
**************************************************************************/
var ExcludedListModel = clone(FilteredListModel);
ExcludedListModel._applyFilter = function(item){
return !this.excludeFn(item);
};
ExcludedListModel.excludeFn = function(item){
return true;
};
|