--- /dev/null
+/*
+Copyright (c) Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+For licensing, see README.txt or http://www.pentilanero.com (Cecill-C or AGPL or LGPL)
+*/
+Ext.ns("EntSavoie.CantineDepartement");
+EntSavoie.CantineDepartement.Suggestion = function (config) {
+ Ext.apply(this, config);
+
+ // Ajoute le texte des erreurs
+ Ext.QuickTips.init();
+ // turn on validation errors beside the field globally
+ Ext.form.Field.prototype.msgTarget = 'side';
+
+ this.suggestionStore = this.suggestionStore || new Ext.data.JsonStore({
+ autoLoad: true,
+ root: 'suggestions',
+ idProperty: 'recetteId',
+ fields: [
+ 'recetteId',
+ 'titreRecette',
+ 'categorie',
+ 'classification'
+ ],
+ sortInfo: {
+ field: 'titreRecette',
+ direction: 'ASC'
+ },
+ url: this.renderURLAjax+'&jspPage=%2Fajax%2FlistSuggestion.jsp'
+ });
+
+ this.action_column = this.action_column || new Ext.grid.ActionColumn({
+ width: 50,
+ sortable: false,
+ menuDisabled: true,
+ align: 'center',
+ items: [
+ /*{
+ iconCls: 'ficheTechnique',
+ tooltip: "Modifier la fiche technique de la recette",
+ scope: this,
+ handler: this.onEditFicheTechnique
+ },*/
+ {
+ iconCls: 'accept',
+ tooltip: "Accepter la recette",
+ margin: 2,
+ scope: this,
+ handler: this.onAcceptRecette
+ },
+ {
+ iconCls: 'refuse',
+ tooltip: "Refuser la recette",
+ margin: 2,
+ scope: this,
+ handler: this.onRefuseRecette
+ }
+ ]
+ });
+
+ this.cmSuggestion = this.cmSuggestion || new Ext.grid.ColumnModel({
+ columns: [
+ {
+ header: "Titre",
+ dataIndex: 'titreRecette',
+ id: 'titreRecette'
+ },
+ {
+ header: "Catégorie",
+ dataIndex: 'categorie'
+ },
+ {
+ header: "Classification",
+ dataIndex: 'classification',
+ width: 300
+ },
+ this.action_column
+ ]
+ });
+
+
+ /*this.editFicheTechniqueWindow = this.editFicheTechniqueWindow || new EntSavoie.FicheTechniqueRecette({
+ id: "editFicheTechniqueWindowForSuggestion",
+ renderURLAjax: this.renderURLAjax,
+ actionURLAjax: this.actionURLAjax,
+ callBackFunctionAfterAcceptOrRefus: this.removeRecordAfterAcceptOrRefusCallBack.createDelegate(this),
+ isDepartement: this.isDepartement
+ });*/
+
+ /**
+ * Constructeur
+ */
+ EntSavoie.CantineDepartement.Suggestion.superclass.constructor.call(this, {
+ title: "Suggestions",
+ border: true,
+ store: this.suggestionStore,
+ cm: this.cmSuggestion,
+ autoExpandColumn: 'titreRecette'
+ });
+
+};
+
+Ext.extend(EntSavoie.CantineDepartement.Suggestion, Ext.grid.GridPanel, {
+ initComponent: function () {
+ EntSavoie.CantineDepartement.Suggestion.superclass.initComponent.call(this);
+ },
+
+ onEditFicheTechnique: function(grid, rowIndex, colIndex){
+ this.editFicheTechniqueWindow.showFicheTechniqueRecette(grid.store.getAt(rowIndex), true);
+ },
+
+ onAcceptRecette: function(grid, rowIndex, colIndex){
+
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "Acceptation de la recette en cours. <br /> <b> Veuillez patienter ... </b>"});
+ this.wait.show();
+
+ this.recette = grid.store.getAt(rowIndex);
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "acceptRecette",
+ recetteId: this.recette.get("recetteId")
+ },
+ scope: this,
+ success: this.onSuccessAcceptRecette,
+ failure: this.onFailureAcceptRecette
+ });
+ },
+
+ onSuccessAcceptRecette: function(response, options) {
+ this.wait.hide();
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert("Attention", "En raison d'un dysfonctionnement réseau l'opération demandée n'a pas pu être effectuée", function(btn){}, this);
+ } else {
+ this.removeRecordAfterAcceptOrRefusCallBack(this.recette, true);
+ Ext.slideMsg.msg("Acceptation de la recette", "La recette a correctement été acceptée dans la base commune.");
+ }
+ },
+
+ onFailureAcceptRecette: function(response, options) {
+ this.wait.hide();
+ Ext.MessageBox.alert("Attention", "En raison d'un dysfonctionnement réseau l'opération demandée n'a pas pu être effectuée", function(btn){}, this);
+ },
+
+ onRefuseRecette: function(grid, rowIndex, colIndex){
+
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "Refus de la recette en cours. <br /> <b> Veuillez patienter ... </b>"});
+ this.wait.show();
+
+ this.recette = grid.store.getAt(rowIndex);
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "refusRecette",
+ recetteId: this.recette.get("recetteId")
+ },
+ scope: this,
+ success: this.onSuccessRefusRecette,
+ failure: this.onFailureRefusRecette
+ });
+ },
+
+ onSuccessRefusRecette: function(response, options) {
+ this.wait.hide();
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert("Attention", "En raison d'un dysfonctionnement réseau l'opération demandée n'a pas pu être effectuée", function(btn){}, this);
+ } else {
+ this.removeRecordAfterAcceptOrRefusCallBack(this.recette, false);
+ Ext.slideMsg.msg("Refus de la recette", "La recette a correctement été refusée.");
+ }
+ },
+
+ onFailureRefusRecette: function(response, options) {
+ this.wait.hide();
+ Ext.MessageBox.alert("Attention", "En raison d'un dysfonctionnement réseau l'opération demandée n'a pas pu être effectuée", function(btn){}, this);
+ },
+
+ removeRecordAfterAcceptOrRefusCallBack: function(recette, reloadRecette){
+ this.suggestionStore.remove(recette);
+ if(reloadRecette){
+ this.recettePanel.treeBanquePanel.selectPath(this.recettePanel.treeBanquePanel.getRootNode().getPath());
+ this.recettePanel.treeBanquePanel.fireEvent("click", this.recettePanel.treeBanquePanel.getRootNode());
+ }
+
+ delete(this.recette);
+ }
+});