--- /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.CantineConsultation");
+EntSavoie.CantineConsultation.MainCantineConsultation = 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.styleSheetForPrint =
+ '.menuTitleCls{' +
+ ' font-size: 16px;' +
+ ' font-family: Comic Sans MS;' +
+ ' font-weight: bold !important;' +
+ ' padding-top: 10px;' +
+ ' border: solid 1px;' +
+ '}' +
+
+ '.menuUnderlineTdCls{' +
+ ' padding-top: 5px;' +
+ '}' +
+
+ '.menuUnderlineCls{' +
+ ' background-repeat: no-repeat;' +
+ ' height: 15px;' +
+ ' width: 340px;' +
+ '}' +
+
+ '.menuCategorieCls{' +
+ ' font-size: 18px;' +
+ ' font-family: Coronetscript, cursive;' +
+ ' font-weight: bold !important;' +
+ ' padding-top: 20px;' +
+ '}' +
+
+ '.menuRecetteCls{' +
+ ' font-size: 14px;' +
+ ' font-family: Comic Sans MS;' +
+ ' font-weight: bold !important;' +
+ ' padding-top: 10px;' +
+ '}' +
+
+ '.tableViewWeekContainerCls{' +
+ ' margin-left: 25px;' +
+ ' margin-right: 25px;' +
+ '}' +
+
+ '.tableViewWeekCls td{' +
+ ' border: solid 1px;' +
+ '}' +
+
+ '.menuWeekTitleCls{' +
+ ' font-size: 16px;' +
+ ' font-family: Comic Sans MS;' +
+ ' font-weight: bold !important;' +
+ ' padding-top: 10px;' +
+ '}' +
+
+ '.menuWeekTableHeaderCls{' +
+ ' font-size: 14px;' +
+ ' font-family: Comic Sans MS;' +
+ ' font-weight: bold !important;' +
+ '}' +
+
+ '.menuWeekRecetteCls{' +
+ ' font-size: 13px;' +
+ ' font-family: Comic Sans MS;' +
+ ' font-weight: bold !important;' +
+ ' padding-top: 10px;' +
+ '}';
+
+ this.menuPanel = this.menuPanel || new Ext.Panel({
+ border: false,
+ bodyStyle: "background-color: transparent;",
+ height: 510,
+ autoScroll: true,
+ html: ""
+ });
+
+ this.closeMenuConsultationBtn = this.closeMenuConsultationBtn || new Ext.BoxComponent({
+ autoEl: {
+ tag: 'div',
+ cls: 'closeMenuConsultationCls'
+ }
+ });
+
+ this.printMenuConsultationBtn = this.printMenuConsultationBtn || new Ext.BoxComponent({
+ autoEl: {
+ tag: 'div',
+ cls: 'printMenuConsultationCls'
+ }
+ });
+
+ this.dayAndNightMenuConsultationBtn = this.dayAndNightMenuConsultationBtn || new Ext.BoxComponent({
+ width: 140,
+ autoEl: {
+ tag: 'div',
+ html: 'Voir le menu du soir',
+ cls: 'dayAndNightMenuConsultationCls'
+ //cls: 'dayMenuConsultationCls'
+ },
+ hidden: !hasInternat
+ });
+
+ this.viewDayOrNightMenuConsultationPanel = this.viewDayOrNightMenuConsultationPanel || new Ext.Panel({
+ columnWidth: .999999,
+ border: false,
+ bodyStyle: "background-color: transparent;",
+ items: [this.dayAndNightMenuConsultationBtn]
+ });
+
+ this.leftMenuConsultationBtn = this.leftMenuConsultationBtn || new Ext.BoxComponent({
+ autoEl: {
+ tag: 'div',
+ cls: 'leftMenuConsultationCls'
+ }
+ });
+
+ this.rightMenuConsultationBtn = this.rightMenuConsultationBtn || new Ext.BoxComponent({
+ autoEl: {
+ tag: 'div',
+ cls: 'rightMenuConsultationCls'
+ }
+ });
+
+ this.viewDayOrWeekMenuConsultationBtn = this.viewWeekMenuConsultationBtn || new Ext.BoxComponent({
+ width: 100,
+ autoEl: {
+ tag: 'div',
+ html: 'Vue Semaine',
+ cls: 'viewWeekConsultationCls'
+ }
+ });
+
+ this.viewDayOrWeekMenuConsultationPanel = this.viewDayOrWeekMenuConsultationPanel || new Ext.Panel({
+ columnWidth: .999999,
+ border: false,
+ bodyStyle: "background-color: transparent;",
+ items: [this.viewDayOrWeekMenuConsultationBtn]
+ });
+
+ /**
+ * Constructeur
+ */
+ EntSavoie.CantineConsultation.MainCantineConsultation.superclass.constructor.call(this, {
+ draggable: {
+ //Config option of Ext.Panel.DD class.
+ //It's a floating Panel, so do not show a placeholder proxy in the original position.
+ insertProxy: false,
+
+ //Called for each mousemove event while dragging the DD object.
+ onDrag : function(e){
+ //Record the x,y position of the drag proxy so that we can
+ //position the Panel at end of drag.
+ var pel = this.proxy.getEl();
+ this.x = pel.getLeft(true);
+ this.y = pel.getTop(true);
+
+ //Keep the Shadow aligned if there is one.
+ var s = this.panel.getEl().shadow;
+ if (s) {
+ s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
+ }
+ },
+
+ //Called on the mouseup event.
+ endDrag : function(e){
+ this.panel.position = [this.x, this.y];
+ this.panel.setPosition(this.x, this.y);
+ }
+ },
+ style: "left:-1000px;top:-1000px;",
+ border: true,
+ height: 600,
+ width: 400,
+ floating: {
+ shadow: true,
+ shim: true,
+ useDisplay: true,
+ constrain: false
+ },
+ layout: 'form',
+ bodyStyle: "background-color: transparent;",
+ bodyCssClass: "cantineConsultationDayWindowClass",
+ items: [
+ {
+ border: false,
+ bodyStyle: "background-color: transparent;",
+ height: 45,
+ layout: 'column',
+ layoutConfig: {
+ columns: 3
+ },
+ items: [this.printMenuConsultationBtn, this.viewDayOrNightMenuConsultationPanel, this.closeMenuConsultationBtn]
+ },
+ this.menuPanel,
+ {
+ border: false,
+ bodyStyle: "background-color: transparent;",
+ height: 25,
+ layout: 'column',
+ layoutConfig: {
+ columns: 3
+ },
+ items: [this.leftMenuConsultationBtn, this.viewDayOrWeekMenuConsultationPanel, this.rightMenuConsultationBtn]
+ }
+ ]
+ });
+
+ this.closeMenuConsultationBtn.on("render", this.onRenderCloseMenuConsultationBtn, this);
+ this.printMenuConsultationBtn.on("render", this.onRenderPrintMenuConsultationBtn, this);
+ this.leftMenuConsultationBtn.on("render", this.onRenderLeftMenuConsultationBtn, this);
+ this.rightMenuConsultationBtn.on("render", this.onRenderRightMenuConsultationBtn, this);
+ this.dayAndNightMenuConsultationBtn.on("render", this.onRenderDayAndNightMenuConsultationBtn, this);
+ this.viewDayOrWeekMenuConsultationBtn.on("render", this.onRenderViewDayOrWeekMenuConsultationBtn, this);
+
+
+};
+
+Ext.extend(EntSavoie.CantineConsultation.MainCantineConsultation, Ext.Panel, {
+ initComponent: function () {
+ EntSavoie.CantineConsultation.MainCantineConsultation.superclass.initComponent.call(this);
+ },
+
+ onRenderCloseMenuConsultationBtn: function(el){
+ el.getEl().on('click', this.onCloseFn, this);
+ },
+
+ onRenderPrintMenuConsultationBtn: function(el){
+ el.getEl().on('click', this.onPrintFn, this);
+ },
+
+ onRenderLeftMenuConsultationBtn: function(el){
+ el.getEl().on('click', this.onLeftFn, this);
+ },
+
+ onRenderRightMenuConsultationBtn: function(el){
+ el.getEl().on('click', this.onRightFn, this);
+ },
+
+ onRenderDayAndNightMenuConsultationBtn: function(el){
+ el.getEl().on('click', this.onDayAndNightFn, this);
+ },
+
+ onRenderViewDayOrWeekMenuConsultationBtn: function(el){
+ el.getEl().on('click', this.onViewDayOrWeekFn, this);
+ },
+
+ onCloseFn: function(){
+ this.position = this.getPosition();
+ this.showAt([-1000, -1000]);
+ },
+
+ onPrintFn: function(){
+ var html = '<html>' +
+ '<head>' +
+ '<meta content="text/html; charset=utf-8" http-equiv="Content-Type">' +
+ '<style type="text/css">' +
+ this.styleSheetForPrint +
+ '@media print' +
+ '{' +
+ this.styleSheetForPrint +
+ '}' +
+ '</style>' +
+ '<title>Menu</title>' +
+ '</head>' +
+ '<body>' +
+ this.htmlMenu +
+ '</body>' +
+ '</html>';
+
+ var win = window.open("", "");
+ win.document.write(html);
+ win.print();
+ },
+
+ showAt: function (xy){
+ this.setPagePosition(xy[0], xy[1]);
+ },
+
+ onLeftFn: function(btn){
+ if(this.isDayView){
+ this.date = this.date.add(Date.DAY, -1);
+ } else {
+ this.date = this.date.add(Date.DAY, -7);
+ }
+ this.showCantineConsultationWindow();
+ },
+
+ onRightFn: function(btn){
+ if(this.isDayView){
+ this.date = this.date.add(Date.DAY, 1);
+ } else {
+ this.date = this.date.add(Date.DAY, 7);
+ }
+ this.showCantineConsultationWindow();
+ },
+
+ onDayAndNightFn: function(btn){
+ this.isMidi = !this.isMidi;
+ //Modification de la classe
+ if(this.isMidi){
+ this.dayAndNightMenuConsultationBtn.getEl().update("Voir le menu du soir", true);
+ } else {
+ this.dayAndNightMenuConsultationBtn.getEl().update("Voir le menu du midi", true);
+ }
+ this.showCantineConsultationWindow();
+ },
+
+ onViewDayOrWeekFn: function(){
+ this.isDayView = !this.isDayView;
+ if(this.isDayView){
+ this.setWidth(400);
+ this.body.removeClass("cantineConsultationWeekWindowClass");
+ this.body.addClass("cantineConsultationDayWindowClass");
+ this.viewDayOrWeekMenuConsultationBtn.getEl().update("Vue Semaine", true);
+ } else {
+ this.setWidth(1000);
+ this.body.removeClass("cantineConsultationDayWindowClass");
+ this.body.addClass("cantineConsultationWeekWindowClass");
+ this.viewDayOrWeekMenuConsultationBtn.getEl().update("Vue Jour", true);
+ }
+ this.showCantineConsultationWindow();
+ },
+
+ showCantineConsultationWindow: function(){
+
+ //Si le menu est affiche
+ if(this.getPosition()[0] >= 0){
+ this.wait = new Ext.LoadMask(this.id, {msg: "<b>Changement des informations en cours.</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+ } else {
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "<b>Changement des informations en cours.</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+ }
+
+ if(!this.date){
+ this.date = (new Date());
+ }
+
+ if(this.isMidi == null){
+ this.isMidi = true;
+ }
+
+ if(this.isDayView == null){
+ this.isDayView = true;
+ }
+
+ if(this.isDayView){
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "getMenuDayForConsultation",
+ date: this.date.format("Y-m-d"),
+ isMidi: this.isMidi
+ },
+ scope: this,
+ success: this.onSuccessGetMenuDayForConsultation,
+ failure: this.onFailureGetMenuDayForConsultation
+ });
+
+ } else {
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "getMenuWeekForConsultation",
+ date: this.date.format("Y-m-d"),
+ isMidi: this.isMidi
+ },
+ scope: this,
+ success: this.onSuccessGetMenuWeekForConsultation,
+ failure: this.onFailureGetMenuWeekForConsultation
+ });
+
+ }
+ },
+
+ onSuccessGetMenuDayForConsultation: 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 html = "";
+
+ var entrees = Ext.decode(backObj.entrees);
+ var plats = Ext.decode(backObj.plats);
+ var garnitures = Ext.decode(backObj.garnitures);
+ var fromages = Ext.decode(backObj.fromages);
+ var desserts = Ext.decode(backObj.desserts);
+
+
+ html = "<table width='100%'>";
+
+ //Titre du menu
+ html += "<tr>" +
+ "<td width='100%' align='center' class='menuTitleCls'>" +
+ backObj.menuTitle +
+ "</td>" +
+ "</tr>";
+
+ html += "<tr>" +
+ "<td width='100%' align='center' class='menuUnderlineTdCls'>" +
+ "<img class='menuUnderlineCls' src='/html/js/extjs/resources/images/default/s.gif'>" +
+ "</td>" +
+ "</tr>";
+
+ /**
+ * Entrees
+ */
+ html += "<tr>" +
+ "<td align='center' class='menuCategorieCls'>" +
+ "- Entrées -" +
+ "</td>" +
+ "</tr>";
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuRecetteCls'>";
+ for(i=0; i<entrees.length; i++){
+ html += entrees[i] + "<br/>";
+ }
+ html += "</div>" +
+ "</td>" +
+ "</tr>";
+
+ /**
+ * Plats
+ */
+ html += "<tr>" +
+ "<td align='center' class='menuCategorieCls'>" +
+ "- Plats -" +
+ "</td>" +
+ "</tr>";
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuRecetteCls'>";
+ for(i=0; i<plats.length; i++){
+ html += plats[i] + "<br/>";
+ }
+ html += "</div>" +
+ "</td>" +
+ "</tr>";
+
+ /**
+ * Garnitures
+ */
+ html += "<tr>" +
+ "<td align='center' class='menuCategorieCls'>" +
+ "- Garnitures -" +
+ "</td>" +
+ "</tr>";
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuRecetteCls'>";
+ for(i=0; i<garnitures.length; i++){
+ html += garnitures[i] + "<br/>";
+ }
+ html += "</div>" +
+ "</td>" +
+ "</tr>";
+
+ /**
+ * Fromages
+ */
+ html += "<tr>" +
+ "<td align='center' class='menuCategorieCls'>" +
+ "- Fromages -" +
+ "</td>" +
+ "</tr>";
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuRecetteCls'>";
+ for(i=0; i<fromages.length; i++){
+ html += fromages[i] + "<br/>";
+ }
+ html += "</div>" +
+ "</td>" +
+ "</tr>";
+
+ /**
+ * Desserts
+ */
+ html += "<tr>" +
+ "<td align='center' class='menuCategorieCls'>" +
+ "- Desserts -" +
+ "</td>" +
+ "</tr>";
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuRecetteCls'>";
+ for(i=0; i<desserts.length; i++){
+ html += desserts[i] + "<br/>";
+ }
+ html += "</div>" +
+ "</td>" +
+ "</tr>";
+
+ html += "</table>";
+
+ this.htmlMenu = html;
+
+ this.menuPanel.body.update(html, true);
+ this.showAt(this.calculatePosition());
+ }
+ },
+
+ onFailureGetMenuDayForConsultation: 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);
+ },
+
+ onSuccessGetMenuWeekForConsultation: 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 html = "";
+
+ var days = Ext.decode(backObj.days);
+ var entrees = Ext.decode(backObj.entrees);
+ var plats = Ext.decode(backObj.plats);
+ var garnitures = Ext.decode(backObj.garnitures);
+ var fromages = Ext.decode(backObj.fromages);
+ var desserts = Ext.decode(backObj.desserts);
+
+ //Title
+ html += "<div width='100%' align='center' class='menuWeekTitleCls'>" +
+ backObj.menuTitle +
+ "</div>";
+
+ html += "<br/>";
+
+ html += "<div class='tableViewWeekContainerCls'>";
+ html += "<table class='tableViewWeekCls' width='100%'>";
+
+ /**
+ * Premiere ligne
+ */
+ html += "<tr>" +
+ "<td align='center'>" +
+ //Pas de contenu
+ "</td>";
+ //On ajoutes les jours
+ for(i=0; i<days.length; i++){
+ html += "<td align='center' class='menuWeekTableHeaderCls'>" +
+ days[i] +
+ "</td>";
+ }
+ html += "</tr>";
+
+ /**
+ * Deuxieme ligne
+ */
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuWeekTableHeaderCls'> Entrees </div>" +
+ "<img src='/html/js/extjs/pentila/img/cantine/entree.png'>" +
+ "</td>";
+ //On ajoutes les entrees
+ for(i=0; i<entrees.length; i++){
+ var entreesMenu = entrees[i];
+ html += "<td align='center'>";
+ html += "<div class='menuWeekRecetteCls'>";
+ for(j=0; j<entreesMenu.length; j++){
+ html += entreesMenu[j] + "<br />";
+ }
+ html += "</div>";
+ html += "</td>";
+ }
+ html += "</tr>";
+
+ /**
+ * Troisieme ligne
+ */
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuWeekTableHeaderCls'> Plats </div>" +
+ "<img src='/html/js/extjs/pentila/img/cantine/plat.png'>" +
+ "</td>";
+ //On ajoutes les plats
+ for(i=0; i<plats.length; i++){
+ var platsMenu = plats[i];
+ html += "<td align='center'>";
+ html += "<div class='menuWeekRecetteCls'>";
+ for(j=0; j<platsMenu.length; j++){
+ html += platsMenu[j] + "<br />";
+ }
+ html += "</div>";
+ html += "</td>";
+ }
+ html += "</tr>";
+
+ /**
+ * Quatrieme ligne
+ */
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuWeekTableHeaderCls'> Garnitures </div>" +
+ "<img src='/html/js/extjs/pentila/img/cantine/garniture.png'>" +
+ "</td>";
+ //On ajoutes les plats
+ for(i=0; i<garnitures.length; i++){
+ var garnituresMenu = garnitures[i];
+ html += "<td align='center'>";
+ html += "<div class='menuWeekRecetteCls'>";
+ for(j=0; j<garnituresMenu.length; j++){
+ html += garnituresMenu[j] + "<br />";
+ }
+ html += "</div>";
+ html += "</td>";
+ }
+ html += "</tr>";
+
+ /**
+ * Cinquieme ligne
+ */
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuWeekTableHeaderCls'> Fromages </div>" +
+ "<img src='/html/js/extjs/pentila/img/cantine/fromage.png'>" +
+ "</td>";
+ //On ajoutes les plats
+ for(i=0; i<fromages.length; i++){
+ var fromagesMenu = fromages[i];
+ html += "<td align='center'>";
+ html += "<div class='menuWeekRecetteCls'>";
+ for(j=0; j<fromagesMenu.length; j++){
+ html += fromagesMenu[j] + "<br />";
+ }
+ html += "</div>";
+ html += "</td>";
+ }
+ html += "</tr>";
+
+ /**
+ * Sixieme ligne
+ */
+ html += "<tr>" +
+ "<td align='center'>" +
+ "<div class='menuWeekTableHeaderCls'> Desserts </div>" +
+ "<img src='/html/js/extjs/pentila/img/cantine/dessert.png'>" +
+ "</td>";
+ //On ajoutes les plats
+ for(i=0; i<desserts.length; i++){
+ var dessertsMenu = desserts[i];
+ html += "<td align='center'>";
+ html += "<div class='menuWeekRecetteCls'>";
+ for(j=0; j<dessertsMenu.length; j++){
+ html += dessertsMenu[j] + "<br />";
+ }
+ html += "</div>";
+ html += "</td>";
+ }
+ html += "</tr>";
+ html += "</table>";
+ html += "</div>";
+
+ this.htmlMenu = html;
+ this.menuPanel.body.update(html, true);
+
+ this.showAt(this.calculatePosition());
+
+ }
+ },
+
+ onFailureGetMenuWeekForConsultation: 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);
+ },
+
+ calculatePosition: function(){
+ if(this.getPosition()[0] < 0){
+ if(EntSavoie.FullScreen.fired()){
+ // Identifiant defini dans FullScreen.js
+ var cantineButton = document.getElementById("cantineFullScreen");
+ var xy = getPosition(cantineButton);
+ xy[0] -= this.getWidth() - cantineButton.clientWidth;
+ xy[1] += cantineButton.clientHeight;
+ this.position = xy;
+ this.inFullScreen = true;
+ EntSavoie.FullScreen.hideModalPanels();
+ EntSavoie.FullScreen.addModalPanel(this.id);
+ } else {
+ if(this.inFullScreen || this.position == null){
+ this.position = [50, 50];
+ this.inFullScreen = false;
+ }
+ }
+
+ return this.position;
+ }
+
+ return this.getPosition();
+ }
+
+});