Blame view

js/app/views/TimeTableOperationUI.js 11.7 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
/**
 * Project   : AMDA-NG
 * Name      : TimeTableOperationUI.js
 * @class 	 amdaUI.TimeTableOperationUI
 * @extends  Ext.container.Container
 * @brief	 Time Table Operations Module UI definition (View)
 * @author 	 Myriam
 * @version  $Id: TimeTableOperationUI.js 1937 2013-11-27 14:42:41Z myriam $
16035364   Benjamin Renard   First commit
9
10
11
12
13
14
15
16
17
18
19
 */

Ext.define('amdaUI.TimeTableOperationUI', {
	extend: 'Ext.container.Container',
	alias: 'widget.panelTtsOpe',

	constructor: function(config) {			
		this.init(config);
		this.callParent(arguments);
	},

aa23703f   Benjamin Renard   Fix TT operation ...
20
	addTT : function(newTTName,newTTid,nodeType) {
16035364   Benjamin Renard   First commit
21
22
23
24
25
		// search for an existing record in store with this unique name
        var existingIndex = this.TTGrid.store.findExact( 'name', newTTName);
        // if no corresponding TT found
        if (existingIndex == -1){
            // adding the time table to the TTGrid of TT download 
aa23703f   Benjamin Renard   Fix TT operation ...
26
            var r = Ext.create('amdaModel.TTobject', { id: newTTid, name: newTTName, nodeType: nodeType});
16035364   Benjamin Renard   First commit
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
            this.TTGrid.store.insert(this.TTGrid.store.getCount(),r);   
        }  
	}, 

	findValidName : function(originalName, crtIndex, module, onValidName){
		if (module == null)
			return;
		
		if (originalName == "")
			return;
		
		originalName = originalName.replace(" ", "_");
		
		var crtName = originalName;
		if (crtIndex > 0)
			crtName = originalName + "_" + crtIndex;
		
		var me = this;
		
        module.linkedNode.isValidName(crtName, function (res) {
    		if (!res)
    			return;
    			
    		if (res.valid)
    		{
    			//
    			onValidName(crtName);
    			return;
    		}
    			
    		//If name is not valid, increment the index and test the new name
    		++crtIndex;
    		me.findValidName(originalName, crtIndex, module, onValidName);
    			
    	});
	},

	/**
	 * 
	 * this method will be used on timetableOperation edition when this win is already opened
	 */
	setObject : function () {
	},

	/**
	 * Check if changes were made before closing window 
	 * @return false
	 */	
	fclose : function() {
		return false;
	},
	
	init : function(config) {    

	    var store = Ext.create('Ext.data.Store', {
	        model: 'amdaModel.TTobject'	
	    });

        this.TTGrid = Ext.create('Ext.grid.Panel', {
        	anchor: '80% 85%',
            itemId: 1,
            store : store,  
            columns: [ 
                Ext.create('Ext.grid.RowNumberer', { width: 20 } ),
                { header: "Time Table Name", dataIndex: 'name', flex:1, sortable : false },
                { 
                    width: 30, renderer: function(){
                        return'<div class="icon-remover" style="width: 15px; height: 15px;"></div>';
                    }
                }
            ]
		,
	    listeners :
		{
		  render : function(o,op)
		  {
		    var me = this;
		    var el = me.body.dom;
		    var dropTarget = Ext.create('Ext.dd.DropTarget', el, {
		        ddGroup: 'explorerTree',
		        notifyEnter : function(ddSource, e, data) 
		        {
		    	  
		        },
		        notifyOver  : function(ddSource, e, data)
		        {
63057027   Hacene SI HADJ MOHAND   6163
113
		        	if ((data.records[0].data.nodeType == 'timeTable' || data.records[0].data.nodeType == 'sharedtimeTable' ) && (data.records[0].data.leaf))
16035364   Benjamin Renard   First commit
114
115
116
117
118
119
120
121
122
123
124
125
126
127
		        	{
		        	  this.valid = true;
		        	  return this.dropAllowed;
		        	}
		        	this.valid = false;
		        	return this.dropNotAllowed;
		        },
		        notifyDrop  : function(ddSource, e, data)
		        {
		          if (!this.valid)
		            return false;
		          var timeTableOperationModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt_op.id);
		          if (!timeTableOperationModule)
		        	  return false;
aa23703f   Benjamin Renard   Fix TT operation ...
128
		          timeTableOperationModule.getUiContent().addTT(data.records[0].get('text'),data.records[0].get('id'), data.records[0].get('nodeType'));
16035364   Benjamin Renard   First commit
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
		          return true;
		        }
		    });
		  }
		}
        });		
        this.TTGrid.on('cellclick', function(view, cell, cellIndex, record, row, recordIndex, e){
            if (cellIndex == 2)
            	    this.TTGrid.getStore().remove(record);
        },this);
        

		var myConf = {
		    layout: 'border',
		    defaults: { layout: 'fit', border: false },
			items: [
			  {
				 xtype: 'form',
                 region: 'center',
                 buttonAlign: 'left',
                 bodyStyle: {background : '#dfe8f6'},
                 padding: '5 5 5 5',
                 layout: {type: 'vbox', pack: 'start', align: 'stretch'},	
                 items: [ 
			        {xtype: 'splitter', height: 15},
                    {						        	        	        	
                        xtype: 'container',
                        border: false,
                        padding: '0 0 5 5',
                        flex: 4,					
                        layout: 'fit',
                        items: [ this.TTGrid ] 					        	        
                    }			        
			        ],            	
			        fbar: [
			               {
			            	   text: 'Merge',
			            	   scope: this,
			            	   handler: function(){
				            	   	if (this.TTGrid.getStore().count()==0) {
				            	   		Ext.Msg.show({title: "Time Table Operations", msg: "Please select at least one time table", icon: Ext.MessageBox.WARNING, buttons: Ext.Msg.OK});
				            	   		return;
				            	   	}
			            	   		var tts = this.TTGrid.getStore().data.items;
			            	   		var ttids = [];
			            	   		var name= "";
			            	   		Ext.each(tts, function(tt, index) {
aa23703f   Benjamin Renard   Fix TT operation ...
176
			            	   			ttids[index] = {'id': tt.data.id, 'nodeType' : tt.data.nodeType};
16035364   Benjamin Renard   First commit
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
			            	   			name = name + tt.data.name + " ";
			            	   		});
			            	   		// Time table's name and history field
			            	        if ( ttids.length == 1 ) {
			                       		var newTabName = tts[0].data.name + "_M";
			                       		var history = "Merged intervals from "+name;
			                    	} else if ( ttids.length == 2 ) {
			                       		var newTabName = tts[0].data.name + "_M_" + tts[1].data.name;
			                       		var history = "Union between "+ name;
			                    	}	
			                    	else {
			                       		var newTabName = ttids.length + "_tables_M";			                       		
			                       		var history = "Union between " + name;
			                    	}

			            	        var me = this;
			            	        myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt_op.id, true, function (module) {
			            	        	
				            	        
				            	        me.findValidName(newTabName, 0, module, function (validName) {
				            	        	AmdaAction.merge({ids:ttids, name:validName, history:history},function(result, e){		
					            	   			var t = e.getTransaction();
					            	   			if (e.status) {	
					            	   				// SUCCESS  
					            	   				if (result && !result.error) {
					            	   					module.linkedNode.set('id',result.id);
					            	   					module.linkedNode.set('text', validName);
					            	   					module.linkedNode.set('object',null);
					            	   					module.linkedNode.set('info',result.info);
					            	   					module.linkedNode.getRootNode().appendChild(module.linkedNode);
					            	   					module.linkedNode.editLeaf();
					            	   				} else {
					            	   					// EXCEPTION : 
					            	   					Ext.Msg.show({title: "Time Table Operations", msg: t.action + "." + t.method + " : " + e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
					            	   				}
					            	   			}
					            	   			else
					            	   			{
					            	   				// FAILURE
					            	   				Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
					            	   			}   
					            	   		},this); 
				            	        	
				            	        	// New node for another operation
					            	        module.createLinkedNode();
					            	       
				            	        });
			            	        });  
			               		}  
			               },
			               {
			            	   text: 'Intersect',
			            	   scope: this,
			            	   handler: function(){
				            	   	if (this.TTGrid.getStore().count()!==2) {
				            	   		Ext.Msg.show({title: "Time Tables Operations", msg: "Intersection is only available for 2 tables", icon: Ext.MessageBox.WARNING, buttons: Ext.Msg.OK});
				            	   		return;
				            	   	}
				            	   	var tts = this.TTGrid.getStore().data.items;
			            	   		var ttids = [];
			            	   		Ext.each(tts, function(tt, index) {
aa23703f   Benjamin Renard   Fix TT operation ...
238
			            	   			ttids[index] = {'id': tt.data.id, 'nodeType': tt.data.nodeType};
16035364   Benjamin Renard   First commit
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
			            	   		});
			            	   		// Time table's name and history field
			            	   		var newTabName = tts[0].data.name + "_I_" + tts[1].data.name;
			            	   		var history = "Intersection between "+ tts[0].data.name + " and " + tts[1].data.name;
			            	        
			            	   		var me = this;
			            	        myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.tt_op.id, true, function (module) {
			            	        	
				            	        
			            	        	me.findValidName(newTabName, 0, module, function (validName) {
				            	        	AmdaAction.intersect({ids:ttids, name:newTabName, history:history},function(result, e){		
					            	   			var t = e.getTransaction();
					            	   			if (e.status) {	
					            	   				// SUCCESS  
					            	   				if (result && !result.error) {
					            	   					if ( result  == "empty" ) Ext.Msg.show({title: "Time Tables Operations", msg: "The intersection of these tables is empty ", icon: Ext.MessageBox.WARNING, buttons: Ext.Msg.OK});
					            	   					else {
					            	   						module.linkedNode.set('id',result.id);
					            	   						module.linkedNode.set('text', validName);
					            	   						module.linkedNode.set('object',null);
					            	   						module.linkedNode.set('info',result.info);
					            	   						module.linkedNode.getRootNode().appendChild(module.linkedNode);
					            	   						module.linkedNode.editLeaf();
					            	   					}
					            	   				} else {
					            	   					// EXCEPTION : 
					            	   					Ext.Msg.show({title: "Time Tables Operations", msg: t.action + "." + t.method + " : " + e.message, icon : Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
					            	   				}
					            	   			}
					            	   			else
					            	   			{
					            	   				// FAILURE
					            	   				Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
					            	   			}   
					            	   		},this); 
				            	        	
				            	        	// New node for another operation
					            	        module.createLinkedNode();
					            	        
				            	        });
			            	        });   
			               	  }
			               }
			              ]
               },                            
               {
42863f42   Elena.Budnik   collapseMode: "he...
285
286
287
288
289
290
291
292
293
294
295
296
297
298
						xtype: 'panel',
						title: 'Information',
						region: 'south',
						height: 100,
						collapsible: true,
						collapseMode: 'header',
						layout: 'fit',
						autoHide: false,
						iconCls: 'icon-information',
						bodyStyle: 'padding:5px',
						loader: {
							autoLoad: true,
							url: helpDir+'ttOperationsHOWTO'
						}
16035364   Benjamin Renard   First commit
299
300
301
302
303
304
305
               }
            ]   
		};

		Ext.apply (this , Ext.apply (arguments, myConf));     

	}
63057027   Hacene SI HADJ MOHAND   6163
306
});