--- /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.Blog");
+EntSavoie.Blog.CategoryTreePanel = 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.treeCategoryLoader = this.treeCategoryLoader || new Ext.tree.TreeLoader({
+ dataUrl: this.renderURLAjax+'&jspPage=%2Fajax%2FcategoryForTree.jsp',
+ preloadChildren: true
+ });
+
+ this.addCategoryBtn = this.addCategoryBtn || new Ext.Button({
+ iconCls: 'addCategory',
+ handler: this.onAddCategory,
+ tooltip: "Ajouter une nouvelle catégorie",
+ scope: this
+ });
+
+ this.deleteCategoryBtn = this.deleteCategoryBtn || new Ext.Button({
+ iconCls: 'deleteCategory',
+ handler: this.onDeleteCategory,
+ tooltip: "Supprimer la catégorie sélectionnée",
+ scope: this
+ });
+
+ this.editCategoryBtn = this.editCategoryBtn || new Ext.Button({
+ iconCls: 'editCategory',
+ handler: this.onEditCategory,
+ tooltip: "Modifier la catégorie sélectionnée",
+ scope: this
+ });
+
+ this.addCategoryBtnBbar = this.addCategoryBtnBbar || new Ext.Button({
+ iconCls: 'addCategory',
+ handler: this.onAddCategory,
+ tooltip: "Ajouter une nouvelle catégorie",
+ scope: this
+ });
+
+ this.deleteCategoryBtnBbar = this.deleteCategoryBtnBbar || new Ext.Button({
+ iconCls: 'deleteCategory',
+ handler: this.onDeleteCategory,
+ tooltip: "Supprimer la catégorie sélectionnée",
+ scope: this
+ });
+
+ this.editCategoryBtnBbar = this.editCategoryBtnBbar || new Ext.Button({
+ iconCls: 'editCategory',
+ handler: this.onEditCategory,
+ tooltip: "Modifier la catégorie sélectionnée",
+ scope: this
+ });
+
+ this.rightClicMenu = this.rightClicMenu || new Ext.menu.Menu({
+ cls: "blog-portlet",
+ items: [
+ {
+ text: "Ajouter",
+ handler: this.onAddCategory,
+ iconCls: 'addCategory',
+ scope: this
+ },
+ {
+ text: "Editer",
+ handler: this.onEditCategory,
+ iconCls: 'editCategory',
+ scope: this
+ },
+ {
+ text: "Supprimer",
+ handler: this.onDeleteCategory,
+ iconCls: 'deleteCategory',
+ scope: this
+ }
+ ]
+ });
+
+ this.topToolBar = this.topToolBar || new Ext.Toolbar({
+ hidden: this.isComboBox || this.viewInternet,
+ items: [{xtype:'tbtext', style: "font-weight: bold; font-size: 12px;", text: 'Catégories'}, "->", this.addCategoryBtn, this.deleteCategoryBtn, this.editCategoryBtn]
+ });
+
+ this.bottomToolBar = this.bottomToolBar || new Ext.Toolbar({
+ hidden: this.isComboBox || this.viewInternet,
+ items: [{xtype:'tbtext', style: "font-weight: bold; font-size: 12px;", text: 'Catégories'}, "->", this.addCategoryBtnBbar, this.deleteCategoryBtnBbar, this.editCategoryBtnBbar]
+ });
+
+ /**
+ * Constructeur
+ */
+ EntSavoie.Blog.CategoryTreePanel.superclass.constructor.call(this, {
+ cls: 'categoryTreePanelCls',
+ border: false,
+ useArrows: true,
+ autoScroll: true,
+ animate: true,
+ containerScroll: true,
+ loader: this.treeCategoryLoader,
+ rootVisible: true,
+ enableDrop: this.isComboBox?false:true,
+ enableDrag: this.isComboBox?false:true,
+ style: this.viewInternet?'':'border-top: solid 1px; border-color: #99BBE8;',
+ root: {
+ nodeType: 'async',
+ text: "Toutes", // Texte du noeud
+ draggable: false, // Désactiver le Drag and drop sur ce noeud
+ id: this.channelId, // Id du rootNodePah
+ leaf: false,
+ allowDrop: true,
+ iconCls: 'blogCategory',
+ expanded: true
+ },
+ tbar: this.topToolBar,
+ bbar: this.bottomToolBar
+ });
+
+ if(!this.isComboBox){
+ this.on("afterrender", this.onAfterRenderTreeCategoryPanel, this);
+ this.on("click", this.onClickTreeCategoryPanel, this);
+ }
+
+ this.on("movenode", this.onMoveNodeTreeCategoryPanel, this);
+ this.on("contextmenu", this.onContextMenuTreeCategoryPanel, this);
+
+};
+
+Ext.extend(EntSavoie.Blog.CategoryTreePanel, Ext.tree.TreePanel, {
+ initComponent: function () {
+ EntSavoie.Blog.CategoryTreePanel.superclass.initComponent.call(this);
+ },
+
+ /*
+ * Evenement lorsque le tree est rendu
+ */
+ onAfterRenderTreeCategoryPanel: function(tree){
+ this.getSelectionModel().select(this.root);
+ this.node = this.root;
+ this.grid.categoryId = this.node.id;
+ },
+
+ /*
+ * Clic sur une des categories --> Filtre du store des billets
+ */
+ onClickTreeCategoryPanel: function(node, e){
+ this.node = node;
+ this.grid.categoryId = this.node.id;
+ this.grid.loadItemStore(true);
+ this.mainContainer.reloadTagStores(true, true);
+ },
+
+ /*
+ * Ajout d'une categorie
+ */
+ onAddCategory: function(btn){
+ Ext.MessageBox.show({
+ title: "Ajout d'une nouvelle catégorie",
+ msg: "Nom de la catégorie :",
+ buttons: {yes:"Valider", no:"Annuler"},
+ value: "Catégorie",
+ fn: this.onAddCategoryCall,
+ prompt: true,
+ minWidth:250,
+ scope: this
+ });
+ },
+
+ onAddCategoryCall: function(btn, categoryTitle){
+ if (btn=="no") {
+ return false;
+ }
+
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "<b>Ajout d'une catégorie en cours</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "addCategory",
+ channelId: this.channelId,
+ parentCategoryId: this.node.id,
+ title: categoryTitle,
+ categoryFilterId: this.grid.categoryId,
+ month: this.grid.archiveId
+ },
+ scope: this,
+ success: this.onSuccessAddCategory,
+ failure: this.onFailureAddCategory
+ });
+ },
+
+ onSuccessAddCategory: 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 newCategory = new Ext.tree.TreeNode({id: backObj.categoryId, text: backObj.title, leaf: false, iconCls: 'blogCategory', allowDrop: true, draggable: true});
+ this.node.appendChild(newCategory);
+ if(!this.node.isExpanded()){
+ this.node.expand();
+ }
+ this.node.sort(function(a, b) {if(a.text < b.text){return -1;} else if(a.text == b.text){return 0;} else {return 1;}});
+
+ // Mise a jour du store des categories
+ this.mainContainer.updateStores(null, backObj.categoryTagStore, null);
+
+ Ext.slideMsg.msg("Ajout d'une catégorie", "La catégorie a correctement été ajoutée.");
+ }
+ },
+
+ onFailureAddCategory: 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);
+ },
+
+ /*
+ * Edition d'une categorie
+ */
+ onEditCategory: function(btn){
+ // Si le noeud n'est pas le root
+ if(this.node.id != this.root.id){
+ Ext.MessageBox.show({
+ title: "Modification de la catégorie sélectionnée",
+ msg: "Nom de la catégorie :",
+ buttons: {yes:"Modifier", no:"Annuler"},
+ value: this.node.text,
+ fn: this.onEditCategoryCall,
+ prompt: true,
+ minWidth:250,
+ scope: this
+ });
+ }
+ },
+
+ onEditCategoryCall: function(btn, categoryTitle){
+ if (btn=="no") {
+ return false;
+ }
+
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "<b>Modification d'une catégorie en cours</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "editCategory",
+ channelId: this.channelId,
+ categoryId: this.node.id,
+ title: categoryTitle,
+ categoryFilterId: this.grid.categoryId,
+ month: this.grid.archiveId
+ },
+ scope: this,
+ success: this.onSuccessEditCategory,
+ failure: this.onFailureEditCategory
+ });
+ },
+
+ onSuccessEditCategory: 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.node.setText(backObj.title);
+ this.node.parentNode.sort(function(a, b) {if(a.text < b.text){return -1;} else if(a.text == b.text){return 0;} else {return 1;}});
+
+ // Mise a jour du store des categories
+ this.mainContainer.updateStores(null, backObj.categoryTagStore, null);
+
+ Ext.slideMsg.msg("Modification d'une catégorie", "La catégorie a correctement été modifiée.");
+ }
+ },
+
+ onFailureEditCategory: 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);
+ },
+
+ /*
+ * Suppression d'une categorie
+ */
+ onDeleteCategory: function(btn){
+ // Si le noeud n'est pas le root
+ if(this.node.id != this.root.id){
+ Ext.MessageBox.show({
+ title: "Suppression de la catégorie sélectionnée",
+ msg: "La catégorie sélectionnée peut contenir des billets et/ou des sous-catégories.<br /> " +
+ "Ces entités seront également supprimées lors de sa suppression. " +
+ "Souhaitez-vous continuer ?",
+ buttons: {yes: "Oui", no: "Non"},
+ fn: this.onDeleteCategoryCall,
+ animEl: 'confirmBtn',
+ icon: Ext.MessageBox.QUESTION,
+ minWidth: 350,
+ scope: this
+ });
+ }
+ },
+
+ onDeleteCategoryCall: function(btn){
+ if (btn=="no") {
+ return false;
+ }
+
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "Suppression de la catégorie en cours. <br /> <b> Veuillez patienter ... </b>"});
+ this.wait.show();
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "deleteCategory",
+ channelId: this.channelId,
+ categoryId: this.node.id,
+ categoryFilterId: this.grid.categoryId,
+ month: this.grid.archiveId,
+ isIE: isIE
+ },
+ scope: this,
+ success: this.onSuccessDeleteCategory,
+ failure: this.onFailureDeleteCategory
+ });
+ },
+
+ onSuccessDeleteCategory: 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 parentNode = this.node.parentNode;
+ parentNode.removeChild(this.node);
+
+ // Mise a jour des stores
+ this.getSelectionModel().select(parentNode);
+ this.node = parentNode;
+ this.grid.categoryId = this.node.id;
+ this.mainContainer.updateStores(backObj.itemStore, backObj.categoryTagStore, backObj.archiveListStore);
+
+ Ext.slideMsg.msg("Suppression de la catégorie", "La catégorie a été correctement supprimée.");
+ }
+ },
+
+ onFailureDeleteCategory: 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);
+ },
+
+ /*
+ * Deplacement d'une categorie dans l'arbre
+ */
+ onMoveNodeTreeCategoryPanel: function(tree, node, oldParent, newParent, index) {
+ // Si on deplace la categorie dans un dossier parent different
+ if (oldParent!=newParent) {
+ this.node = node;
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "Déplacement des catégories en cours. <br /> <b> Veuillez patienter ... </b>"});
+ this.wait.show();
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "moveCategoryNode",
+ parentCategoryId: newParent.id,
+ categoryId: node.id,
+ month: this.grid.archiveId,
+ isIE: isIE
+ },
+ scope: this,
+ success: this.onSuccessMoveCategoryNode,
+ failure: this.onFailureMoveCategoryNode
+ });
+ }
+ },
+
+ onSuccessMoveCategoryNode: 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 parentNode = this.node.parentNode;
+ parentNode.expand();
+ parentNode.sort(function(a, b) {if(a.text < b.text){return -1;} else if(a.text == b.text){return 0;} else {return 1;}});
+ this.getSelectionModel().select(this.node);
+ this.grid.categoryId = this.node.id;
+
+ this.mainContainer.updateStores(backObj.itemStore, backObj.categoryTagStore, backObj.archiveListStore);
+
+ Ext.slideMsg.msg("Modification des catégories", "Les catégories ont correctement été modifiées.");
+ }
+ },
+
+ onFailureMoveCategoryNode: 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);
+ },
+
+ onContextMenuTreeCategoryPanel: function(node, e){
+ e.stopEvent();
+ var coords = e.getXY();
+
+ if(node.id == this.root.id){
+ // Hide des boutons d'edition et suppression
+ this.rightClicMenu.items.get(1).hide();
+ this.rightClicMenu.items.get(2).hide();
+ } else {
+ // Show des boutons d'edition et suppression
+ this.rightClicMenu.items.get(1).show();
+ this.rightClicMenu.items.get(2).show();
+ }
+
+ this.selectPath(node.getPath());
+ this.fireEvent("click", node);
+ this.rightClicMenu.showAt([coords[0], coords[1]]);
+ }
+});