--- /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.UserComponent");
+EntSavoie.UserComponent.DestinataireChooser = 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.chooseDestinataireBtn = this.chooseDestinataireBtn || new Ext.Button({
+ //width: 150,
+ text: this.chooseDestinataireBtnTxt || this.i18n.UserComponent.DestinataireChooser.chooseDestinataireBtn.text,
+ handler: this.onShowSelectDestinataireFn,
+ style: this.chooseDestBtnStyle || "margin-right: 10px;",
+ tooltip: this.chooseDestinataireBtnTooltip || "",
+ scope: this
+ });
+
+ // Panel de gestion des destinataires
+
+ // on redefinit les destinataires
+ this.membreRecordCreator = Ext.data.Record.create(["type",
+ "orgId",
+ "roleId",
+ "listId",
+ "id",
+ "parentList",
+ "childrenList",
+ "displayText",
+ "admin"]);
+
+ this.membres_store = this.membres_store || new Ext.data.Store( {
+ fields : [ "id", "displayText", "type", "orgId", "roleId", "listId", "parentList", "childrenList", "admin"],
+ sortInfo: {
+ field: 'displayText',
+ direction: 'ASC' // or 'DESC' (case sensitive for local sorting)
+ }
+ });
+
+ this.membresPaggingTB = this.membresPaggingTB || new Ext.PagingToolbar({
+ hidden: true,
+ pageSize: 18,
+ store: this.membres_store,
+ displayInfo: false,
+ displayMsg: '',
+ emptyMsg: "",
+ cls: "no-border-paging-toolbar",
+ items:[]
+ });
+
+ // the check column is created using a custom plugin
+ this.checkColumn = this.checkColumn || "no column";
+
+ this.title_membres_grid = this.title_membres_grid || new Ext.form.DisplayField({
+ value: this.i18n.UserComponent.DestinataireChooser.title_membres_grid.value,
+ cls: "title-membre-grid",
+ style: "color: #15428B"
+ });
+
+ this.retirerMembresBtn = this.retirerMembresBtn || new Ext.Button({
+ text: this.i18n.UserComponent.DestinataireChooser.retirerMembresBtn.text,
+ iconCls: 'remove-receiver',
+ handler: this.retirerMembres,
+ scope: this
+ });
+
+ this.membreGridTBar = this.membreGridTBar || new Ext.Toolbar({
+ items: [
+ this.title_membres_grid,
+ '->',
+ this.retirerMembresBtn
+ ]
+ });
+
+ this.membres_grid = this.membres_grid || new Ext.grid.GridPanel({
+ enableDragDrop: true,
+ border: false,
+ ddGroup : "retirerMembresDD",
+ ddText : this.membres_gridddText || this.i18n.UserComponent.DestinataireChooser.membres_grid.ddText,
+ store : this.membres_store,
+ autoExpandColumn: 'nom',
+ columns :
+ [{ header : this.i18n.UserComponent.DestinataireChooser.membres_grid.header,
+ id: 'nom',
+ dataIndex : "displayText",
+ sortable : false,
+ width: 165,
+ editable: false
+ }],
+ tbar: this.membreGridTBar,
+ /*tbar : [{
+ text : 'Retirer',
+ iconCls : 'remove-receiver',
+ handler : this.retirerMembres,
+ scope: this
+ }, '-' ],*/
+ bbar: [this.membresPaggingTB]
+ //title : this.membres_gridddTitle || "Destinataires"
+ });
+
+
+ // on definit maintenant le composant
+ this.destinatairesPanel = this.destinatairesPanel || new EntSavoie.Atelier.GestionMembres({
+ renderURLAjax: this.renderURLAjax,
+ userGroupId: this.userGroupId,
+ width: 688,
+ height: 500,
+ border: false,
+ //bkdStyle: 'margin : Opx !important;',
+ membreRecordCreator: this.membreRecordCreator,
+ checkColumn: this.checkColumn,
+ membres_store: this.membres_store,
+ membresPaggingTB: this.membresPaggingTB,
+ membres_grid: this.membres_grid,
+ heightGridListContacts: 500,
+ heightGridListContactMembers: 500,
+ heightGridListGroupMembers: 500,
+ checkColumnLabel: this.checkColumnLabel || "",
+ isGroupManagment: this.isGroupManagment,
+ hasDirectoryRights : this.hasDirectoryRights
+ });
+
+ this.addDestinataireBtn = this.addDestinataireBtn || new Ext.Button({
+ minWidth: 80,
+ text: this.i18n.UserComponent.DestinataireChooser.addDestinataireBtn.text,
+ handler: this.onAddDestFn,
+ scope: this
+ });
+
+ this.cancelDestinataireBtn = this.cancelDestinataireBtn || new Ext.Button({
+ minWidth: 80,
+ text: this.i18n.UserComponent.DestinataireChooser.cancelDestinataireBtn.text,
+ handler: this.onCancelDestFn,
+ scope: this
+ });
+
+ this.chooseWindow = this.chooseWindow || new Ext.Window({
+ title: this.chooseWindowTitle || this.i18n.UserComponent.DestinataireChooser.chooseWindow.title,
+ hidden: true,
+ border: false,
+ resizable: false,
+ modal: true,
+ closeAction: 'hide',
+ closable: false,
+ layout: "fit",
+ width: 875,
+ height: 564,
+ items: [this.destinatairesPanel],
+ buttons: [this.addDestinataireBtn, this.cancelDestinataireBtn]
+ });
+
+ // affichage via un combo des destinataires choisis
+ this.destComboRecord = Ext.data.Record.create([
+ "name",
+ "destId",
+ "admin"
+ ]);
+
+ this.destStore = this.destStore || new Ext.data.SimpleStore({
+ fields : [ "destId", "name", "admin"],
+ sortInfo: {
+ field: 'name',
+ direction: 'ASC'
+ },
+ data:[]
+ });
+
+ this.viewDestCombo = this.viewDestCombo || new Ext.form.ComboBox({
+ emptyText: this.viewDestComboEmptyText || this.i18n.UserComponent.DestinataireChooser.viewDestCombo.emptyText,
+ valueField: 'destId',
+ displayField: 'name',
+ editable: false,
+ triggerAction: 'all',
+ store: this.destStore,
+ width: 200,
+ mode: "local",
+ allowBlank: this.viewDestComboAllowBlank || false
+ });
+
+ this.mainTableWidth = this.mainTableWidth || 470;
+
+ EntSavoie.UserComponent.DestinataireChooser.superclass.constructor.call(this, {
+ border: false,
+ layout: 'table',
+ layoutConfig: {
+ tableAttrs: {
+ style: "width: " + this.mainTableWidth + "px;"
+ },
+ columns: 3
+ },
+ style: this.destChooserStyle || "margin-bottom: 2px; margin-right : 5px;",
+ labelAlign: 'left',
+ hideLabel: false,
+ items: [
+ this.chooseDestinataireBtn,
+ {
+ style : "margin-left : 2px; margin-right : 5px;",
+ border : false,
+ width : this.comboFieldLabelWidth || 0,
+ html : this.viewDestComboFieldLabel || ""
+ },
+ {
+ style : "margin-left : 2px; margin-right : 5px;",
+ border : false,
+ width : this.comboTDWidth || 300,
+ items : [this.viewDestCombo]
+ }
+ ]
+ });
+
+ // definition des listeners
+
+};
+
+Ext.extend(EntSavoie.UserComponent.DestinataireChooser, Ext.Panel, {
+ initComponent: function () {
+ EntSavoie.UserComponent.DestinataireChooser.superclass.initComponent.call(this);
+ },
+
+ onShowSelectDestinataireFn: function(btn) {
+ // on affiche la fenetre
+ this.chooseWindow.show();
+ },
+
+ onAddDestFn: function(btn) {
+ this.chooseWindow.hide();
+ this.destStore.removeAll();
+ for (i=0; i<this.membres_store.getCount(); i++) {
+ var rec = this.membres_store.getAt(i);
+ this.destStore.addSorted(new this.destComboRecord({name: rec.get('displayText'),
+ destId: rec.get("id")}));
+ }
+ if (this.membres_store.getCount()>0) {
+ this.viewDestCombo.enable();
+ this.viewDestCombo.setValue(this.destStore.getAt(0).get('destId'));
+ }
+ else {
+ this.viewDestCombo.reset();
+ this.viewDestCombo.disable();
+ }
+
+ // indique que le combo a ete mis a jour entierement
+ this.fireEvent("destStoreUpdated", this);
+
+ },
+
+ onCancelDestFn: function(btn) {
+ this.chooseWindow.hide();
+ this.membres_store.removeAll();
+ for (i=0; i<this.destStore.getCount(); i++) {
+ var rec = this.destStore.getAt(i);
+ this.membres_store.add(new this.membreRecordCreator({
+ type: "",
+ orgId: "",
+ roleId: "",
+ listId: "",
+ id: rec.get('destId'),
+ displayText: rec.get('name'),
+ admin: rec.get('admin')
+ }));
+ }
+ },
+
+ initializeFields: function() {
+ this.membres_store.removeAll();
+ this.destStore.removeAll();
+ this.viewDestCombo.reset();
+ this.viewDestCombo.disable();
+ },
+
+ addDestinataire: function(idDest, name) {
+ this.addDestinataire(idDest, name, false);
+ },
+
+ addDestinataire: function(idDest, name, isAdmin) {
+ if (this.membres_store.find('id', idDest) == -1) {
+ this.membres_store.add(new this.membreRecordCreator({
+ type: "",
+ orgId: "",
+ roleId: "",
+ listId: "",
+ id: idDest,
+ displayText: name,
+ admin: isAdmin
+ }));
+ this.destStore.addSorted(new this.destComboRecord({name: name,
+ destId: idDest,
+ admin: isAdmin}));
+ }
+ },
+
+
+ addListe: function(type, orgId, roleId, listId, id, parentList, childrenList, displayText){
+ if (this.membres_store.find('id', id) == -1) {
+ this.membres_store.add(new this.membreRecordCreator({
+ type: type,
+ orgId: orgId,
+ roleId: roleId,
+ listId: listId,
+ id: id,
+ parentList: parentList,
+ childrenList: childrenList,
+ displayText: displayText,
+ admin: false
+ }));
+ this.destStore.addSorted(new this.destComboRecord({name: displayText,
+ destId: id,
+ admin: false}));
+ }
+ },
+
+ activateDestinataireCombo: function() {
+ this.viewDestCombo.enable();
+ this.viewDestCombo.setValue(this.destStore.getAt(0).get('destId'));
+ },
+
+ getDestinataires: function() {
+ var mbrArray = new Array();
+
+ for (i=0; i<this.membres_store.getCount(); i++) {
+ var rec = this.membres_store.getAt(i);
+ var resTmp = {};
+ resTmp.type = rec.get("type");
+ resTmp.orgId = rec.get("orgId");
+ resTmp.roleId = rec.get("roleId");
+ resTmp.listId = rec.get("listId");
+ resTmp.id = rec.get("id").substring(1);
+ resTmp.admin = rec.get('admin');
+ mbrArray.push(resTmp);
+ }
+ return mbrArray;
+ },
+
+ retirerMembres : function() {
+ var recListArray = this.membres_grid
+ .getSelectionModel().getSelections();
+
+ for (i = 0; i < recListArray.length; i++) {
+ var currRec = recListArray[i];
+ this.membres_store.remove(currRec);
+ }
+ }
+
+});