--- /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.ItemGridPanel = 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.archiveId = this.archiveId || "0";
+
+ this.limit = 6;
+
+ this.itemStore = this.itemStore || new Ext.data.JsonStore({
+ autoLoad: false,
+ baseParams: {limit: this.limit},
+ root: 'items',
+ idProperty: 'itemId',
+ totalProperty: 'total',
+ fields: [
+ 'itemId',
+ 'title',
+ 'description',
+ 'author',
+ {name: 'active', type: 'boolean'},
+ 'pubDate',
+ "pubDateFormat",
+ "category",
+ "image",
+ "mediaFileName",
+ 'mediaConvertedViewer',
+ 'mediaOriginal',
+ 'attachments',
+ {name: 'sort', type: 'number'}
+ ],
+ proxy: new Ext.data.HttpProxy({
+ url: this.renderURLAjax+'&jspPage=%2Fajax%2FlistItems.jsp'
+ }),
+ sortInfo: {
+ field: 'sort',
+ direction: 'DESC'
+ }
+ });
+
+ this.action_column = null;
+
+ if(this.viewInternet) {
+ this.action_column = new Ext.grid.ActionColumn({
+ width: 25,
+ fixed: true,
+ sortable: false,
+ menuDisabled: true,
+ align: 'right',
+ items: [
+ {
+ getClass: function(v, meta, rec, row, col, store) {
+ if (rec.get('mediaOriginal') != "") {
+ return 'download';
+ }
+ },
+ tooltip: "Télécharger le média associé au billet",
+ scope: this,
+ handler: this.onDownloadItemAction
+ }
+ ]
+ });
+ } else {
+ this.action_column = new Ext.grid.ActionColumn({
+ width: 75,
+ fixed: true,
+ sortable: false,
+ menuDisabled: true,
+ align: 'right',
+ items: [
+ {
+ iconCls: 'editItem',
+ tooltip: "Modifier le billet",
+ scope: this,
+ handler: this.onEditItemAction
+ },
+ {
+ iconCls: 'deleteItem',
+ tooltip: "Supprimer le billet",
+ scope: this,
+ handler: this.onDeleteItemAction
+ },
+ {
+ getClass: function(v, meta, rec, row, col, store) {
+ if (rec.get('mediaOriginal') != "") {
+ return 'download';
+ }
+ },
+ tooltip: "Télécharger le média associé au billet",
+ scope: this,
+ handler: this.onDownloadItemAction
+ }
+ ]
+ });
+ }
+
+ // Template pour la seconde colonne
+ this.itemTpl = new Ext.XTemplate(
+ "<table width='100%' class='itemTableTplCls'>" +
+ "<tr>" +
+ "<td>" +
+ "<b class='blogTitle' style='font-size:14px; margin-bottom: 4px;'>{title}</b>" +
+ '{active}' +
+ "</td>" +
+ "<td style='width: 120px; text-align: right;'>" +
+ "<span class='dateHeure'>{pubDateFormat}</span>" +
+ "</td>" +
+ "</tr>" +
+ "<tr>" +
+ "<td colspan='2'>" +
+ "<div>" +
+ "{image}" +
+ "{description}" +
+ "</div>" +
+ "</td>" +
+ "</tr>" +
+ "<tr>" +
+ "<td colspan='2'>" +
+ "<div style='margin: 0 auto; width: 80%;'>{mediaConvertedViewer}</div>" +
+ "<br/>" +
+ "<div class='blogMediaOriginal'>{mediaOriginal}</div>" +
+ "</td>" +
+ "</tr>" +
+ "<tr>" +
+ "<td colspan='2'>" +
+ "<div class='blogAttachment'>{attachments}</div>" +
+ "</td>" +
+ "</tr>" +
+ "<tr>" +
+ "<td style='text-align: right;' colspan='2'>" +
+ "<div class='categoryName'><i>{categoryName}</i></div>" +
+ "</td>" +
+ "</tr>" +
+ "</table>"
+ );
+ this.itemTpl.compile();
+
+ this.cmItem = this.cmItem || new Ext.grid.ColumnModel({
+ columns: [
+ {
+ id: "title",
+ dataIndex: 'title',
+ renderer: {
+ fn: function(value, metaData, record, rowIndex, colIndex, store) {
+ var result = this.itemTpl.apply({
+ title: record.get("title"),
+ description: record.get("description"),
+ author: record.get("author"),
+ pubDateFormat: "Posté le " + record.get("pubDateFormat"),
+ active: record.get("active")?'':'<b style="color:red;">(Ce billet sera publié le ' + record.get("pubDateFormat") + ')</b>',
+ image: (record.get("image") != "")?"<img border='no' style='margin-top:5px; margin-right: 10px; float: left;' src='" +record.get("image")+"' height='64px'/>":"",
+ mediaConvertedViewer: record.get("mediaConvertedViewer"),
+ mediaOriginal: (record.get("mediaOriginal") != "")?("<u>Média :</u><a href='" + record.get("mediaOriginal") + "'> " + record.get("mediaFileName") + "</a>"):"",
+ attachments: this.formatAttachements(record.get("attachments")),
+ categoryName: record.get("category").categoryName
+ });
+ return result;
+ },
+ scope: this
+ }
+ },
+ this.action_column
+ ]
+ });
+
+ this.blogItemGridPBar = this.blogItemGridPBar || new Ext.PagingToolbar({
+ pageSize: this.limit,
+ store: this.itemStore,
+ displayInfo: true,
+ cls : this.viewInternet?"blogItemGridPBar":"",
+ displayMsg: "Billets {0} à {1} sur {2}",
+ emptyMsg: "Aucun billet publié"
+ });
+
+ /**
+ * Constructeur
+ */
+ if(this.viewInternet){
+ EntSavoie.Blog.ItemGridPanel.superclass.constructor.call(this, {
+ cls: 'itemGridPanelCls itemGridPanelViewInternetCls',
+ bodyStyle: {"background-color": this.backgroudColor},
+ border: false,
+ store : this.itemStore,
+ autoExpandColumn: 'title',
+ hideHeaders: true,
+ disableSelection: true,
+ colModel: this.cmItem,
+ autoHeight: true,
+ autoScroll: false,
+ columnWidth: 0.999,
+ viewConfig: {
+ scrollOffset: 0,
+ forceFit: true
+ },
+ bbar: this.blogItemGridPBar
+ });
+ } else {
+ EntSavoie.Blog.ItemGridPanel.superclass.constructor.call(this, {
+ cls: 'itemGridPanelCls',
+ region: "center",
+ border: true,
+ store : this.itemStore,
+ autoExpandColumn: 'title',
+ hideHeaders: true,
+ disableSelection: true,
+ colModel: this.cmItem,
+ viewConfig: {
+ forceFit: true
+ },
+ bbar: this.blogItemGridPBar
+ });
+ }
+
+ this.itemStore.proxy.on("beforeload", this.onBeforeLoadItemStoreProxy, this);
+
+};
+
+Ext.extend(EntSavoie.Blog.ItemGridPanel, Ext.grid.GridPanel, {
+ initComponent: function () {
+ EntSavoie.Blog.ItemGridPanel.superclass.initComponent.call(this);
+ },
+
+ /*
+ * Before Load Item Store Proxy
+ */
+ onBeforeLoadItemStoreProxy: function(proxy, params){
+ if(this.refresh){
+ params.start = 0;
+ params.limit = this.limit;
+ }
+ this.refresh = false;
+ params.channelId = this.channelId;
+ params.categoryId = this.categoryId;
+ params.month = this.archiveId;
+ params.isIntranet = !this.viewInternet;
+ params.isIE = isIE;
+ },
+
+ /*
+ * Load Item Store After Filter
+ */
+ loadItemStore: function(refresh){
+ this.refresh = refresh;
+ this.store.load();
+ },
+
+ /*
+ * Edition d'un billet
+ */
+ onEditItemAction: function(grid, rowIndex, colIndex){
+ var record = grid.getStore().getAt(rowIndex);
+ this.mainContainer.editItem(record);
+ },
+
+ /*
+ * Suppression d'un billet
+ */
+ onDeleteItemAction: function(grid, rowIndex, colIndex){
+ this.itemToDelete = grid.getStore().getAt(rowIndex);
+ Ext.MessageBox.show({
+ title: "Suppression du billet sélectionné",
+ msg: "Le billet sélectionné sera supprimé définitivement. <br/>" +
+ "Souhaitez-vous continuer?",
+ buttons: {yes: "Oui", no: "Non"},
+ fn: this.onDeleteItemCall,
+ animEl: 'confirmBtn',
+ icon: Ext.MessageBox.QUESTION,
+ minWidth: 350,
+ scope: this
+ });
+ },
+
+ onDeleteItemCall: function(btn){
+ if (btn=="no") {
+ return false;
+ }
+
+ this.wait = new Ext.LoadMask(Ext.getBody(), {msg: "Suppression du billet en cours. <br /> <b> Veuillez patienter ... </b>"});
+ this.wait.show();
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "deleteItem",
+ itemId: this.itemToDelete.get("itemId"),
+ categoryId: this.categoryId,
+ month: this.archiveId
+ },
+ scope: this,
+ success: this.onSuccessDeleteItem,
+ failure: this.onFailureDeleteItem
+ });
+ },
+
+ onSuccessDeleteItem: 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.store.remove(this.itemToDelete);
+
+ var activePage = Math.ceil((this.blogItemGridPBar.cursor + this.blogItemGridPBar.pageSize) / this.blogItemGridPBar.pageSize);
+ if((this.store.getRange().length % this.limit) == 0){
+ activePage = activePage-1;
+ }
+
+ // Mise a jour de la paging toolbar
+ this.mainContainer.updatePagingToolBar(activePage);
+
+ // Mise a jour du stores categories et archives
+ this.mainContainer.updateStores(null, backObj.categoryTagStore, backObj.archiveListStore);
+
+ Ext.slideMsg.msg("Suppression du billet", "La billet a été correctement supprimé.");
+ }
+ },
+
+ onFailureDeleteItem: 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);
+ },
+
+ /*
+ * Formattage des pieces jointes
+ */
+ formatAttachements: function(attachementFiles) {
+ var result = "";
+ var fileArray = Ext.decode(attachementFiles);
+ for (i=0; i<fileArray.length; i++) {
+ var file = fileArray[i];
+ result += file.fileHref + " (" + file.fileInfo + "kb) ";
+ }
+ if(result != ""){
+ result = "<u>Pièces jointes :</u> " + result;
+ }
+ return result;
+ },
+
+ /*
+ * Telechargement du media associe
+ */
+ onDownloadItemAction: function(grid, rowIndex, colIndex){
+ var record = grid.getStore().getAt(rowIndex);
+ window.open(record.get("mediaOriginal") + "&contentDispo=attachment");
+ }
+});