From 02e89fbe8c0ba131de2993b31c9b93ff12d26326 Mon Sep 17 00:00:00 2001
From: Hacene SI HADJ MOHAND <hacene.si-hadj-mohand@akka.eu>
Date: Wed, 17 Jul 2019 01:49:26 +0200
Subject: [PATCH] rm_6903 ok

---
 js/app/models/InteractiveNode.js |   2 +-
 js/app/views/CatalogUI.js        | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------
 2 files changed, 94 insertions(+), 70 deletions(-)

diff --git a/js/app/models/InteractiveNode.js b/js/app/models/InteractiveNode.js
index da9554e..1868ed7 100644
--- a/js/app/models/InteractiveNode.js
+++ b/js/app/models/InteractiveNode.js
@@ -199,7 +199,7 @@ Ext.define('amdaModel.InteractiveNode', {
 							opt.callback.call(scope,'update');
 					}
 					
-					Ext.Msg.alert('Complete', 'Object '+this.get('object').get('name')+' has been modified');
+					Ext.Msg.alert('Complete', 'Object '+this.get('object').get('name')+' has been modified',  this);
 					// fix the modifications for object
 					this.get('object').commit();
 					
diff --git a/js/app/views/CatalogUI.js b/js/app/views/CatalogUI.js
index d85e12d..d2b3282 100644
--- a/js/app/views/CatalogUI.js
+++ b/js/app/views/CatalogUI.js
@@ -116,8 +116,31 @@ Ext.define('amdaUI.CatalogUI', {
 		this.object.set('nbIntervals',this.TTGrid.getStore().getTotalCount());		
 		this.formPanel.getForm().findField('nbIntervals').setValue(this.object.get('nbIntervals'));
 	}, 
-	generateTT : function(catId){   
-                              var catObj = Ext.create('amdaModel.TimeTable');
+	generateTT : function(){   
+                         console.log(this);
+                       if(this.fclose()){
+                        Ext.Msg.confirm('Generate TT', 'Current Catalog has been modified.\nDo you want to include these changes in the generated Time Table ?' ,
+                        function (btn, text){  
+                         if (btn == 'yes'){ 
+                          // mark this.closed as true before the call to close() as that will fire the beforeclose event again
+                          if(this.object.get('id') ==""){
+                              // case of creation of catalog
+                          this.saveCatalog(true);
+                      }else{
+                          // casse existing catalog
+                          this.saveProcess(false,true);
+                      }
+                          return
+                          //win.close();
+                          } 
+                           }, this); 
+
+            }else{
+                this.createTT(this.object.get('id'));
+            }              
+                    },
+                    createTT : function(catId){
+                             var catObj = Ext.create('amdaModel.TimeTable');
                               var timeTabNode = Ext.create('amdaModel.TimeTableNode',{leaf : true});
                               catObj.set('relatedCatalogId', catId)
                               creatDate=new Date(this.object.get('created'));
@@ -133,9 +156,6 @@ Ext.define('amdaUI.CatalogUI', {
 				// edit newNode into Parameter Module with node as contextNode
 				timeTabNode.editInModule();
 			});
-                                       
-  
-                                        
                     },
 	onAfterInit:  function(result, e) 
 	{
@@ -473,7 +493,7 @@ Ext.define('amdaUI.CatalogUI', {
 	/*	    
 	 * save method called by Save button
 	 */
-	saveProcess : function(toRename)
+	saveProcess : function(toRename, onAfterSave)
 	{
 		var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);
 		//  store / columns are the same - not needed to reconfigure grid
@@ -488,7 +508,7 @@ Ext.define('amdaUI.CatalogUI', {
 			var obj = module.linkedNode.get('object');                                                    
 			// synchronisation of objects
 			this.object = obj;
-			module.linkedNode.create();
+			module.linkedNode.create({callback : function() {if (onAfterSave) this.createTT(this.object.get('id'));}, scope : this});
 		}
 		// if the name has been modified this is a creation
 		else if (this.fclose()) {         
@@ -509,13 +529,73 @@ Ext.define('amdaUI.CatalogUI', {
 					this.object = obj;
 					if (toRename) module.linkedNode.toRename = true;
 				} 
-				module.linkedNode.create({callback : function() {module.linkedNode.update();}, scope : this});
+				module.linkedNode.create({callback : function() {module.linkedNode.update({callback : function() {if (onAfterSave) this.createTT(this.object.get('id'));}, scope : this});}, scope : this});
 			} else {
 				//update				
-				module.linkedNode.update();
+				module.linkedNode.update({callback : function() {if (onAfterSave) this.createTT(this.object.get('id'));}, scope : this});
 			}	
 		}
 	},
+        saveCatalog : function (onAfterSave){
+            if (this.updateObject())
+                {
+                        var basicForm = this.formPanel.getForm();      
+                        // if there's at least one record in the store of TTGrid
+                        if (this.TTGrid.getStore().getTotalCount() > 0) 
+                        {
+                                // update TimeTable object which the content of form
+                                basicForm.updateRecord(this.object);
+
+                                var me = this;
+                                this.checkIntervalsStatusForSave(function () {
+                                        //Name validation
+                                        var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);	
+
+                                        if (!module) return;
+                                        module.linkedNode.isValidName(me.fieldName.getValue(), function (res) 
+                                        {
+                                                if (!res) {
+                                                        me.fieldName.validFlag = 'Error during object validation';
+                                                        myDesktopApp.errorMsg(me.fieldName.validFlag);
+                                                        me.fieldName.validate();
+                                                        return;
+                                                }
+
+                                                if (!res.valid) {
+                                                        if (res.error) {
+                                                                if (res.error.search('subtree') != -1) {  							
+                                                                        Ext.MessageBox.show({title:'Warning', 
+                                                                                msg: res.error+'<br/>Do you want to overwrite it?',
+                                                                                width: 300,
+                                                                                buttons: Ext.MessageBox.OKCANCEL, 
+                                                                                fn : me.overwriteProcess,
+                                                                                icon: Ext.MessageBox.WARNING,
+                                                                                scope : me
+                                                                        });
+                                                                        me.fieldName.validFlag = true;
+                                                                }
+                                                                else
+                                                                        me.fieldName.validFlag = res.error;
+                                                        }
+                                                        else {
+                                                                me.fieldName.validFlag = 'Invalid object name';
+                                                                myDesktopApp.errorMsg(me.fieldName.validFlag);
+                                                        }
+                                                        me.fieldName.validate();
+                                                        return;
+                                                }
+
+                                                me.fieldName.validFlag = true;
+                                                me.fieldName.validate();
+                                                me.saveProcess(false, onAfterSave);
+                                        });
+                                });                            
+                        } 
+                        else {
+                                Ext.Msg.alert('No intervals', 'Your catalog is invalid, <br>you must have at least one interval');
+                        }
+                }
+        },
 	
 	/**
 	 * overwrite metod called by Save button
@@ -767,64 +847,8 @@ Ext.define('amdaUI.CatalogUI', {
 							scope : this,
 							handler: function () 
 							{
-								if (this.updateObject())
-								{
-									var basicForm = this.formPanel.getForm();      
-									// if there's at least one record in the store of TTGrid
-									if (this.TTGrid.getStore().getTotalCount() > 0) 
-									{
-										// update TimeTable object which the content of form
-										basicForm.updateRecord(this.object);
-
-										var me = this;
-										this.checkIntervalsStatusForSave(function () {
-											//Name validation
-											var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.catalog.id);	
-											
-											if (!module) return;
-											module.linkedNode.isValidName(me.fieldName.getValue(), function (res) 
-											{
-												if (!res) {
-													me.fieldName.validFlag = 'Error during object validation';
-													myDesktopApp.errorMsg(me.fieldName.validFlag);
-													me.fieldName.validate();
-													return;
-												}
-												
-												if (!res.valid) {
-													if (res.error) {
-														if (res.error.search('subtree') != -1) {  							
-															Ext.MessageBox.show({title:'Warning', 
-																msg: res.error+'<br/>Do you want to overwrite it?',
-																width: 300,
-																buttons: Ext.MessageBox.OKCANCEL, 
-																fn : me.overwriteProcess,
-																icon: Ext.MessageBox.WARNING,
-																scope : me
-															});
-															me.fieldName.validFlag = true;
-														}
-														else
-															me.fieldName.validFlag = res.error;
-													}
-													else {
-														me.fieldName.validFlag = 'Invalid object name';
-														myDesktopApp.errorMsg(me.fieldName.validFlag);
-													}
-													me.fieldName.validate();
-													return;
-												}
-												
-												me.fieldName.validFlag = true;
-												me.fieldName.validate();
-												me.saveProcess(false);
-											});
-										});                            
-									} 
-									else {
-										Ext.Msg.alert('No intervals', 'Your catalog is invalid, <br>you must have at least one interval');
-									}
-								}
+                                                                                                                                                        this.saveCatalog();
+								
 							} 
 						},{
 							type: 'button',
@@ -896,8 +920,8 @@ Ext.define('amdaUI.CatalogUI', {
                                                                                                                                              //dock: 'bottom', 
                                                                                                                                              //ui: 'footer',
                                                                                                                                              handler: function() {
-                                                                                                                                                                   this.generateTT(this.object.get('id'));
-                                                                                                                                                                }
+                                                                                                                                                                this.generateTT(this.object.get('id'));
+                                                                                                                                                            }
                                                                                                                                              }]},
                                                                                             ]
 				},
--
libgit2 0.21.2