--- /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");
+EntSavoie.AddFileWindow = 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.btnStyle = this.btnStyle || '';
+ this.bodyCssClass = this.bodyCssClass || '';
+ this.onAddItemOverride = this.onAddItemOverride || this.onAddItemFn;
+ this.onDblclickTreeOverride = this.onDblclickTreeOverride || this.onDblclickTree;
+ this.onRenderPanelGridOverride = this.onRenderPanelGridOverride || this.onRenderPanelGrid;
+
+ this.callUpdateOnGridFileOverride = this.callUpdateOnGridFileOverride || this.callUpdateOnGridFile;
+ this.callUpdateOnGridFileScope = this.callUpdateOnGridFileScope || this;
+
+ this.disableDiskUpload = this.disableDiskUpload || false;
+
+ this.addFileWindowId = this.addFileWindowId || "addFileWindow";
+
+
+ // Declaration du createur de record
+ this.attachFileRecordCreator = Ext.data.Record.create([
+ "id",
+ "name",
+ "type",
+ "isNew",
+ "isSignet"
+ ]);
+
+ // Definition des composants affiches dans le popup du choix des pieces jointes
+ this.preview_attachFile_store = this.preview_attachFile_store || new Ext.data.JsonStore( {
+ fields : [ "id", "name", "type", "isNew", {name:"isSignet", type:"boolean"}],
+ sortInfo: {
+ field: 'name',
+ direction: 'ASC'
+ }
+ });
+
+ this.action_column = this.action_column || new Ext.grid.ActionColumn({
+ width: 25,
+ sortable: false,
+ menuDisabled: true,
+ align: 'left',
+ items: [
+ {iconCls: 'deleteAttachFile', // Use a URL in the icon config
+ tooltip: this.i18n.AddFileWindow.action_column.tooltip,
+ handler: this.onRowPreviewAction,
+ scope: this
+ }
+ ]
+ });
+
+
+ this.preview_attachFile_grid = this.preview_attachFile_grid || new Ext.grid.GridPanel({
+ border: true,
+ store : this.preview_attachFile_store,
+ hideHeaders: true,
+ autoExpandColumn: 'name',
+ padding: 5,
+ enableDrag: true,
+ enableDrop: false,
+ ddGroup: 'removeFileDD',
+ ddText : this.i18n.AddFileWindow.preview_attachFile_grid.ddText,
+ columns :
+ [
+ {
+ id: "name",
+ dataIndex : "name",
+ sortable : false,
+ editable: false,
+ renderer: {
+ fn: function(value, metaData, record, rowIndex, colIndex, store) {
+ metaData.css = this.getFileCls(record);
+ return value;
+ },
+ scope: this
+ }
+ },
+ {
+ id: "type",
+ dataIndex : "type",
+ sortable : false,
+ editable: false
+ },
+ this.action_column
+ ],
+ viewConfig: {
+ forceFit: true,
+
+ getRowClass: function(record, index) {
+ if (record.get('type')=="Dossier") {
+ return 'attachFile-Folder';
+ } else {
+ return 'attachFile-File';
+ }
+ }
+ }
+ });
+
+ //Defini l'arbre represantant le parcours du cartable
+ this.treeElt = this.treeElt || new Ext.tree.TreePanel({
+ useArrows: true,
+ autoScroll: true,
+ animate: true,
+ enableDrag: true,
+ enableDrop: false,
+ ddGroup: 'attachFileDD',
+ ddText : this.i18n.AddFileWindow.treeElt.ddText,
+ containerScroll: true,
+ border: true,
+ cls: "treeView",
+ style: 'background-color: white',
+ dataUrl: this.renderURLAjax+"&jspPage=/ajax/cartable_chooseAttachFileAdvanced.jsp",
+ rootVisible: false,
+ root:{
+ noteType: 'async',
+ text: this.i18n.AddFileWindow.treeElt.root.text,
+ id:"0",
+ draggable: false
+ }
+ });
+
+ this.attachBtn = this.attachBtn || new Ext.Button({
+ minWidth: 80,
+ text: this.i18n.AddFileWindow.attachBtn.text,
+ handler: this.onAttachFn,
+ scope: this
+ });
+
+ this.addItemBtn = this.addFileBtn || new Ext.Button({
+ iconCls: 'addItemBtn',
+ scale: 'large',
+ handler: this.onAddItemOverride,
+ scope: this
+ });
+
+ this.cancelBtn = this.cancelBtn || new Ext.Button({
+ minWidth: 80,
+ text: this.i18n.AddFileWindow.cancelBtn.text,
+ handler: this.onCancelAttachFn,
+ scope: this
+ });
+
+ // on definit 2 panel qui vont acceuillir les composants et qui vont etre les zone de drop
+ this.panelTree = this.panelTree || new Ext.Panel({
+ border: false,
+ height: 347,
+ width: 240,
+ layout: 'fit',
+ frame: true,
+ items: [
+ this.treeElt
+ ]
+ });
+
+ this.panelTreeFieldSet = this.panelTreeFieldSet || new Ext.form.FieldSet({
+ title: "Depuis mon espace de travail",
+ autoHeight:true,
+ collapsed: false,
+ style: "margin-top: 5px; margin-right: 10px;",
+ items :[
+ this.panelTree
+ ]
+ });
+
+ this.panelGrid = this.panelGrid || new Ext.Panel({
+ title: "Documents sélectionnés",
+ border: false,
+ height: 464,
+ width: 250,
+ style: "margin-left: 10px;",
+ layout: 'fit',
+ frame: true,
+ rowspan: 3,
+ items: [
+ this.preview_attachFile_grid
+ ]
+ });
+
+ this.orLabel = this.orLabel || new Ext.form.DisplayField({
+ value: this.i18n.AddFileWindow.orLabel.value,
+ cls: 'orLabel',
+ hidden: this.disableDiskUpload,
+ colspan: 2
+ });
+
+ this.upploadButtonPanel = this.upploadButtonPanel || new Ext.Panel({
+ border: false,
+ height: 45
+ });
+
+ this.uploadFieldSet = this.uploadFieldSet || new Ext.form.FieldSet({
+ title: "Depuis mon poste local",
+ autoHeight:true,
+ collapsed: false,
+ style: "margin-right: 10px;",
+ items :[
+ this.upploadButtonPanel
+ ]
+ });
+
+ this.panelContainer = this.panelContainer || new Ext.Panel({
+ layout: 'table',
+ layoutConfig: {
+ columns: 3
+ },
+ border: false,
+ frame:true,
+ /*items: [
+ this.panelTree,
+ this.addItemBtn,
+ this.panelGrid,
+ this.orLabel
+ ]*/
+ items: [
+ this.uploadFieldSet,
+ {
+ border: false,
+ html: ""
+ },
+ this.panelGrid,
+ this.panelTreeFieldSet,
+ this.addItemBtn
+ ]
+ });
+
+ EntSavoie.AddFileWindow.superclass.constructor.call(this, {
+ id: this.addFileWindowId,
+ title: this.i18n.AddFileWindow.constructor.title,
+ hidden: true,
+ border: false,
+ height: 560,
+ width: 610,
+ resizable: false,
+ layout: 'fit',
+ modal: true,
+ closeAction: 'hide',
+ items: [this.panelContainer],
+ buttons: [this.attachBtn, this.cancelBtn]
+ });
+
+
+ // definition des listeners
+ this.treeElt.on("dblclick", this.onDblclickTreeOverride, this);
+ this.panelGrid.on('render', this.onRenderPanelGridOverride, this);
+ this.panelTree.on('render', this.onRenderPanelTree, this);
+ this.on('show', this.onShow, this);
+ this.on("afterrender", this.onAfterRenderAddFileWindow, this);
+
+
+
+};
+
+Ext.extend(EntSavoie.AddFileWindow, Ext.Window, {
+ initComponent: function () {
+ EntSavoie.AddFileWindow.superclass.initComponent.call(this);
+ },
+
+ onShow: function(){
+ this.preview_attachFile_store.removeAll();
+ },
+
+ /**
+ * Rafraichissement de l'interface après ajout d'un fichier
+ */
+ refreshInterfaceAddFile: function(response) {
+ var resp = response.responseText.substring(response.responseText.indexOf("{"),response.responseText.lastIndexOf("}") + 1);
+ var backObj = Ext.decode(resp);
+ if (!backObj.success) {
+ Ext.MessageBox.alert(this.i18n.AddFileWindow.refreshInterfaceAddFile.alert[0], this.i18n.AddFileWindow.refreshInterfaceAddFile.alert[1], function(btn){});
+ }
+ else {
+ if (backObj.portal_message) {
+ Ext.MessageBox.alert(this.i18n.AddFileWindow.refreshInterfaceAddFile.alert[0], backObj.portal_message, function(btn){});
+ } else {
+ // Mise a jour de la grid
+ var record = new this.preview_attachFile_store.recordType({
+ id: backObj.id,
+ name: backObj.name,
+ type: backObj.type,
+ isNew: true,
+ isSignet: backObj.isSignet}, backObj.id);
+
+ this.preview_attachFile_store.addSorted(record);
+
+ Ext.slideMsg.msg(this.i18n.AddFileWindow.refreshInterfaceAddFile.slideMsg[0], this.i18n.AddFileWindow.refreshInterfaceAddFile.slideMsg[1] + backObj.name + this.i18n.AddFileWindow.refreshInterfaceAddFile.slideMsg[2]);
+ }
+ }
+
+ },
+
+ /**
+ * Permet de retourner l'icone correspondante au fichier
+ */
+ getFileCls: function(record) {
+ var name = record.get("name");
+ var atmp = name.split('.');
+ if(1 === atmp.length) {
+ return 'ux-folder';
+ }
+ else {
+ if(record.get('isSignet')){
+ return 'ux-file file-signet';
+ } else {
+ return 'ux-file file-' + atmp.pop().toLowerCase();
+ }
+ }
+ },
+
+ onDblclickTree: function(node, event){
+ // double click sur un noeud
+ // on ajoute le file
+ if (node.id!= "0" && this.preview_attachFile_store.find('id', node.id) == -1 && node.attributes.draggable) {
+ this.preview_attachFile_store.add(new this.attachFileRecordCreator({
+ id: node.id,
+ name: node.text,
+ type: (node.isLeaf()) ? this.i18n.AddFileWindow.onDblclickTree.type[0] : this.i18n.AddFileWindow.onDblclickTree.type[1],
+ isNew: true,
+ isSignet: node.attributes.isSignet
+ }));
+ }
+ },
+
+ onAttachFn: function(btn) {
+ var fileArray = new Array();
+ for (i=0; i<this.preview_attachFile_store.getCount(); i++) {
+ var pjRec = this.preview_attachFile_store.getAt(i);
+ fileArray.push(pjRec.get("id"));
+ }
+
+ if(fileArray.length > 0){
+ this.callUpdateOnGridFileOverride(fileArray, this.mainContainer);
+ this.hide();
+ } else {
+ Ext.MessageBox.alert(this.i18n.AddFileWindow.onAttachFn.alert[0], this.i18n.AddFileWindow.onAttachFn.alert[1], function(btn){});
+ }
+ },
+
+ onCancelAttachFn: function(btn) {
+ this.hide();
+ },
+
+ /**
+ * Evenement sur le preview rowAction, supprimer une pièce jointe
+ */
+ onRowPreviewAction: function(grid, rowIndex, colIndex) {
+ var record = grid.getStore().getAt(rowIndex);
+ this.preview_attachFile_store.remove(record);
+ },
+
+ /**
+ * Mise en forme du nom du fichier
+ */
+ renderName: function(val) {
+ return "<span style='padding-left: 20px;'>"+val+"</span>";
+ },
+
+ /**
+ * DragDrop Grid -> Tree
+ */
+ onRenderPanelTree: function(panel) {
+ panel.dropTarget = new Ext.dd.DropTarget(panel.getId(), {
+ scope : this,
+ ddGroup : "removeFileDD",
+ notifyDrop : function(dd, e, data) {
+ var recListArray = data.selections;
+ for (i = 0; i < recListArray.length; i++) {
+ this.scope.preview_attachFile_store.remove(recListArray[i]);
+ }
+ }
+ });
+ },
+
+
+ /**
+ * DragDrop Tree -> Grid
+ */
+ onRenderPanelGrid: function(panel) {
+ panel.dropTarget = new Ext.dd.DropTarget(panel.getId(), {
+ scope : this,
+ ddGroup : "attachFileDD",
+ notifyDrop : function(dd, e, data) {
+ var node = dd.dragData.node;
+ if (this.scope.preview_attachFile_store.find('id', node.id) == -1) {
+
+ this.scope.preview_attachFile_store.add(new this.scope.attachFileRecordCreator({
+ id: node.id,
+ name: node.text,
+ type: (node.isLeaf()) ? this.scope.i18n.AddFileWindow.onRenderPanelGrid.type[0] : this.scope.i18n.AddFileWindow.onRenderPanelGrid.type[1],
+ isNew: true,
+ isSignet: node.attributes.isSignet
+ }));
+ }
+ }
+ });
+ },
+
+ onAddItemFn: function(btn) {
+ var selectedNode = this.treeElt.getSelectionModel().getSelectedNode();
+ if (selectedNode!=null) {
+ if (this.preview_attachFile_store.find('id', selectedNode.id) == -1 && selectedNode.attributes.draggable) {
+ this.preview_attachFile_store.add(new this.attachFileRecordCreator({
+ id: selectedNode.id,
+ name: selectedNode.text,
+ type: (selectedNode.isLeaf()) ? this.i18n.AddFileWindow.onAddItemFn.type[0] : this.i18n.AddFileWindow.onAddItemFn.type[1],
+ isNew: true,
+ isSignet: selectedNode.attributes.isSignet
+ }));
+ }
+ }
+ },
+
+ refreshInterfaceAddFileJQuery: function(backObj) {
+ if (!backObj.success) {
+ Ext.MessageBox.alert(this.i18n.AddFileWindow.refreshInterfaceAddFile.alert[0], backObj.portal_message, function(btn){});
+ }
+ else {
+ // Mise a jour de la grid
+ var record = new this.preview_attachFile_store.recordType({
+ id: backObj.id,
+ name: backObj.name,
+ type: backObj.type,
+ isNew: true,
+ isSignet: backObj.isSignet}, backObj.id);
+
+ this.preview_attachFile_store.addSorted(record);
+
+ //Ext.slideMsg.msg(this.i18n.AddFileWindow.refreshInterfaceAddFile.slideMsg[0], this.i18n.AddFileWindow.refreshInterfaceAddFile.slideMsg[1] + backObj.name + this.i18n.AddFileWindow.refreshInterfaceAddFile.slideMsg[2]);
+ }
+ },
+
+ onAfterRenderAddFileWindow: function(panel){
+ var uploadFileBtnPanel = new EntSavoie.JQueryUploader({
+ actionURLAjax: this.actionURLAjax,
+ isGroup: true,
+ filesDropZone: document.getElementById(this.addFileWindowId),
+ colspan: 2,
+ mainContainer: this
+ });
+
+ this.upploadButtonPanel.add(uploadFileBtnPanel);
+ this.upploadButtonPanel.doLayout(false, true);
+ }
+
+
+});