--- /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.Atelier");
+EntSavoie.Atelier.RequestLifeExtension = 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';
+
+ // flag pour forcer le refresh
+ this.forceRefresh = true;
+
+ // stock le record sur lequel on agit
+ this.actionRecord = null;
+
+ // definition du store
+ this.requestLifeExtension_store = this.requestLifeExtension_store || new Ext.data.JsonStore({
+ root: 'community',
+ idProperty: 'id',
+ fields: ["id", "name", "description", "expirationDate", "desiredExtension", {name: "hideDesc", type: "boolean"}],
+ url: this.renderURLAjax+"&jspPage=/requestLifeExtension.jsp"
+ });
+
+ this.action_column = this.action_column || new Ext.grid.ActionColumn({
+ header: this.i18n.Atelier.RequestLifeExtension.action_column.header,
+ width: 60,
+ sortable: false,
+ menuDisabled: true,
+ align: 'center',
+ items: [
+ {iconCls: 'approved', // Use a URL in the icon config
+ tooltip: this.i18n.Atelier.RequestLifeExtension.action_column.items.approved.tooltip,
+ handler: this.onApprovedGrpAction,
+ scope: this
+ },
+ {iconCls: 'refused', // Use a URL in the icon config
+ tooltip: this.i18n.Atelier.RequestLifeExtension.action_column.items.refused.tooltip,
+ handler: this.onRefusedGrpAction,
+ scope: this
+ }
+ ]
+ });
+
+ this.action_column_description = this.action_column_description || new Ext.grid.ActionColumn({
+ header: this.i18n.Atelier.RequestLifeExtension.action_column_description.header,
+ width: 65,
+ sortable: false,
+ menuDisabled: true,
+ align: 'center',
+ items: [
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (rec.get('hideDesc') == false) {
+ return 'description';
+ }
+ },
+ tooltip: this.i18n.Atelier.RequestLifeExtension.action_column_description.items.descr.tooltip,
+ scope: this,
+ handler: this.onActionGrpActionDesc
+ }
+ ]
+ });
+
+ // definition du grid
+ this.requestLifeExtension_grid = this.requestLifeExtension_grid || new Ext.grid.GridPanel({
+ loadMask: true,
+ disableSelection: true,
+ border:false,
+ store: this.requestLifeExtension_store,
+ forcefit:'true',
+ autoExpandColumn: 'name',
+ columns: [
+ this.action_column_description,
+ {
+ header: this.i18n.Atelier.RequestLifeExtension.requestLifeExtension_grid.columns[0],
+ id: 'name',
+ dataIndex: 'name',
+ sortable: true
+ },
+ {
+ header: this.i18n.Atelier.RequestLifeExtension.requestLifeExtension_grid.columns[1],
+ dataIndex: 'expirationDate',
+ width: 200,
+ sortable: false
+ },
+ {
+ header: this.i18n.Atelier.RequestLifeExtension.requestLifeExtension_grid.columns[2],
+ dataIndex: 'desiredExtension',
+ width: 200,
+ sortable: false
+ },
+ this.action_column
+ ],
+ height: 150
+ });
+
+ EntSavoie.Atelier.RequestLifeExtension.superclass.constructor.call(this, {
+ hidden: true,
+ border: false,
+ width: "auto",
+ layout: 'fit',
+ height: 155,
+ title: this.i18n.Atelier.RequestLifeExtension.title,
+ monitorResize: true,
+ items: [this.requestLifeExtension_grid]
+ });
+
+ // definition des listeners
+ this.requestLifeExtension_grid.on("viewready", this.onRenderPanel, this);
+ this.requestLifeExtension_store.on("load", this.onLoadRequestLifeExtensionStore, this);
+ //this.grpActionDesc.on("action", this.onActionGrpActionDesc, this);
+ //this.grpAction.on("action", this.onActionGrpAction, this);
+ this.on("activate", this.onActivate, this);
+
+
+};
+
+Ext.extend(EntSavoie.Atelier.RequestLifeExtension, Ext.Panel, {
+ initComponent: function () {
+ EntSavoie.Atelier.RequestLifeExtension.superclass.initComponent.call(this);
+ },
+
+ onActivate: function(panel){
+ this.refreshInfos();
+ },
+
+ refreshInfos: function() {
+ if (this.isGrpAdmin) {
+ this.requestLifeExtension_store.load();
+ }
+ },
+
+ onRenderPanel: function(grid) {
+ if (this.isGrpAdmin) {
+ this.requestLifeExtension_store.load();
+ }
+ },
+
+ onLoadRequestLifeExtensionStore: function(store, records, e){
+ if (records.length==0) {
+ //alert('ici hide');
+ this.accessAtelier.requestLifeExtension.hide();
+ }
+ else {
+ //alert('ici show');
+ this.accessAtelier.requestLifeExtension.show();
+ }
+ },
+
+ onActionGrpActionDesc: function(grid, rowIndex, colIndex) {
+ var record = grid.getStore().getAt(rowIndex);
+ Ext.Msg.show({
+ title: this.i18n.Atelier.RequestLifeExtension.onActionGrpActionDesc.Msg.title,
+ msg: record.get('description'),
+ modal:true,
+ width: 250,
+ icon:Ext.Msg.INFO,
+ buttons:Ext.Msg.OK
+ });
+ },
+
+ onApprovedGrpAction: function(grid, rowIndex, colIndex) {
+ this.actionRecord = grid.getStore().getAt(rowIndex);
+ Ext.MessageBox.show({
+ icon:Ext.Msg.QUESTION,
+ title: this.i18n.Atelier.RequestLifeExtension.onApprovedGrpAction.MessageBox.title,
+ msg: this.i18n.Atelier.RequestLifeExtension.onApprovedGrpAction.MessageBox.msg,
+ buttons: {yes: this.i18n.Atelier.RequestLifeExtension.onApprovedGrpAction.MessageBox.buttons.yes, cancel: this.i18n.Atelier.RequestLifeExtension.onApprovedGrpAction.MessageBox.buttons.cancel},
+ fn: this.onApproved_call,
+ scope: this
+ });
+ },
+
+ onRefusedGrpAction: function(grid, rowIndex, colIndex) {
+ this.actionRecord = grid.getStore().getAt(rowIndex);
+ Ext.MessageBox.show({
+ icon:Ext.Msg.QUESTION,
+ title: this.i18n.Atelier.RequestLifeExtension.onRefusedGrpAction.MessageBox.title,
+ msg: this.i18n.Atelier.RequestLifeExtension.onRefusedGrpAction.MessageBox.msg,
+ buttons: {yes: this.i18n.Atelier.RequestLifeExtension.onRefusedGrpAction.MessageBox.buttons.yes, cancel: this.i18n.Atelier.RequestLifeExtension.onRefusedGrpAction.MessageBox.buttons.cancel},
+ fn: this.onRefused_call,
+ scope: this
+ });
+ },
+
+ onApproved_call: function(btn) {
+ if(btn=="cancel") {
+ return false;
+ }
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "approvedRequestLifeExtension",
+ groupId: this.actionRecord.get("id")
+ },
+ scope: this,
+ success: this.onSuccessApproved,
+ failure: this.onFailureAction
+ });
+
+ },
+
+ onSuccessApproved:function(response, options) {
+ this.requestLifeExtension_store.remove(this.actionRecord);
+ if (this.requestLifeExtension_store.getCount()==0) {
+ this.requestLifeExtension_grid.hide();
+ }
+ this.actionRecord = null;
+ },
+
+ onFailureAction:function(response, options) {
+ this.refreshInfos();
+ Ext.MessageBox.alert( this.i18n.Atelier.RequestLifeExtension.onFailureAction.alert.title, this.i18n.Atelier.RequestLifeExtension.onFailureAction.alert.msg, function(btn){});
+ },
+
+ onRefused_call: function(btn) {
+ if(btn=="cancel") {
+ return false;
+ }
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "refusedRequestLifeExtension",
+ groupId: this.actionRecord.get("id")
+ },
+ scope: this,
+ success: this.onSuccessRefused,
+ failure: this.onFailureAction
+ });
+
+ },
+
+ onSuccessRefused:function(response, options) {
+ this.requestLifeExtension_store.remove(this.actionRecord);
+ if (this.requestLifeExtension_store.getCount()==0) {
+ this.requestLifeExtension_grid.hide();
+ }
+ this.actionRecord = null;
+ }
+
+});