--- /dev/null
+/*
+Copyright (c) Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+For licensing, see README.txt or http://www.pentilanero.com (Cecill-C or AGPL or LGPL)
+*/
+Ext.ns("EntSavoie.CantineCollege");
+EntSavoie.CantineCollege.PlanAlimentaire = 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';
+
+ /***************************************************
+ * PLANS ALIMENTAIRES
+ ***************************************************/
+
+ this.planAlimentaireStore = this.planAlimentaireStore || new Ext.data.ArrayStore({
+ idProperty: 'planAlimentaireId',
+ fields: [
+ 'planAlimentaireId',
+ 'nomPlan',
+ 'dates',
+ 'type',
+ 'isShare',
+ 'isDiffuse'
+ ]
+ });
+
+ this.cmPlanAlimentaire = this.cmPlanAlimentaire || new Ext.grid.ColumnModel({
+ columns: [
+ {
+ header: "Liste des plans",
+ dataIndex: 'nomPlan',
+ id: 'nomPlan',
+ sortable: true,
+ renderer: {
+ fn: function(value, metaData, record, rowIndex, colIndex, store) {
+ var result = record.get("nomPlan");
+
+ if(record.get("type") == 1){
+ result += " <span style='color: blue;'> (Matin) </span>";
+ } else if(record.get("type") == 2){
+ result += " <span style='color: blue;'> (Midi) </span>";
+ } else if(record.get("type") == 3){
+ result += " <span style='color: blue;'> (Soir) </span>";
+ }
+
+ return result;
+ },
+ scope: this
+ }
+ }
+ ]
+ });
+
+ this.addPlanAlimentaireBtn = this.addPlanAlimentaireBtn || new Ext.Button({
+ name: 'addPlan',
+ iconCls: 'cantineAdd',
+ handler: this.onAddOrEditPlanAlimentaire,
+ tooltip: "Ajouter un nouveau plan alimentaire",
+ scope: this
+ });
+
+ this.deletePlanAlimentaireBtn = this.deletePlanAlimentaireBtn || new Ext.Button({
+ iconCls: 'cantineDelete',
+ handler: this.onDeletePlanAlimentaire,
+ tooltip: "Supprimer le(les) plan(s) sélectionnée(s)",
+ scope: this
+ });
+
+ this.editPlanAlimentaireBtn = this.editPlanAlimentaireBtn || new Ext.Button({
+ name: 'editPlan',
+ iconCls: 'cantineEdit',
+ handler: this.onAddOrEditPlanAlimentaire,
+ tooltip: "Modifier le(les) plan(s) sélectionnée(s)",
+ scope: this
+ });
+
+ this.addPlanAlimentaireTbarBtn = this.addPlanAlimentaireTbarBtn || new Ext.Button({
+ name: 'addPlan',
+ iconCls: 'cantineAdd',
+ handler: this.onAddOrEditPlanAlimentaire,
+ tooltip: "Ajouter un nouveau plan alimentaire",
+ scope: this
+ });
+
+ this.deletePlanAlimentaireTbarBtn = this.deletePlanAlimentaireTbarBtn || new Ext.Button({
+ iconCls: 'cantineDelete',
+ handler: this.onDeletePlanAlimentaire,
+ tooltip: "Supprimer le(les) plan(s) sélectionnée(s)",
+ scope: this
+ });
+
+ this.editPlanAlimentaireTbarBtn = this.editPlanAlimentaireTbarBtn || new Ext.Button({
+ name: 'editPlan',
+ iconCls: 'cantineEdit',
+ handler: this.onAddOrEditPlanAlimentaire,
+ tooltip: "Modifier le(les) plan(s) sélectionnée(s)",
+ scope: this
+ });
+
+ this.validAddOrEditPlanAlimentaire = this.validAddOrEditPlanAlimentaire || new Ext.Button({
+ text: "Valider",
+ handler: this.onValidEditPlanAlimentaire,
+ scope: this
+ });
+
+ this.cancelAddOrEditPlanAlimentaire = this.cancelAddOrEditPlanAlimentaire || new Ext.Button({
+ text: "Annuler",
+ handler: this.onCancelEditPlanAlimentaire,
+ scope: this
+ });
+
+ this.addOrEditPlanAlimentaireWindow = this.addOrEditPlanAlimentaireWindow || new Ext.Window({
+ cls: "cantine-portlet",
+ title: "Edition des plans alimentaires",
+ modal: true,
+ width: 450,
+ height: 475,
+ layout: 'form',
+ closable: false,
+ autoScroll: true,
+ padding: 10,
+ buttons: [
+ this.validAddOrEditPlanAlimentaire,
+ this.cancelAddOrEditPlanAlimentaire
+ ]
+ });
+
+ this.planAlimentaireGridPanel = this.planAlimentaireGridPanel || new Ext.grid.GridPanel({
+ store: this.planAlimentaireStore,
+ cm: this.cmPlanAlimentaire,
+ sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
+ buttonAlign: "left",
+ autoExpandColumn: 'nomPlan',
+ tbar: [this.addPlanAlimentaireTbarBtn, this.deletePlanAlimentaireTbarBtn, this.editPlanAlimentaireTbarBtn],
+ bbar: [this.addPlanAlimentaireBtn, this.deletePlanAlimentaireBtn, this.editPlanAlimentaireBtn]
+ });
+
+ // Menu clic droit
+ this.rightClicMenuPlanAlimentaire = this.rightClicMenuPlanAlimentaire || new Ext.menu.Menu({
+ cls: "cantine-portlet",
+ items: [
+ {
+ text: "Editer",
+ name: 'editPlan',
+ handler: this.onAddOrEditPlanAlimentaire,
+ iconCls: 'cantineAdd',
+ scope: this
+ },
+ {
+ text: "Supprimer",
+ handler: this.onDeletePlanAlimentaire,
+ iconCls: 'cantineDelete',
+ scope: this
+ }
+ ]
+ });
+
+
+ /***************************************************
+ * TABLE SYNTHETIQUE DES CONTRAINTES
+ ***************************************************/
+
+ this.nomPlanLabel = this.nomPlanLabel || new Ext.form.Label({
+ style: "font-size: 16px; color:#15428B; font-weight: bold;",
+ text: ""
+ });
+
+ this.dateLabel = this.dateLabel || new Ext.form.Label({
+ style: "font-size: 16px; color:#15428B; font-weight: bold;",
+ text: ""
+ });
+
+ this.nomEtabLabel = this.nomEtabLabel || new Ext.form.Label({
+ style: "font-size: 16px; color:#15428B; font-weight: bold;",
+ text: ""
+ });
+
+ this.diffusePlanAlimentaireBtn = this.diffusePlanAlimentaireBtn || new Ext.Button({
+ style: 'margin-left: 10px;',
+ iconCls: 'broadcast',
+ text: "",
+ handler: this.onDiffusePlanAlimentaire,
+ tooltip: "Diffuser le plan alimentaire sélectionné à l'établissement",
+ scope: this
+ });
+
+ this.feuilleControlePlanAlimentaireBtn = this.feuilleControlePlanAlimentaireBtn || new Ext.Button({
+ text: "Exporter Feuille de contrôle",
+ handler: this.onGetFeuillePlanAlimentaire,
+ tooltip: "Exporter la feuille de contrôle pour le plan alimentaire sélectionné",
+ scope: this
+ });
+
+ this.titlePanel = this.titlePanel || new Ext.Panel({
+ hidden: true,
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ items: [
+ {
+ width: "100%",
+ border: false,
+ layout: "column",
+ height: 30,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ style: "margin-left: 5px; margin-top: 5px;",
+ items: [
+ {
+ border: false,
+ columnWidth: 0.99,
+ height: 25,
+ layout: "table",
+ layoutConfig: {
+ columns: 2
+ },
+ bodyStyle:{"background-color": "#DFE8F6"},
+ items: [this.nomPlanLabel, this.diffusePlanAlimentaireBtn]
+ },
+ {
+ width: 230,
+ border: false,
+ height: 25,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ items: [this.dateLabel]
+ }
+ ]
+ },
+ {
+ width: "100%",
+ border: false,
+ layout: "column",
+ height: 30,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ style: 'margin-left: 5px; margin-top: 5px;',
+ items: [
+ {
+ border: false,
+ columnWidth: 0.99,
+ height: 25,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ items: [this.nomEtabLabel]
+ },
+ {
+ width: 150,
+ border: false,
+ height: 25,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ items: [this.feuilleControlePlanAlimentaireBtn]
+ }
+ ]
+ }
+ ]
+ });
+
+ this.allContrainteStore = this.allContrainteStore || new Ext.data.ArrayStore({
+ idProperty: 'gemrcnId',
+ fields: [
+ 'gemrcnId',
+ 'libelleGemrcn',
+ 'nbEntree',
+ 'nbPlat',
+ 'nbGarniture',
+ 'nbLait',
+ 'nbDessert',
+ 'frequence',
+ 'freqGlobal',
+ 'controle'
+ ]
+ });
+
+ this.cmAllContrainte = this.cmAllContrainte || new Ext.grid.ColumnModel({
+ columns: [
+ {
+ header: "Contrainte sur 20 repas",
+ dataIndex: 'libelleGemrcn',
+ id: 'libelleGemrcn'
+ },
+ {
+ header: "Entrée",
+ dataIndex: 'nbEntree',
+ width: 50
+ },
+ {
+ header: "Plat protidique",
+ dataIndex: 'nbPlat',
+ width: 70
+ },
+ {
+ header: "Garniture",
+ dataIndex: 'nbGarniture',
+ width: 60
+ },
+ {
+ header: "Produit Laitier",
+ dataIndex : 'nbLait',
+ width: 50
+ },
+ {
+ header: "Dessert",
+ dataIndex: 'nbDessert',
+ width: 50
+ },
+ {
+ header: "Fréquence recommandée",
+ dataIndex: 'frequence',
+ width: 80
+ },
+ {
+ header: "Contrôle",
+ dataIndex: 'freqGlobal',
+ width: 55
+ }
+ ]
+ });
+
+ this.allContrainteGridPanel = this.allContrainteGridPanel || new Ext.grid.GridPanel({
+ hidden: true,
+ title: 'Table synthétique des contraintes',
+ columnLines: true,
+ border: true,
+ store: this.allContrainteStore,
+ cm: this.cmAllContrainte,
+ disableSelection: true,
+ trackMouseOver: false,
+ stripeRows: true,
+ viewConfig: {
+ markDirty: false
+ },
+ autoExpandColumn: 'libelleGemrcn'
+ });
+
+
+ /***************************************************
+ * DEFINITION DES BOUTONS
+ ***************************************************/
+
+ this.copyPlanAlimentaireBtn = this.copyPlanAlimentaireBtn || new Ext.Button({
+ iconCls: "copyPlanAlimentaireCls",
+ text: "Remplir depuis un plan",
+ tooltip: "Remplir le plan sélectionné avec les menus d'un autre plan",
+ handler: this.onCopyPlanAlimentaire,
+ scope: this
+ });
+
+ this.copyPlanAlimentaireTbarBtn = this.copyPlanAlimentaireTbarBtn || new Ext.Button({
+ iconCls: "copyPlanAlimentaireCls",
+ text: "Remplir depuis un plan",
+ tooltip: "Remplir le plan sélectionné avec les menus d'un autre plan",
+ handler: this.onCopyPlanAlimentaire,
+ scope: this
+ });
+
+ //Window de copie d'un plan
+ this.copyPlanWindow = this.copyPlanWindow || new EntSavoie.CantineCollege.CopyPlanWindow({
+ renderURLAjax: this.renderURLAjax,
+ actionURLAjax: this.actionURLAjax,
+ callBackFunction: this.afterCopyPlanAlimentaireCallBack.createDelegate(this)
+ });
+
+ this.editMenuPlanAlimentaireBtn = this.editMenuPlanAlimentaireBtn || new Ext.Button({
+ iconCls: "editMenuPlanAlimentaireCls",
+ text: "Saisr le plan",
+ handler: this.onEditMenuPlanAlimentaire,
+ tooltip: "Saisir les menus du plan alimentaire sélectionné",
+ scope: this
+ });
+
+ this.editMenuPlanAlimentaireTbarBtn = this.editMenuPlanAlimentaireTbarBtn || new Ext.Button({
+ iconCls: "editMenuPlanAlimentaireCls",
+ text: "Saisr le plan",
+ handler: this.onEditMenuPlanAlimentaire,
+ tooltip: "Saisir les menus du plan alimentaire sélectionné",
+ scope: this
+ });
+
+ //Window de visualisation synthetique d'un plan
+ this.viewPlanWindow = this.viewPlanWindow || new EntSavoie.CantineCollege.ViewPlanWindow({
+ renderURLAjax: this.renderURLAjax,
+ actionURLAjax: this.actionURLAjax
+ });
+
+ this.viewMenuPlanAlimentaireBtn = this.viewMenuPlanAlimentaireBtn || new Ext.Button({
+ iconCls: "viewMenuPlanAlimentaireCls",
+ text: "Visualiser",
+ handler: this.onViewMenuPlanAlimentaire,
+ tooltip: "Voir les menus du plan alimentaire sélectionné",
+ scope: this
+ });
+
+ this.viewMenuPlanAlimentaireTbarBtn = this.viewMenuPlanAlimentaireTbarBtn || new Ext.Button({
+ iconCls: "viewMenuPlanAlimentaireCls",
+ text: "Visualiser",
+ handler: this.onViewMenuPlanAlimentaire,
+ tooltip: "Voir les menus du plan alimentaire sélectionné",
+ scope: this
+ });
+
+ this.partagerPlanAlimentaireBtn = this.partagerPlanAlimentaireBtn || new Ext.Button({
+ iconCls: "partagerPlanAlimentaireCls",
+ text: "Partager",
+ handler: this.onPartagerPlanAlimentaire,
+ tooltip: "Partager aux autre cuisiniers le plan alimentaire sélectionné",
+ scope: this
+ });
+
+ this.partagerPlanAlimentaireTbarBtn = this.partagerPlanAlimentaireTbarBtn || new Ext.Button({
+ iconCls: "partagerPlanAlimentaireCls",
+ text: "Partager",
+ handler: this.onPartagerPlanAlimentaire,
+ tooltip: "Partager aux autre cuisiniers le plan alimentaire sélectionné",
+ scope: this
+ });
+
+ this.exportPlanAlimentaireBtn = this.exportPlanAlimentaireBtn || new Ext.Button({
+ iconCls: "exportPlanAlimentaireCls",
+ text: "Imprimer",
+ handler: this.onExportPlanAlimentaire,
+ tooltip: "Obtenir une version imprimable plan alimentaire sélectionné",
+ scope: this
+ });
+
+ this.exportPlanAlimentaireTbarBtn = this.exportPlanAlimentaireTbarBtn || new Ext.Button({
+ iconCls: "exportPlanAlimentaireCls",
+ text: "Imprimer",
+ handler: this.onExportPlanAlimentaire,
+ tooltip: "Obtenir une version imprimable plan alimentaire sélectionné",
+ scope: this
+ });
+
+ this.exportWindow = this.exportWindow || new EntSavoie.CantineCollege.ExportMenuWindow({
+ renderURLAjax: this.renderURLAjax,
+ actionURLAjax: this.actionURLAjax
+ });
+
+ this.informationPanel = this.informationPanel || new Ext.Panel ({
+ hidden: true,
+ padding: 20,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ style: 'margin-left: 40px; margin-right: 40px;',
+ html: "<table><tr><td><div style='font-size: 19px; color:#15428B; font-weight: bold; text-align: center; cursor: pointer; line-height:110%;'> Bienvenue dans votre outil de gestion de plan alimentaire.<br /> Pour commencer veuillez créer un plan. <br /> (<u>Cliquez ici</u>)</div></td><td width='50' class='informationPanel'></td></tr></table>"
+ });
+
+ this.planAlimentaireTitle = this.planAlimentaireTitle || new Ext.form.Label({
+ text: "Plan Alimentaire",
+ cls: "toolBarHeaderTextCls"
+ });
+
+ this.planAlimentaireTbar = this.planAlimentaireTbar || new Ext.Toolbar({
+ cls: "x-panel-header",
+ items: [
+ this.planAlimentaireTitle,
+ "->",
+ this.copyPlanAlimentaireTbarBtn,
+ "-",
+ this.editMenuPlanAlimentaireTbarBtn,
+ "-",
+ this.viewMenuPlanAlimentaireTbarBtn,
+ "-",
+ this.partagerPlanAlimentaireTbarBtn,
+ "-",
+ this.exportPlanAlimentaireTbarBtn
+ ]
+ });
+
+ /**
+ * Constructeur
+ */
+ EntSavoie.CantineCollege.PlanAlimentaire.superclass.constructor.call(this, {
+ border: false,
+ layout: 'table',
+ layoutConfig: {
+ columns: 2,
+ fitToParent: true
+ },
+ width: "auto",
+ monitorResize: true,
+ items: [
+ {
+ width: 200,
+ border: false,
+ layout: 'fit',
+ items: [this.planAlimentaireGridPanel]
+ },
+ {
+ border: true,
+ layout: 'fit',
+ bodyStyle:{"background-color": "#DFE8F6"},
+ items:[
+ {
+ layout:'border',
+ border:false,
+ split: true,
+ items: [
+ {
+ layout: 'fit',
+ width: "auto",
+ region: 'north',
+ bodyStyle:{"background-color": "#DFE8F6"},
+ height: 70,
+ border: false,
+ items: [this.titlePanel]
+ },{
+ layout: "fit",
+ width: "auto",
+ region: 'center',
+ bodyStyle:{"background-color": "#DFE8F6"},
+ border: false,
+ items: [this.allContrainteGridPanel, this.informationPanel]
+ }
+ ]
+ }
+ ],
+ bbar: ["->", this.copyPlanAlimentaireBtn, "-", this.editMenuPlanAlimentaireBtn, "-", this.viewMenuPlanAlimentaireBtn, "-", this.partagerPlanAlimentaireBtn, "-", this.exportPlanAlimentaireBtn]
+ }
+ ],
+ tbar: this.planAlimentaireTbar
+ });
+
+ this.on("activate", this.onActivatePlanAlimentaire, this);
+ this.planAlimentaireStore.on("load", this.onLoadPlanAlimentaireStore, this);
+ this.planAlimentaireGridPanel.on("rowclick", this.onRowClickPlanAlimentaireGridPanel, this);
+ this.allContrainteStore.on("beforeload", this.onBeforeLoadAllContrainteStore, this);
+ this.allContrainteStore.on("load", this.onLoadAllContrainteStore, this);
+
+ this.planAlimentaireGridPanel.on('cellcontextmenu', this.onRightClickPlanAlimentaire, this);
+ this.planAlimentaireGridPanel.on('rowdblclick', this.onRowDblClickPlanAlimentaireGridPanel, this);
+
+ this.informationPanel.on("render", this.onRenderInformationPanel, this);
+};
+
+Ext.extend(EntSavoie.CantineCollege.PlanAlimentaire, Ext.Panel, {
+ initComponent: function () {
+ EntSavoie.CantineCollege.PlanAlimentaire.superclass.initComponent.call(this);
+ },
+
+ onRenderInformationPanel: function(panel){
+ panel.el.on("click", this.onAddOrEditPlanAlimentaire, this);
+ },
+
+ onActivatePlanAlimentaire: function(panel){
+
+ if(this.mainContainer.planAlimentaireId){
+ //Reload des contraintes pour le plan courant
+ this.planAlimentaireGridPanel.fireEvent("rowclick", this.planAlimentaireGridPanel, this.planAlimentaireStore.find("planAlimentaireId", this.mainContainer.planAlimentaireId), this);
+ } else {
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "<b>Chargement des informations en cours.</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params:{
+ cmd: "getStorePlanAlimentaireAndFirstPlanInformations"
+ },
+ scope: this,
+ success: this.onSuccessGetStorePlanAlimentaireAndFirstPlanInformations,
+ failure: this.onFailureGetStorePlanAlimentaireAndFirstPlanInformations
+ });
+ }
+ },
+
+ onSuccessGetStorePlanAlimentaireAndFirstPlanInformations: 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.planAlimentaireStore.loadData(backObj.planAlimentaireStore);
+ this.mainContainer.planAlimentaireId = backObj.planAlimentaireId;
+ if(this.mainContainer.planAlimentaireId){
+ this.planAlimentaireGridPanel.getSelectionModel().selectFirstRow();
+ var nomPlan = backObj.nomPlan;
+ if(backObj.isDiffuse){
+ this.diffusePlanAlimentaireBtn.setIconClass("unbroadcast");
+ this.diffusePlanAlimentaireBtn.setTooltip("Oter la diffusion du plan alimentaire sélectionné à l'établissement");
+ nomPlan += " (Diffusé)";
+ } else {
+ this.diffusePlanAlimentaireBtn.setIconClass("broadcast");
+ this.diffusePlanAlimentaireBtn.setTooltip("Diffuser le plan alimentaire sélectionné à l'établissement");
+ nomPlan += " (Non diffusé)";
+ }
+ this.nomPlanLabel.setText(nomPlan);
+ this.dateLabel.setText(backObj.dateIntervalle);
+ this.nomEtabLabel.setText(backObj.nomEtab);
+ this.mainContainer.dates = backObj.dates;
+ this.mainContainer.titles = backObj.titles;
+ if(backObj.isShare){
+ this.partagerPlanAlimentaireBtn.setText("Arrêter le partage");
+ this.partagerPlanAlimentaireBtn.setTooltip("Arrêter le partage du plan alimentaire sélectionné");
+ this.partagerPlanAlimentaireTbarBtn.setText("Arrêter le partage");
+ this.partagerPlanAlimentaireTbarBtn.setTooltip("Arrêter le partage du plan alimentaire sélectionné");
+ } else {
+ this.partagerPlanAlimentaireBtn.setText("Partager");
+ this.partagerPlanAlimentaireBtn.setTooltip("Partager aux autre cuisiniers le plan alimentaire sélectionné");
+ this.partagerPlanAlimentaireTbarBtn.setText("Partager");
+ this.partagerPlanAlimentaireTbarBtn.setTooltip("Partager aux autre cuisiniers le plan alimentaire sélectionné");
+ }
+ this.allContrainteStore.loadData(backObj.allContrainteStore);
+ }
+ }
+ },
+
+ onFailureGetStorePlanAlimentaireAndFirstPlanInformations: 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);
+ },
+
+
+ onLoadPlanAlimentaireStore: function(store){
+ if(store.getCount()>0){
+ this.copyPlanAlimentaireTbarBtn.show();
+ this.editMenuPlanAlimentaireTbarBtn.show();
+ this.viewMenuPlanAlimentaireTbarBtn.show();
+ this.partagerPlanAlimentaireTbarBtn.show();
+ this.exportPlanAlimentaireTbarBtn.show();
+ this.copyPlanAlimentaireBtn.show();
+ this.editMenuPlanAlimentaireBtn.show();
+ this.viewMenuPlanAlimentaireBtn.show();
+ this.partagerPlanAlimentaireBtn.show();
+ this.exportPlanAlimentaireBtn.show();
+ this.titlePanel.show();
+ this.allContrainteGridPanel.show();
+ this.informationPanel.hide();
+ } else {
+ this.copyPlanAlimentaireTbarBtn.hide();
+ this.editMenuPlanAlimentaireTbarBtn.hide();
+ this.viewMenuPlanAlimentaireTbarBtn.hide();
+ this.partagerPlanAlimentaireTbarBtn.hide();
+ this.exportPlanAlimentaireTbarBtn.hide();
+ this.copyPlanAlimentaireBtn.hide();
+ this.editMenuPlanAlimentaireBtn.hide();
+ this.viewMenuPlanAlimentaireBtn.hide();
+ this.partagerPlanAlimentaireBtn.hide();
+ this.exportPlanAlimentaireBtn.hide();
+ this.titlePanel.hide();
+ this.allContrainteGridPanel.hide();
+ this.informationPanel.show();
+ }
+ },
+
+ onAddOrEditPlanAlimentaire: function(btn){
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "<b>Chargement des informations en cours.</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+
+ var planAlimentaireId = 0;
+ if(btn.name == "editPlan"){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ planAlimentaireId = plan.get("planAlimentaireId");
+ this.planAction = "editPlanAlimentaire";
+ } else {
+ return;
+ }
+ } else {
+ this.planAction = "addPlanAlimentaire";
+ }
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "getDatesAlreadyUsed",
+ planAlimentaireId: planAlimentaireId
+ },
+ scope: this,
+ success: this.onSuccessGetDatesAlreadyUsed,
+ failure: this.onFailureGetDatesAlreadyUsed
+ });
+ },
+
+ onSuccessGetDatesAlreadyUsed: 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 {
+ // On met a jour les dates
+ var datesMidi = [];
+ var datesSoir = [];
+ for(i=0; i<backObj.datesMidi.length; i++){
+ var date = backObj.datesMidi[i].split("-");
+ var year = date[0];
+ var month = date[1] - 1;
+ var day = date[2];
+ datesMidi.push(new Date(year, month, day));
+ }
+ for(i=0; i<backObj.datesSoir.length; i++){
+ var date = backObj.datesSoir[i].split("-");
+ var year = date[0];
+ var month = date[1] - 1;
+ var day = date[2];
+ datesSoir.push(new Date(year, month, day));
+ }
+ if(this.planAction == "addPlanAlimentaire"){
+ this.addPlanAlimentaireFn(datesMidi, datesSoir);
+ } else {
+ this.editPlanAlimentaireFn(datesMidi, datesSoir);
+ }
+ }
+ },
+
+ onFailureGetDatesAlreadyUsed: 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);
+ },
+
+ addPlanAlimentaireFn: function(datesMidi, datesSoir){
+
+ this.addOrEditPlanAlimentaireWindow.setTitle("Ajout d'un nouveau plan alimentaire");
+
+ var dateLabel = new Ext.form.Label({
+ text: "Dates sélectionnées 0/20",
+ style: "margin-left: 115px; font-weight: bold; font-size: 12px;"
+ });
+
+ var datePicker = new Ext.ux.DatePickerPlus({
+ datesMidi: datesMidi,
+ datesSoir: datesSoir,
+ allowedDates: datesMidi,
+ maxSelectionDays: 20,
+ maxSelectionDaysTitle : 'Choix des dates',
+ maxSelectionDaysText : 'Vous pouvez sélectionner au maximum %0 jours',
+ dateLabel: dateLabel,
+ showWeekNumber: false,
+ multiSelection: true,
+ multiSelectByCTRL: false,
+ undoText: "Annuler",
+ markWeekends: false,
+ style: "margin-left: 100px;",
+ renderOkUndoButtons: false,
+ selectWeekText: "Cliquez pour séléctionner tous les jours de la semaine",
+ selectMonthText: "Cliquez pour séléctionner tous les semaines du mois",
+ weekName: "Sem.",
+ markNationalHolidays: false,
+ value: new Date()
+ });
+
+ var comboType = new Ext.form.ComboBox({
+ listClass: "cantine-portlet",
+ datePicker: datePicker,
+ hidden: !hasInternat,
+ fieldLabel: "Type",
+ typeAhead: true,
+ triggerAction: 'all',
+ store: [
+ // [1,"Matin"],
+ [2,'Midi'],
+ [3,'Soir']
+ ],
+ value: 2,
+ lazyRender: true,
+ listClass: 'x-combo-list-small',
+ width: 250,
+ scope: this
+ });
+
+ var patternPlanAlimentairePanel = new Ext.form.FieldSet({
+ width: 410,
+ checkboxToggle:false,
+ title: "Nouveau Plan",
+ autoHeight:true,
+ padding: 0,
+ labelWidth: 120,
+ style: 'margin-bottom: 20px;',
+ items: [
+ {
+ xtype: 'textfield',
+ fieldLabel: "Nom du plan",
+ value: "Plan",
+ allowBlank: false,
+ width: 250,
+ scope: this
+ },
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "<br />"
+ },
+ dateLabel,
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "<br />"
+ },
+ datePicker,
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "Les dates grisées sont des dates déjà sélectionnées pour d'autres plans"
+ },
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "<br />"
+ },
+ comboType
+ ]
+ });
+
+ datePicker.on("afterdateclick", function(picker){
+ picker.dateLabel.setText("Dates sélectionnées " + picker.selectedDates.length + "/20");
+ });
+
+ comboType.on("select", function(combo, record, index){
+ //Midi
+ if(index == 0){
+ combo.datePicker.setAllowedDates(datePicker.datesMidi, true);
+ }
+ //Soir
+ else if(index == 1){
+ combo.datePicker.setAllowedDates(datePicker.datesSoir, true);
+ }
+ });
+
+ this.addOrEditPlanAlimentaireWindow.add(patternPlanAlimentairePanel);
+ this.addOrEditPlanAlimentaireWindow.show();
+
+ },
+
+ editPlanAlimentaireFn: function(datesMidi, datesSoir){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+
+ this.addOrEditPlanAlimentaireWindow.setTitle("Edition des plans alimentaire sélectionnés");
+
+ for(k=0; k<plans.length; k++){
+
+ var plan = plans[k];
+
+ var dateLabel = new Ext.form.Label({
+ text: "Dates sélectionnées 20/20",
+ style: "margin-left: 115px; font-weight: bold; font-size: 12px;"
+ });
+
+ var datePicker = new Ext.ux.DatePickerPlus({
+ datesMidi: datesMidi,
+ datesSoir: datesSoir,
+ allowedDates: plan.get("type")==2?datesMidi:datesSoir,
+ maxSelectionDays: 20,
+ maxSelectionDaysTitle : 'Choix des dates',
+ maxSelectionDaysText : 'Vous pouvez sélectionner au maximum %0 jours',
+ dateLabel: dateLabel,
+ showWeekNumber: false,
+ multiSelection: true,
+ multiSelectByCTRL: false,
+ undoText: "Annuler",
+ markWeekends: false,
+ style: "margin-left: 100px;",
+ renderOkUndoButtons: false,
+ selectWeekText: "Cliquez pour séléctionner tous les jours de la semaine",
+ selectMonthText: "Cliquez pour séléctionner tous les semaines du mois",
+ weekName: "Sem.",
+ markNationalHolidays: false,
+ value: new Date()
+ });
+
+ // On set les dates
+ var dates = [];
+ var datesPlan = plan.get("dates");
+ for(j=0; j<datesPlan.length; j++){
+ var date = datesPlan[j].split("-");
+ var year = date[0];
+ var month = date[1] - 1;
+ var day = date[2];
+ dates.push(new Date(year, month, day));
+ }
+ if(dates.length>0){
+ datePicker.setValue(dates);
+ }
+
+ var comboType = new Ext.form.ComboBox({
+ listClass: "cantine-portlet",
+ datePicker: datePicker,
+ hidden: !hasInternat,
+ xtype: 'combo',
+ fieldLabel: "Type",
+ typeAhead: true,
+ triggerAction: 'all',
+ store: [
+ // [1,"Matin"],
+ [2,'Midi'],
+ [3,'Soir']
+ ],
+ value: plan.get("type"),
+ lazyRender: true,
+ listClass: 'x-combo-list-small',
+ width: 250,
+ scope: this
+ });
+
+ //Petite phrase pour dire sur le plan est diffuse --> visible par les eleves
+ var diffuse = "Le plan n'est pas diffusé à l'établissement.";
+ if(plan.get("isShare")){
+ diffuse = "Le plan est diffusé à l'établissement.";
+ }
+
+ var patternPlanAlimentairePanel = new Ext.form.FieldSet({
+ id: plan.get("planAlimentaireId"),
+ width: 410,
+ checkboxToggle:false,
+ title: plan.get("nomPlan"),
+ autoHeight:true,
+ padding: 0,
+ labelWidth: 120,
+ style: 'margin-bottom: 20px;',
+ items: [
+ {
+ xtype: 'textfield',
+ fieldLabel: "Nom du plan",
+ value: plan.get("nomPlan"),
+ allowBlank: false,
+ width: 250,
+ scope: this
+ },
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "<br />"
+ },
+ dateLabel,
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "<br />"
+ },
+ datePicker,
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "Les dates grisées sont des dates déjà sélectionnées pour d'autres plans"
+ },
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "<br />"
+ },
+ comboType,
+ {
+ border: false,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: diffuse
+ }
+ ]
+ });
+
+ datePicker.on("afterdateclick", function(picker){
+ picker.dateLabel.setText("Dates sélectionnées " + picker.selectedDates.length + "/20");
+ });
+
+ comboType.on("select", function(combo, record, index){
+ //Midi
+ if(index == 0){
+ combo.datePicker.setAllowedDates(datePicker.datesMidi, true);
+ }
+ //Soir
+ else if(index == 1){
+ combo.datePicker.setAllowedDates(datePicker.datesSoir, true);
+ }
+ });
+
+ this.addOrEditPlanAlimentaireWindow.add(patternPlanAlimentairePanel);
+ }
+ this.addOrEditPlanAlimentaireWindow.show();
+ }
+ },
+
+ onValidEditPlanAlimentaire: function(btn){
+ var fieldSets = this.addOrEditPlanAlimentaireWindow.items;
+ var plans = new Array();
+
+ var has20Dates = true;
+
+ var nbDates = 0;
+ var planNom = "";
+
+ for(i=0; i<fieldSets.length; i++){
+ var fieldSet = fieldSets.get(i);
+
+ var datesSelected = fieldSet.items.get(4).selectedDates;
+ var datesPlan = new Array();
+ if(datesSelected.length != 20){
+ has20Dates = false;
+ nbDates = datesSelected.length;
+ planNom = fieldSet.items.get(0).getValue();
+ break;
+ } else {
+ for(j=0; j<datesSelected.length; j++){
+ datesPlan.push(datesSelected[j]);
+ }
+
+ var plan = {
+ planAlimentaireId: fieldSet.id,
+ nomPlan: fieldSet.items.get(0).getValue(),
+ dates: Ext.util.JSON.encode(datesPlan),
+ type: fieldSet.items.get(7).getValue()
+ };
+
+ plans.push(plan);
+ }
+ }
+
+ if(has20Dates){
+
+ //Ajout
+ if(this.planAction == "addPlanAlimentaire"){
+ this.wait = new Ext.LoadMask(this.addOrEditPlanAlimentaireWindow.id, {msg: "<b>Ajout du plan alimentaire en cours</b> <br/> Veuillez patienter ..."});
+ }
+ //Edition
+ else {
+ this.wait = new Ext.LoadMask(this.addOrEditPlanAlimentaireWindow.id, {msg: "<b>Edition des plans alimentaire en cours</b> <br/> Veuillez patienter ..."});
+ }
+
+ this.wait.show();
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params:{
+ cmd: this.planAction,
+ plans: Ext.util.JSON.encode(plans),
+ currentPlanAlimentaireId: this.mainContainer.planAlimentaireId
+ },
+ scope: this,
+ success: this.onSuccessPlanAlimentaireAction,
+ failure: this.onFailurePlanAlimentaireAction
+ });
+
+ } else {
+ if(this.planAction == "addPlanAlimentaire"){
+ Ext.MessageBox.alert("Attention", "Vous devez sélectionner 20 dates pour le plan à ajouter (" + nbDates + " actuellement).", function(btn){}, this);
+ } else {
+ Ext.MessageBox.alert("Attention", "Vous devez sélectionner 20 dates pour chacun des plans que vous éditez (" + nbDates + " pour le plan " + planNom + " actuellement).", function(btn){}, this);
+ }
+ }
+ },
+
+ onSuccessPlanAlimentaireAction: 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.copyPlanAlimentaireBtn.show();
+ this.editMenuPlanAlimentaireBtn.show();
+ this.viewMenuPlanAlimentaireBtn.show();
+ this.partagerPlanAlimentaireBtn.show();
+ this.exportPlanAlimentaireBtn.show();
+ this.copyPlanAlimentaireTbarBtn.show();
+ this.editMenuPlanAlimentaireTbarBtn.show();
+ this.viewMenuPlanAlimentaireTbarBtn.show();
+ this.partagerPlanAlimentaireTbarBtn.show();
+ this.exportPlanAlimentaireTbarBtn.show();
+ this.titlePanel.show();
+ this.allContrainteGridPanel.show();
+ this.informationPanel.hide();
+
+ //Ajout
+ if(this.planAction == "addPlanAlimentaire"){
+
+ var plan = new this.planAlimentaireStore.recordType({
+ planAlimentaireId: backObj.planAlimentaireId,
+ nomPlan: backObj.nomPlan,
+ dates: backObj.dates,
+ type: backObj.type,
+ isShare: false
+ }, backObj.planAlimentaireId);
+
+ this.planAlimentaireStore.addSorted(plan);
+ Ext.slideMsg.msg("Ajout d'un plan alimentaire", "Le plan alimentaire a correctement été ajouté.");
+
+ //Selection du plan ajoute
+ var row = this.planAlimentaireStore.indexOf(plan);
+ this.planAlimentaireGridPanel.getSelectionModel().selectRow(row);
+ this.planAlimentaireGridPanel.fireEvent("rowclick", this.planAlimentaireGridPanel, row, this);
+ }
+ //Edition
+ else {
+ var fieldSets = this.addOrEditPlanAlimentaireWindow.items;
+ for(i=0; i<fieldSets.length; i++){
+ var fieldSet = fieldSets.get(i);
+ var plan = this.planAlimentaireStore.getAt(this.planAlimentaireStore.find("planAlimentaireId", fieldSet.id));
+ plan.set("nomPlan", fieldSet.items.get(0).getValue());
+ plan.set("type", fieldSet.items.get(7).getValue());
+
+ var datesPlan = new Array();
+ var datesSelected = fieldSet.items.get(4).selectedDates;
+ for(j=0; j<datesSelected.length; j++){
+ datesPlan.push(datesSelected[j].format("Y-m-d"));
+ }
+
+ plan.set("dates", datesPlan);
+ }
+
+ this.planAlimentaireStore.sort("nomPlan", "ASC");
+ Ext.slideMsg.msg("Edition des plans alimentaire", "Les plans alimentaire ont été correctement édités.");
+ }
+
+ this.mainContainer.dates = backObj.dates;
+ this.mainContainer.titles = backObj.titles;
+
+ this.addOrEditPlanAlimentaireWindow.removeAll(true);
+ this.addOrEditPlanAlimentaireWindow.hide();
+
+ }
+ },
+
+ onFailurePlanAlimentaireAction: 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);
+ },
+
+ onDeletePlanAlimentaire: function(btn){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ Ext.MessageBox.show({
+ title: "Suppression des plans alimentaire sélectionnés",
+ msg: "Ces plans peuvent contenir des menus que vous avez définis. <br /> Souhaitez-vous continuer ?",
+ buttons: {yes: "Oui", no: "Non"},
+ fn: this.onDeletePlanAlimentaireCall,
+ animEl: 'confirmBtn',
+ icon: Ext.MessageBox.QUESTION,
+ minWidth: 350,
+ scope: this
+ });
+ }
+ },
+
+ onDeletePlanAlimentaireCall: function(btn){
+ if (btn=="no") {
+ return false;
+ }
+
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "Suppression des plans alimentaire de en cours. <br /> <b> Veuillez patienter ... </b>"});
+ this.wait.show();
+
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ var listPlansId = new Array();
+
+ for(i=0; i<plans.length; i++){
+ var plan = plans[i];
+ listPlansId.push(plan.get("planAlimentaireId"));
+ }
+
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "deletePlanAlimentaire",
+ listPlansId: Ext.util.JSON.encode(listPlansId)
+ },
+ scope: this,
+ success: this.onSuccessDeletePlanAlimentaire,
+ failure: this.onFailureDeletePlanAlimentaire
+ });
+ },
+
+ onSuccessDeletePlanAlimentaire: 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 {
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ this.planAlimentaireStore.remove(plans);
+ if(this.planAlimentaireStore.getCount() == 0){
+ this.copyPlanAlimentaireBtn.hide();
+ this.editMenuPlanAlimentaireBtn.hide();
+ this.viewMenuPlanAlimentaireBtn.hide();
+ this.partagerPlanAlimentaireBtn.hide();
+ this.exportPlanAlimentaireBtn.hide();
+ this.copyPlanAlimentaireTbarBtn.hide();
+ this.editMenuPlanAlimentaireTbarBtn.hide();
+ this.viewMenuPlanAlimentaireTbarBtn.hide();
+ this.partagerPlanAlimentaireTbarBtn.hide();
+ this.exportPlanAlimentaireTbarBtn.hide();
+ this.titlePanel.hide();
+ this.allContrainteGridPanel.hide();
+ this.informationPanel.show();
+ }
+ Ext.slideMsg.msg("Suppression des plans alimentaires", "Les plans alimentaires ont correctement été supprimés.");
+ }
+ },
+
+ onFailureDeletePlanAlimentaire: 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);
+ },
+
+ onCancelEditPlanAlimentaire: function(btn){
+ this.addOrEditPlanAlimentaireWindow.removeAll(true);
+ this.addOrEditPlanAlimentaireWindow.hide();
+ },
+
+ onRowClickPlanAlimentaireGridPanel: function(grid, rowIndex, e){
+ var record = grid.getStore().getAt(rowIndex);
+
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "<b>Chargement des informations en cours</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+
+ this.mainContainer.planAlimentaireId = record.get("planAlimentaireId");
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "getPlanInformations",
+ planAlimentaireId: record.get("planAlimentaireId")
+ },
+ scope: this,
+ success: this.onSuccessGetPlanInformations,
+ failure: this.onFailureGetPlanInformations
+ });
+ },
+
+ onSuccessGetPlanInformations: 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 {
+ var nomPlan = backObj.nomPlan;
+ if(backObj.isDiffuse){
+ this.diffusePlanAlimentaireBtn.setIconClass("unbroadcast");
+ this.diffusePlanAlimentaireBtn.setTooltip("Oter la diffusion du plan alimentaire sélectionné à l'établissement");
+ nomPlan += " (Diffusé)";
+ } else {
+ this.diffusePlanAlimentaireBtn.setIconClass("broadcast");
+ this.diffusePlanAlimentaireBtn.setTooltip("Diffuser le plan alimentaire sélectionné à l'établissement");
+ nomPlan += " (Non diffusé)";
+ }
+ this.nomPlanLabel.setText(nomPlan);
+ this.dateLabel.setText(backObj.dateIntervalle);
+ this.nomEtabLabel.setText(backObj.nomEtab);
+ this.mainContainer.dates = backObj.dates;
+ this.mainContainer.titles = backObj.titles;
+ if(backObj.isShare){
+ this.partagerPlanAlimentaireBtn.setText("Arrêter le partage");
+ this.partagerPlanAlimentaireBtn.setTooltip("Arrêter le partage du plan alimentaire sélectionné");
+ this.partagerPlanAlimentaireTbarBtn.setText("Arrêter le partage");
+ this.partagerPlanAlimentaireTbarBtn.setTooltip("Arrêter le partage du plan alimentaire sélectionné");
+ } else {
+ this.partagerPlanAlimentaireBtn.setText("Partager");
+ this.partagerPlanAlimentaireBtn.setTooltip("Partager aux autre cuisiniers le plan alimentaire sélectionné");
+ this.partagerPlanAlimentaireTbarBtn.setText("Partager");
+ this.partagerPlanAlimentaireTbarBtn.setTooltip("Partager aux autre cuisiniers le plan alimentaire sélectionné");
+ }
+ this.allContrainteStore.loadData(backObj.allContrainteStore);
+ }
+ },
+
+ onFailureGetPlanInformations: 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);
+ },
+
+ onRightClickPlanAlimentaire: function(grid, rowIndex, cellIndex, e) {
+ e.stopEvent();
+ var coords = e.getXY();
+ var entityArray = grid.getSelectionModel().getSelections();
+ var select = false;
+
+ //On selectionne la ligne si aucune ligne n'est selctionne
+ if (entityArray.length==0) {
+ grid.getSelectionModel().selectRow(rowIndex);
+ } else {
+ //On check si la ligne est selectionne
+ for (i=0; i < entityArray.length; i++) {
+ rec = entityArray[i];
+ if (!select && grid.store.indexOf(entityArray[i]) == rowIndex) {
+ select = true;
+ break;
+ }
+ }
+ //Si ce n'est pas le cas on la selectionne
+ if (select == false) {
+ grid.getSelectionModel().selectRow(rowIndex);
+ }
+ }
+
+ this.rightClicMenuPlanAlimentaire.showAt([coords[0], coords[1]]);
+ },
+
+ onRowDblClickPlanAlimentaireGridPanel: function(grid, rowIndex, e){
+ var plan = grid.store.getAt(rowIndex);
+ this.mainContainer.titlePlan = plan.get("nomPlan");
+ this.mainContainer.layout.setActiveItem(1);
+ },
+
+ onEditMenuPlanAlimentaire: function(btn){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ this.mainContainer.titlePlan = plan.get("nomPlan");
+ this.mainContainer.layout.setActiveItem(1);
+ } else {
+ Ext.MessageBox.alert("Attention", "Avant d'éditer, veuillez sélectionner un plan alimentaire.", function(btn){}, this);
+ }
+ },
+
+ onBeforeLoadAllContrainteStore: function(store){
+ this.wait = new Ext.LoadMask(this.allContrainteGridPanel.id, {msg: "<b>Chargement des contraintes en cours.</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+ },
+
+ onLoadAllContrainteStore: function(btn){
+
+ var gridView = this.allContrainteGridPanel.getView();
+ var contraintes = this.allContrainteStore.getRange();
+ for(i=0; i<contraintes.length; i++){
+ var contrainte = contraintes[i];
+
+ //Grisement des cellules qui doivent l'etre
+ if(contrainte.get("nbEntree") == ""){
+ var cell1 = gridView.getCell(i, 1);
+ cell1.bgColor = "#979797";
+ }
+ if(contrainte.get("nbPlat") == ""){
+ var cell2 = gridView.getCell(i, 2);
+ cell2.bgColor = "#979797";
+ }
+ if(contrainte.get("nbGarniture") == ""){
+ var cell3 = gridView.getCell(i, 3);
+ cell3.bgColor = "#979797";
+ }
+ if(contrainte.get("nbLait") == ""){
+ var cell4 = gridView.getCell(i, 4);
+ cell4.bgColor = "#979797";
+ }
+ if(contrainte.get("nbDessert") == ""){
+ var cell5 = gridView.getCell(i, 5);
+ cell5.bgColor = "#979797";
+ }
+
+ //Coloration de la colonne de controle
+ var controlCell = gridView.getCell(i, 7);
+ //La contrainte est respectee
+ if(contrainte.get("controle") == true){
+ controlCell.bgColor = "#75E250";
+ } else {
+ controlCell.bgColor = "#F44E4E";
+ }
+ }
+
+ this.wait.hide();
+
+ },
+
+ onPartagerPlanAlimentaire: function(btn){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "partagePlan",
+ planAlimentaireId: plan.get("planAlimentaireId")
+ },
+ scope: this,
+ success: this.onSuccessPartagePLanAlimentaire,
+ failure: this.onFailurePartagePLanAlimentaire
+ });
+ }
+ },
+
+ onSuccessPartagePLanAlimentaire: 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 {
+ //Mise à jour du record
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ plan.set("isShare", backObj.isShare);
+ }
+ if(backObj.isShare){
+ this.partagerPlanAlimentaireBtn.setText("Arrêter le partage");
+ this.partagerPlanAlimentaireBtn.setTooltip("Arrêter le partage du plan alimentaire sélectionné");
+ this.partagerPlanAlimentaireTbarBtn.setText("Arrêter le partage");
+ this.partagerPlanAlimentaireTbarBtn.setTooltip("Arrêter le partage du plan alimentaire sélectionné");
+ Ext.slideMsg.msg("Partage du plan alimentaire", "Le plan alimentaire a été correctement partagé.");
+ } else {
+ this.partagerPlanAlimentaireBtn.setText("Partager");
+ this.partagerPlanAlimentaireBtn.setTooltip("Partager aux autre cuisiniers le plan alimentaire sélectionné");
+ this.partagerPlanAlimentaireTbarBtn.setText("Partager");
+ this.partagerPlanAlimentaireTbarBtn.setTooltip("Partager aux autre cuisiniers le plan alimentaire sélectionné");
+ Ext.slideMsg.msg("Partage du plan alimentaire", "Le partage du plan alimentaire a été correctement arrêté.");
+ }
+ }
+ },
+
+ onFailurePartagePLanAlimentaire: 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);
+ },
+
+ onCopyPlanAlimentaire: function(btn){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ this.copyPlanWindow.showCopyPlanWindow(plan.get("planAlimentaireId"));
+ }
+ },
+
+ afterCopyPlanAlimentaireCallBack: function(){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ var row = this.planAlimentaireGridPanel.store.find("planAlimentaireId", plans[0].get("planAlimentaireId"));
+ this.planAlimentaireGridPanel.fireEvent("rowclick", this.planAlimentaireGridPanel, row, this);
+ },
+
+ onViewMenuPlanAlimentaire: function(btn){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ this.viewPlanWindow.setTitle(this.nomPlanLabel.text + " " + this.dateLabel.text);
+ this.viewPlanWindow.showViewPlanWindow(plan.get("planAlimentaireId"));
+ }
+ },
+
+ onGetFeuillePlanAlimentaire:function(btn){
+
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ Ext.MessageBox.show({
+ title: "Export de la feuille de contrôle",
+ msg: "Nom du fichier exporté :",
+ buttons: {yes:"Export PDF", no:"Export XLS", cancel:"Annuler"},
+ value: plan.get("nomPlan"),
+ fn: this.getFeuillePlanAlimentaireAction,
+ prompt: true,
+ minWidth:250,
+ scope: this
+ });
+ }
+ },
+
+ getFeuillePlanAlimentaireAction: function(btn, fileName){
+ if (btn=="cancel") {
+ return false;
+ }
+
+ var typeExport = (btn=="yes")?"pdf":"xls";
+
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "<b>Export de la feuille de contrôle en cours</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+
+ var contraintes = new Array();
+ var contrainteRecords = this.allContrainteStore.getRange();
+ for(i=0; i<contrainteRecords.length; i++){
+ var rec = contrainteRecords[i];
+ var contrainte = {
+ libelleGemrcn: rec.get("libelleGemrcn"),
+ nbEntree: rec.get("nbEntree"),
+ nbPlat: rec.get("nbPlat"),
+ nbGarniture: rec.get("nbGarniture"),
+ nbLait: rec.get("nbLait"),
+ nbDessert: rec.get("nbDessert"),
+ frequence: rec.get("frequence"),
+ controle: rec.get("controle"),
+ freqGlobal: rec.get("freqGlobal")
+ };
+ contraintes.push(contrainte);
+ }
+
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ var plan = plans[0];
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "getFeuilleControle",
+ typeExport: typeExport,
+ fileName: fileName,
+ planAlimentaireId: plan.get("planAlimentaireId"),
+ contraintes: Ext.util.JSON.encode(contraintes)
+ },
+ scope: this,
+ success: this.onSuccessGetFeuilleControle,
+ failure: this.onFailureGetFeuilleControle
+ });
+ },
+
+ onSuccessGetFeuilleControle: 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 {
+ Ext.slideMsg.msg("Export de la feuille de contrôle", "L'export de la feuille de contrôle au format xls a correctement été réalisé.");
+ Ext.MessageBox.show({
+ title: "Feuille de contrôle",
+ msg: backObj.hrefFile,
+ icon: Ext.MessageBox.INFO,
+ buttons: {yes:"OK"},
+ minWidth: 350
+ });
+ }
+ },
+
+ onFailureGetFeuilleControle: 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);
+ },
+
+ onExportPlanAlimentaire: function(btn){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ var datesPlan = plan.get("dates");
+ var dateFormatted = datesPlan[0].split("-");
+ var year = dateFormatted[0];
+ var month = dateFormatted[1] - 1;
+ var day = dateFormatted[2];
+ var date = new Date(year, month, day);
+ this.exportWindow.showExportWindow(date);
+ }
+ },
+
+ onDiffusePlanAlimentaire: function(btn){
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "diffusePlan",
+ planAlimentaireId: plan.get("planAlimentaireId")
+ },
+ scope: this,
+ success: this.onSuccessDiffusePLanAlimentaire,
+ failure: this.onFailureDiffusePLanAlimentaire
+ });
+ }
+ },
+
+ onSuccessDiffusePLanAlimentaire: 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 {
+ //Mise à jour du record
+ var plans = this.planAlimentaireGridPanel.getSelectionModel().getSelections();
+ if(plans.length>0){
+ var plan = plans[0];
+ plan.set("isDiffuse", backObj.isDiffuse);
+ }
+ if(backObj.isDiffuse){
+ this.diffusePlanAlimentaireBtn.setIconClass("unbroadcast");
+ this.diffusePlanAlimentaireBtn.setTooltip("Oter la diffusion du plan alimentaire sélectionné à l'établissement");
+ Ext.slideMsg.msg("Diffusion du plan alimentaire", "Le plan alimentaire a été correctement diffusé.");
+ } else {
+ this.diffusePlanAlimentaireBtn.setIconClass("broadcast");
+ this.diffusePlanAlimentaireBtn.setTooltip("Diffuser le plan alimentaire sélectionné à l'établissement");
+ Ext.slideMsg.msg("Diffusion du plan alimentaire", "La diffusion du plan alimentaire sélectionné a été correctement otée.");
+ }
+ }
+ },
+
+ onFailureDiffusePLanAlimentaire: 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);
+ }
+});