--- /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.Forum");
+EntSavoie.Forum.GridEntity = 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.categoryId = this.categoryId || 0;
+ this.pagingLimit = this.pagingLimit || 10;
+ this.hideGridTBar = this.hideGridTBar || false;
+
+
+ // indique qu'une operation est en cours
+ this.operationProgress = this.operationProgress || new Ext.form.DisplayField({
+ value: this.i18n.Forum.GridEntity.operationProgress,
+ cls: 'operationProgress',
+ hidden :true
+ });
+
+ // Store des category et thread du forum
+ this.entityStore = this.entityStore || new Ext.data.Store({
+ proxy: new Ext.data.HttpProxy({
+ url: this.renderURLAjax+"&jspPage=%2Fajax%2FlistEntity.jsp"
+ }),
+ reader: new Ext.data.JsonReader({
+ root: "entities",
+ idProperty: "id",
+ totalProperty: 'total'
+ }, ['id', 'type', 'creator', 'createdDate', 'name', 'rootMessageId', 'subcategoryCount', 'description', 'threadCount', 'messageCount', 'lastPostUser', 'attachements',
+ 'lastPostDate', 'viewCount', 'priority', 'isSubscribed', {name:"hideEdit", type:"boolean"}, {name:"hideDelete", type:"boolean"},
+ {name:"hideSubscribe", type:"boolean"}, {name:"hideMoveThread", type:"boolean"}, {name:"hideManagePermissions", type:"boolean"}, 'nbMessageNew', 'groupId', {name:"anonymous", type:"boolean"}]),
+ remoteSort: true
+ });
+
+ this.resultSearchStore = this.resultSearchStore || new Ext.data.Store({
+ proxy: new Ext.data.HttpProxy({
+ url: this.renderURLAjax+"&jspPage=%2Fajax%2Fsearch.jsp"
+ }),
+ reader: new Ext.data.JsonReader({
+ root: "entities",
+ idProperty: "id",
+ totalProperty: 'total'
+ }, ['id', 'type', 'creator', 'createdDate', 'rootMessageId', 'name', 'subcategoryCount', 'description', 'threadCount', 'messageCount', 'lastPostUser',
+ 'lastPostDate', 'viewCount', 'priority', 'isSubscribed', {name:"hideEdit", type:"boolean"}, {name:"hideDelete", type:"boolean"},
+ {name:"hideSubscribe", type:"boolean"}, {name:"hideMoveThread", type:"boolean"}, {name:"hideManagePermissions", type:"boolean"}, 'nbMessageNew', 'groupId', {name:"anonymous", type:"boolean"}]),
+ remoteSort: true
+ });
+
+ this.addCategoryBtn =this.addCategoryBtn || new Ext.menu.Item({
+ text: this.i18n.Forum.GridEntity.addCategoryBtn,
+ iconCls: 'addCategory',
+ handler: this.onAddCategory,
+ scope: this
+ });
+
+ this.addThreadBtn =this.addThreadBtn || new Ext.menu.Item( {
+ text: this.i18n.Forum.GridEntity.addThreadBtn,
+ iconCls: 'addThread',
+ handler: this.onAddThread,
+ scope: this
+ });
+
+ this.backTo = this.backTo || new Ext.Button({
+ text: this.i18n.Forum.GridEntity.backTo.text,
+ tooltip: this.i18n.Forum.GridEntity.backTo.tooltip,
+ iconCls: 'backTo',
+ handler: this.onBackTo,
+ hidden: true,
+ scope: this
+ });
+
+ this.backHome = this.backHome || new Ext.Button({
+ text: this.i18n.Forum.GridEntity.backHome.text,
+ tooltip: this.i18n.Forum.GridEntity.backHome.tooltip,
+ iconCls: 'backHome',
+ hidden: true,
+ handler: this.onBackHome,
+ scope: this
+ });
+
+ // Menu Ajouter
+ this.addMenu = this.addMenu || new Ext.menu.Menu({
+ cls: "forum-portlet",
+ items: [
+ this.addCategoryBtn,
+ this.addThreadBtn
+ ]
+ });
+
+ // Menu Trier
+ this.sortMenu = this.sortMenu || new Ext.menu.Menu({
+ cls: "forum-portlet",
+ items: [
+ {
+ text: "Nom",
+ handler: this.onSortByName,
+ iconCls: 'sortInfo',
+ scope: this
+ },
+ {
+ text: "Nouveaux messages",
+ handler: this.onSortByNbNewMessages,
+ iconCls: 'sortInfo',
+ scope: this
+ },
+ {
+ text: "Ne pas trier",
+ handler: this.onUnSort,
+ iconCls: 'sortInfo',
+ scope: this
+ }
+ ]
+ });
+
+ this.searchBtn = this.searchBtn || new Ext.Button({
+ text: this.i18n.Forum.GridEntity.searchBtn.text,
+ tooltip: this.i18n.Forum.GridEntity.searchBtn.tooltip,
+ iconCls: 'search',
+ handler: this.onSearch,
+ //hidden: true,
+ scope: this
+ });
+
+ this.search = this.search || new Ext.form.TextField({
+ width: 300,
+ enableKeyEvents: true,
+ emptyText: this.i18n.Forum.GridEntity.search.emptyText
+ });
+
+ // Toolbar contenant les menus
+ this.gridTBar = this.gridTBar || new Ext.Toolbar({
+ hidden: this.hideGridTBar,
+ items: [{
+ itemId: 'addMenu',
+ hidden: true,
+ text: this.i18n.Forum.GridEntity.gridTBar.text,
+ iconCls: 'addMenu',
+ menu: this.addMenu
+ },
+ {
+ text: "Trier par",
+ menu: this.sortMenu,
+ iconCls: 'sortMenu',
+ style: "margin: 0px 5px 0px 5px;",
+ hidden: false
+ },
+ this.backHome,
+ this.operationProgress,
+ '->',
+ this.search,
+ this.searchBtn,
+ this.backTo
+ ]
+ });
+
+ // Pagination
+ this.entityPaggingTB = this.entityPaggingTB || new Ext.PagingToolbar({
+ hidden: this.hideEntityPaggingTB || false,
+ pageSize: this.pagingLimit,
+ store: this.entityStore,
+ displayInfo: true,
+ displayMsg: this.i18n.Forum.GridEntity.entityPaggingTB.displayMsg,
+ emptyMsg: this.i18n.Forum.GridEntity.entityPaggingTB.emptyMsg,
+ items:[]
+ });
+
+
+ this.action_column = this.action_column || new Ext.grid.ActionColumn({
+ width: 125,
+ sortable: false,
+ menuDisabled: true,
+ align: 'center',
+ items: [
+ {
+ iconCls: 'addToFavoriteCls',
+ tooltip: this.i18n.Forum.GridEntity.action_column.tooltip[0],
+ scope: this,
+ handler: this.onAddShortCutAction
+ },
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (rec.get('hideEdit') == false) {
+ return 'edit';
+ }
+ },
+ tooltip: this.i18n.Forum.GridEntity.action_column.tooltip[1],
+ scope: this,
+ handler: this.onEditAction
+ },
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (rec.get('hideSubscribe') == false) {
+ if (rec.get('isSubscribed') == true) {
+ return 'unsubscribe';
+ }
+ }
+ },
+ tooltip: this.i18n.Forum.GridEntity.action_column.tooltip[3],
+ scope: this,
+ handler: this.onSubscribeAction
+ },
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (rec.get('hideSubscribe') == false) {
+ if (rec.get('isSubscribed') == false) {
+ return 'subscribe';
+ }
+ }
+ },
+ tooltip: this.i18n.Forum.GridEntity.action_column.tooltip[4],
+ scope: this,
+ handler: this.onSubscribeAction
+ },
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (rec.get('hideMoveThread') == false) {
+ return 'moveThread';
+ }
+ },
+ tooltip: this.i18n.Forum.GridEntity.action_column.tooltip[5],
+ scope: this,
+ handler: this.onMoveAction
+ },
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (rec.get('hideManagePermissions') == false) {
+ return 'managePermissions';
+ }
+ },
+ tooltip: this.i18n.Forum.GridEntity.action_column.tooltip[6],
+ scope: this,
+ handler: this.onPermissionAction
+ },
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (rec.get('hideDelete') == false) {
+ return 'delete';
+ }
+ },
+ tooltip: this.i18n.Forum.GridEntity.action_column.tooltip[2],
+ scope: this,
+ handler: this.onDeleteAction
+ }
+ ]
+ });
+
+ //this.categoryDateTpl = new Ext.XTemplate('<div class="categoryStyle"></div><p class= "entityCreator"> {creator} <br /> le {createdDate} </p>');
+ this.categoryDateTpl = new Ext.XTemplate('<div class="categoryStyle"></div>');
+ this.categoryDateTpl.compile();
+
+ this.categoryNameTpl = new Ext.XTemplate('<div> <p class="entityName" onclick="{action}"> {name} </p> <p> {shortDesc} </p> </div> ');
+ this.categoryNameTpl.compile();
+
+ //this.threadDatePriorityTpl = new Ext.XTemplate('<div class="thread{priority}PriorityStyle"> </div> <p class= "entityCreator"> {creator} <br/> le {createdDate} </p>');
+ this.threadDatePriorityTpl = new Ext.XTemplate('<div class="thread{priority}PriorityStyle"> </div>');
+ this.threadDatePriorityTpl.compile();
+
+ this.threadNameTpl = new Ext.XTemplate('<div> <p class="entityName"> {name} <tpl if="anonymous"><b style="color: #6E7D8F;"> (Anonyme) </b></tpl></p> </div>');
+ this.threadNameTpl.compile();
+
+ this.categoryInfoTpl = new Ext.XTemplate(this.i18n.Forum.GridEntity.categoryInfoTpl, {
+ hasNewMessage: function (nbMessageNew) {
+ if(nbMessageNew > 0) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ });
+ this.categoryInfoTpl.compile();
+
+ //this.threadInfoTpl = new Ext.XTemplate('<div>{viewCount} vue(s)</div><div>{messageCount} publication(s)</div><div>dernière publication par {lastPostUser} </div> <div> le {lastPostDate}</div><tpl if="this.hasNewMessage(nbMessageNew)"><div class="messageNew"> {nbMessageNew} message(s) non lu(s)</div></tpl>', {
+ this.threadInfoTpl = new Ext.XTemplate(this.i18n.Forum.GridEntity.threadInfoTpl, {
+ hasNewMessage: function (nbMessageNew) {
+ if(nbMessageNew > 0) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ });
+ this.threadInfoTpl.compile();
+
+ EntSavoie.Forum.GridEntity.superclass.constructor.call(this, {
+ store: this.entityStore,
+ autoExpandColumn: 'name',
+ title: this.gridEntityTitle || ' ',
+ columns: [
+ {header: "", width: 40, dataIndex: 'createdDate',sortable: true,
+ renderer: {
+ fn: function(value, metaData, record, rowIndex, colIndex, store) {
+ if (record.get("type")=="Category") {
+ var result = this.categoryDateTpl.apply({
+ creator: record.get("creator"),
+ createdDate: record.get("createdDate")
+ });
+ metaData.attr = 'ext:qtip="'+ this.i18n.Forum.GridEntity.constructor.metaData.attr[0] + record.get("creator") + this.i18n.Forum.GridEntity.constructor.metaData.attr[1] + record.get("createdDate") + '"';
+ return result;
+ } else if (record.get("type")=="Thread") {
+ metaData.attr = 'ext:qtip="'+ this.i18n.Forum.GridEntity.constructor.metaData.attr[0] + record.get("creator") + this.i18n.Forum.GridEntity.constructor.metaData.attr[1] + record.get("createdDate") + '"';
+ return this.threadDatePriorityTpl.apply({
+ priority: record.get("priority")
+ });
+ }
+ },
+ scope: this
+ }
+ },
+ {header: this.i18n.Forum.GridEntity.constructor.header1, id: 'name', sortable: true,
+ renderer: {
+ fn: function(value, metaData, record, rowIndex, colIndex, store) {
+ if (record.get("type")=="Category") {
+ //var shortDescription = record.get("description");
+ //if (shortDescription.length > 300) {
+ // shortDescription = shortDescription.substring(0, 300) + "...";
+ //}
+ var result = this.categoryNameTpl.apply({
+ name: record.get("name"),
+ shortDesc: record.get("description")
+ });
+
+ //metaData.attr = 'ext:qtip="' + description + '"';
+ return result;
+ } else if (record.get("type")=="Thread") {
+ return this.threadNameTpl.apply({
+ name: record.get("name"),
+ anonymous: record.get("anonymous")
+ });
+ }
+ },
+ scope: this
+ }
+ },
+ {header: this.i18n.Forum.GridEntity.constructor.header2, width: 140, sortable: false, menuDisabled: true,
+ renderer: {
+ fn: function(value, metaData, record, rowIndex, colIndex, store) {
+ if (record.get("type")=="Category") {
+ return this.categoryInfoTpl.apply({
+ subcategoryCount: record.get("subcategoryCount"),
+ threadCount: record.get("threadCount"),
+ messageCount: record.get("messageCount"),
+ nbMessageNew: record.get("nbMessageNew")
+ });
+ } else if (record.get("type")=="Thread") {
+ metaData.attr = 'ext:qtip="'+ this.i18n.Forum.GridEntity.constructor.metaData.attr[2] + record.get("lastPostUser") + this.i18n.Forum.GridEntity.constructor.metaData.attr[3] + record.get("lastPostDate") + '"';
+ return this.threadInfoTpl.apply({
+ viewCount: record.get("viewCount"),
+ messageCount: record.get("messageCount"),
+ nbMessageNew: record.get("nbMessageNew")
+ });
+ }
+ },
+ scope: this
+ }
+ },
+ this.action_column
+ ],
+ loadMask: true,
+ border: false,
+ bbar: this.entityPaggingTB,
+ tbar: this.gridTBar
+ });
+
+ // Fenetre d'edition de categorie
+ this.editCategoryWindow = this.editCategoryWindow || new EntSavoie.Forum.EditCategory({
+ mainInstance: this.mainInstance,
+ gridEntity: this,
+ actionURLAjax: this.actionURLAjax,
+ language: this.language
+ });
+
+ // Fenetre d'edition de fil de discussion
+ this.editThreadWindow = this.editThreadWindow || new EntSavoie.Forum.EditThread({
+ mainInstance: this.mainInstance,
+ gridEntity: this,
+ isEleveOrParent: this.isEleveOrParent,
+ renderURLAjax: this.renderURLAjax,
+ actionURLAjax: this.actionURLAjax,
+ language: this.language
+ });
+
+ // Fenetre de deplacement d'un fil de discussion
+ this.moveThreadWindow = this.moveThreadWindow || new EntSavoie.Forum.MoveThread({
+ gridEntity: this,
+ renderURLAjax: this.renderURLAjax,
+ actionURLAjax: this.actionURLAjax
+ });
+
+ //window d'ajout aux favoris
+ this.addToFavoritesWindow = this.addToFavoritesWindow || new EntSavoie.AddShortCutWindow({
+ actionURLAjax:this.actionURLAjax,
+ renderURLAjax: this.renderURLAjax
+ });
+
+ // Definition des listeners
+ this.on("viewready", this.onViewReadyEntityGrid, this);
+ this.on("celldblclick", this.onCellDblclickGrid, this);
+ this.entityStore.proxy.on("beforeload", this.onBeforeLoadProxyEntityStore, this);
+ this.entityStore.on("load", this.onLoadEntityStore, this);
+ this.search.on("keydown", this.onKeyDownSearch, this);
+ this.resultSearchStore.on("load", this.onLoadresultSearchStore, this);
+
+};
+
+Ext.extend(EntSavoie.Forum.GridEntity, Ext.grid.GridPanel, {
+ initComponent: function () {
+ EntSavoie.Forum.GridEntity.superclass.initComponent.call(this);
+ },
+
+
+ /**
+ * Render EntityGrid
+ */
+ onViewReadyEntityGrid: function() {
+ // Chargement du store
+ this.entityStore.load({params:{limit:this.pagingLimit}});
+
+ // Refresh du menu ajout et du titre
+ this.refreshGridInfo();
+ },
+
+
+ /**
+ * Chargement du entityStore
+ */
+ onBeforeLoadProxyEntityStore: function(proxy, params) {
+ if (this.mainInstance.standalone == null) {
+ params.groupId = this.mainInstance.mainContainer.scopeGroupId;
+ params.categoryId = this.categoryId;
+ }
+ },
+
+ onLoadEntityStore: function(store, records, options){
+ if(this.isAfterSearch){
+ this.fireEvent("celldblclick", this, store.indexOfId(this.threadId), 0, options);
+ this.isAfterSearch = false;
+ }
+ },
+
+ /**
+ * Chargement du resultSearchStore
+ */
+ onLoadresultSearchStore: function() {
+ this.setTitle(this.i18n.Forum.GridEntity.onLoadresultSearchStore.title);
+ this.gridTBar.get(0).hide();
+ this.gridTBar.get(1).hide();
+ this.backTo.hide();
+ this.entityPaggingTB.refresh.addClass('hideRefresh');
+ this.backHome.show();
+ },
+
+ /**
+ * Refresh EntityGrid
+ */
+ refreshGrid: function(categoryId) {
+ if (!this.active) {
+ this.active = true;
+ this.mainInstance.layout.setActiveItem(0);
+ }
+ this.getSelectionModel().clearSelections();
+ this.categoryId = categoryId;
+ this.refreshGridInfo();
+ this.refreshBackTo(categoryId);
+ },
+
+ /**
+ * Refresh du menu ajouter
+ */
+ refreshGridInfo: function() {
+ if (this.hideGridTBar) {
+ return false;
+ }
+ this.operationProgress.show();
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "refreshGridInfo",
+ categoryId: this.categoryId,
+ groupId : this.mainInstance.mainContainer.scopeGroupId
+ },
+ scope: this,
+ success: this.onSuccessRefreshGridInfo,
+ failure: this.onFailureRefreshGridInfo
+ });
+ },
+
+ onSuccessRefreshGridInfo: function(response, options) {
+ this.operationProgress.hide();
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ this.setTitle(this.i18n.Forum.GridEntity.onSuccessRefreshGridInfo.title);
+ this.gridTBar.getComponent("addMenu").hide();
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onSuccessRefreshGridInfo.alert[0], this.i18n.Forum.GridEntity.onSuccessRefreshGridInfo.alert[1], function(btn){}, this);
+ } else {
+ // mise a jour du titre
+ this.setTitle(backObj.breadCrumbs);
+
+ // mise a jour du menu ajouter
+ if (this.categoryId==0) {
+ //Si l'utilisateur n'a pas la permission d'ajouter
+ if (backObj.hideBtnMenu) {
+ this.gridTBar.getComponent("addMenu").hide();
+ } else {
+ this.gridTBar.getComponent("addMenu").show();
+ this.addThreadBtn.hide();
+ }
+ } else {
+ //Si l'utilisateur n'a pas la permission d'ajouter
+ if (backObj.hideBtnMenu) {
+ this.gridTBar.getComponent("addMenu").hide();
+ this.addThreadBtn.hide();
+ }
+ else {
+ this.gridTBar.getComponent("addMenu").show();
+ this.addThreadBtn.show();
+ }
+ }
+
+ this.entityPaggingTB.moveFirst();
+ }
+ },
+
+ onFailureRefreshGridInfo: function(response, options) {
+ this.setTitle(this.i18n.Forum.GridEntity.onSuccessRefreshGridInfo.title);
+ this.gridTBar.getComponent("addMenu").hide();
+ this.operationProgress.hide();
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onFailureRefreshGridInfo.alert[0], this.i18n.Forum.GridEntity.onFailureRefreshGridInfo.alert[1], function(btn){}, this);
+ },
+
+ /**
+ * Refresh du bouton retour
+ */
+ refreshBackTo: function(categoryId) {
+ if (this.categoryId==0) {
+ this.backTo.hide();
+ } else {
+ this.backTo.show();
+ }
+ },
+
+ /**
+ * Double clic sur une ligne de la grid
+ */
+ onCellDblclickGrid: function(grid, rowIndex, colIndex, e) {
+ // Element de la grid sur lequel le double clic a ete realise
+ var selectedRecord = grid.getStore().getAt(rowIndex);
+ // Si on double clic sur une categorie rafraichissement de la gridEntity, sinon affichage du fil de discussion
+ if (selectedRecord.get("type")=='Category') {
+ this.entityGridShow(selectedRecord.get("id"));
+ } else if (selectedRecord.get("type")=='Thread'){
+ this.active = false;
+ this.mainInstance.gridMessage.messageGridShow(selectedRecord);
+ }
+ },
+
+ entityGridShow: function(categoryId) {
+ this.mainInstance.layout.setActiveItem(0);
+ this.refreshGrid(categoryId);
+ },
+
+ /**
+ * Ajouter une categorie
+ */
+ onAddCategory: function(btnMenu) {
+ this.editCategoryWindow.showAddCategoryWindow();
+ },
+
+ /**
+ * Ajouter un fil de discussion
+ */
+ onAddThread: function(btnMenu) {
+ this.editThreadWindow.showAddThreadWindow();
+ },
+
+ /**
+ * Clic sur le bouton d'edition
+ */
+ onEditAction: function(grid, rowIndex, colIndex) {
+ var record = grid.getStore().getAt(rowIndex);
+ if (record.get("type")=="Category") {
+ this.editCategoryWindow.showEditCategoryWindow(record);
+ } else if (record.get("type")=="Thread") {
+ this.editThreadWindow.showEditThreadWindow(record);
+ }
+ },
+
+ /**
+ * Clic sur le bouton de suppression
+ */
+ onDeleteAction: function(grid, rowIndex, colIndex) {
+ this.currentEntity = grid.getStore().getAt(rowIndex);
+ Ext.MessageBox.show({
+ title:this.i18n.Forum.GridEntity.onDeleteAction.title,
+ msg:this.i18n.Forum.GridEntity.onDeleteAction.msg,
+ buttons: {yes:"Oui", no:"Non"},
+ fn: this.deleteEntityCall,
+ animEl: 'confirmBtn',
+ icon: Ext.MessageBox.QUESTION,
+ minWidth: 350,
+ scope: this
+ });
+ },
+
+ deleteEntityCall: function(btn) {
+ if (btn=="no") {
+ return false;
+ }
+ this.wait = new Ext.LoadMask(this.id, {msg: "<b>Suppression en cours.</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "deleteEntity",
+ type: this.currentEntity.get("type"),
+ groupId: this.currentEntity.get("groupId"),
+ entityId: this.currentEntity.get("id")
+ },
+ scope: this,
+ success: this.onSuccessDelete,
+ failure: this.onFailureDelete
+ });
+ },
+
+ onSuccessDelete: function(response, options) {
+ this.wait.hide();
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onSuccessDelete.alert[0], this.i18n.Forum.GridEntity.onSuccessDelete.alert[1], function(btn){}, this);
+ } else {
+
+ // Actualisation de la grid
+ var record = this.entityStore.getById(backObj.id);
+ this.entityStore.remove(record);
+
+ // Actualisation de la pagingToolbar
+ this.entityStore.totalLength--;
+ this.entityPaggingTB.updateInfo();
+
+ if(!this.mainInstance.standalone){
+ this.mainInstance.mainContainer.refreshGrids(true);
+ }
+
+ Ext.slideMsg.msg(this.i18n.Forum.GridEntity.onSuccessDelete.slideMsg[0], this.i18n.Forum.GridEntity.onSuccessDelete.slideMsg[1] + backObj.name + this.i18n.Forum.GridEntity.onSuccessDelete.slideMsg[2]);
+ }
+ },
+
+ onFailureDelete: function(response, options) {
+ this.wait.hide();
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onFailureDelete.alert[0], this.i18n.Forum.GridEntity.onFailureDelete.alert[1], function(btn){}, this);
+ },
+
+ /**
+ * Clic sur le bouton de souscription
+ */
+ onSubscribeAction: function(grid, rowIndex, colIndex) {
+ var record = grid.getStore().getAt(rowIndex);
+ if (record.get("isSubscribed") == false) {
+ record.set("isSubscribed", true);
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "subscribe",
+ threadId: record.get("id")
+ },
+ scope: this,
+ success: this.onSuccessSubscribe,
+ failure: this.onFailureSubscribe
+ });
+ } else {
+ record.set("isSubscribed", false);
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "unsubscribe",
+ threadId: record.get("id")
+ },
+ scope: this,
+ success: this.onSuccessUnSubscribe,
+ failure: this.onFailureUnSubscribe
+ });
+ }
+ },
+
+ onSuccessSubscribe: function(response, options) {
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onSuccessSubscribe.alert[0], this.i18n.Forum.GridEntity.onSuccessSubscribe.alert[1], function(btn){}, this);
+ } else {
+ if(!this.mainInstance.standalone){
+ this.mainInstance.mainContainer.refreshGrids(false);
+ }
+ Ext.slideMsg.msg(this.i18n.Forum.GridEntity.onSuccessSubscribe.slideMsg[0], this.i18n.Forum.GridEntity.onSuccessSubscribe.slideMsg[1] + backObj.name);
+ }
+ },
+
+ onFailureSubscribe: function(response, options) {
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onFailureSubscribe.alert[0], this.i18n.Forum.GridEntity.onFailureSubscribe.alert[1], function(btn){}, this);
+ },
+
+ onSuccessUnSubscribe: function(response, options) {
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onSuccessUnSubscribe.alert[0], this.i18n.Forum.GridEntity.onSuccessUnSubscribe.alert[1], function(btn){}, this);
+ } else {
+ if(!this.mainInstance.standalone){
+ this.mainInstance.mainContainer.refreshGrids(false);
+ }
+ Ext.slideMsg.msg(this.i18n.Forum.GridEntity.onSuccessUnSubscribe.slideMsg[0], this.i18n.Forum.GridEntity.onSuccessUnSubscribe.slideMsg[1] + backObj.name);
+ }
+ },
+
+ onFailureUnSubscribe: function(response, options) {
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onFailureUnSubscribe.alert[0], this.i18n.Forum.GridEntity.onFailureUnSubscribe.alert[1], function(btn){}, this);
+ },
+
+ /**
+ * Clic sur le bouton de deplacement d'un fil de discussion
+ */
+ onMoveAction: function(grid, rowIndex, colIndex) {
+ var record = grid.getStore().getAt(rowIndex);
+ this.moveThreadWindow.showMoveThread(record);
+ },
+
+ /**
+ * Il faut connaitre le rootMessageId pour charger la grille des permissions
+ */
+ onPermissionAction: function(grid, rowIndex, colIndex) {
+ var record = grid.getStore().getAt(rowIndex);
+ if (record.get("type")=="Category") {
+ // Fenetre de gestion des permissions pour la category
+ var permissionsCurrentCategoryView = new EntSavoie.Permissions.gestionPermissions({
+ renderURLAjax: this.renderURLAjax,
+ actionURLAjax: this.actionURLAjax,
+ //scopeGroupId: this.scopeGroupId,
+ scopeGroupId: record.get("groupId"),
+ type: "category",
+ objectId: record.get("id"),
+ objectName: " de la catégorie " + record.get("name"),
+ gridParent: this
+ });
+ permissionsCurrentCategoryView.show();
+ } else if (record.get("type")=="Thread") {
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "permissionThread",
+ threadId: record.get("id")
+ },
+ scope: this,
+ success: this.onSuccessPermissionAction,
+ failure: this.onFailurePermissionAction
+ });
+ }
+ },
+
+ onSuccessPermissionAction: function(response, options) {
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onSuccessPermissionAction.alert[0], this.i18n.Forum.GridEntity.onSuccessPermissionAction.alert[1], function(btn){}, this);
+ } else {
+ // Fenetre de gestion des permissions pour le thread courant
+ var permissionsCurrentThreadView = new EntSavoie.Permissions.gestionPermissions({
+ renderURLAjax: this.renderURLAjax,
+ actionURLAjax: this.actionURLAjax,
+ type: "thread",
+ scopeGroupId: backObj.groupId,
+ objectId: backObj.rootMessageId,
+ objectName: " du fil de discussion " + backObj.name,
+ gridParent: this
+ });
+ permissionsCurrentThreadView.show();
+ }
+ },
+
+
+ onFailurePermissionAction: function(response, options) {
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onFailurePermissionAction.alert[0], this.i18n.Forum.GridEntity.onFailurePermissionAction.alert[1], function(btn){}, this);
+ },
+
+ /**
+ * Il faut connaitre le parentCategoryId pour charger le store avec le categoryId
+ */
+ onBackTo: function(btn) {
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "backTo",
+ categoryId: this.categoryId
+ },
+ scope: this,
+ success: this.onSuccessBackTo,
+ failure: this.onFailureBackTo
+ });
+ },
+
+ onSuccessBackTo: function(response, options) {
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onSuccessBackTo.alert[0], this.i18n.Forum.GridEntity.onSuccessBackTo.alert[1], function(btn){}, this);
+ } else {
+ this.refreshGrid(backObj.parentCategoryId);
+ // Si on a effectue une recherche
+ if (this.search.getValue()!="") {
+ this.backTo.hide();
+ }
+ }
+ },
+
+ onFailureBackTo: function(response, options) {
+ Ext.MessageBox.alert(this.i18n.Forum.GridEntity.onFailureBackTo.alert[0], this.i18n.Forum.GridEntity.onFailureBackTo.alert[1], function(btn){}, this);
+ },
+
+ /**
+ * Retour sur la page d'accueil
+ */
+ onBackHome: function(btn) {
+ this.reconfigure(this.entityStore, this.getColumnModel());
+ this.entityPaggingTB.bindStore(this.entityStore);
+ this.refreshGrid(0);
+ this.setTitle(this.i18n.Forum.GridEntity.onBackHome);
+ this.backHome.hide();
+ this.gridTBar.get(0).show();
+ this.gridTBar.get(1).show();
+ this.entityPaggingTB.refresh.removeClass('hideRefresh');
+ this.search.reset();
+ },
+
+
+ /**
+ * Recherche appuis sur touche entree
+ */
+ onKeyDownSearch: function(textfield, e) {
+ if (e.keyCode==13) {
+ this.onSearch();
+ }
+ },
+
+ onSearch: function(btn) {
+ this.reconfigure(this.resultSearchStore, this.getColumnModel());
+ this.entityPaggingTB.bindStore(this.resultSearchStore);
+ this.resultSearchStore.load({params:{groupId: this.mainInstance.mainContainer.scopeGroupId, keywords: this.search.getValue()}});
+ },
+
+ onAddShortCutAction: function(grid, rowIndex, colIndex){
+ var record = grid.getStore().getAt(rowIndex);
+ this.addToFavoritesWindow.showShortCutWindow(record.get("id"), record.get("name"));
+ },
+
+ /**
+ * Tri
+ */
+ onSortByName: function(btn){;
+ this.entityStore.sort("name", 'ASC');
+ },
+
+ onSortByNbNewMessages: function(btn){
+ this.entityStore.sort("nbMessageNew", 'DESC');
+ },
+
+ onUnSort: function(btn){
+ this.entityStore.sort("id");
+ }
+
+});