--- /dev/null
+/*
+7Copyright (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.Cartable");
+EntSavoie.Cartable.FileVersionWindow = 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.recordProcessed = null;
+ this.folderId = null;
+ this.initialComment = "";
+ this.downloadCount = 0;
+ this.viewCount = 0;
+ this.permissionsView = null;
+ this.tags = null;
+ this.links = null;
+ this.keywords = null;
+
+ this.fileInformationsPanel = this.fileInformationsPanel || new Ext.Panel({
+ rowspan: 3,
+ border: false,
+ height: 75,
+ bodyStyle: {"background-color":"#DFE8F6"},
+ html: ""
+ });
+
+ // on a ici le cmp pour uploader un nouveau file!!!!
+ this.viewVersionBtn = this.viewVersionBtn || new Ext.Button({
+ handler: this.viewVersion,
+ tooltip: "Visualiser",
+ margins: "0 3 0 0",
+ width: 22,
+ iconCls: 'viewer',
+ scope: this
+ });
+
+ this.downloadBtn = this.downloadBtn || new Ext.Button({
+ handler: this.download,
+ tooltip: "Télécharger",
+ margins: "0 3 0 3",
+ width: 22,
+ iconCls: 'download',
+ scope: this
+ });
+
+ this.lockBtn = this.lockBtn || new Ext.Button({
+ handler: this.lockFile,
+ tooltip: "Verrouiller",
+ margins: "0 0 0 3",
+ width: 22,
+ iconCls: 'lockCls',
+ hidden: true,
+ scope: this
+ });
+
+ // on a ici le cmp pour uploader un nouveau file!!!!
+ this.updateContentBtn = this.updateContentBtn || new Ext.Button({
+ text: this.i18n.Cartable.FileVersionWindow.buttons[1],
+ handler: this.onUpdateContent,
+ margins: "5 5 5 5",
+ width: 85,
+ iconCls: 'browse',
+ scope: this
+ });
+
+ this.versionComment = this.versionComment || new Ext.form.TextArea({
+ height: 100,
+ width: 554,
+ colspan: 2
+ });
+
+ this.deleteVersionCommentBtn = this.deleteVersionCommentBtn || new Ext.Button({
+ handler: this.deleteVersionCommentAction,
+ margins: "3 0 0 420",
+ text: 'Effacer',
+ iconCls: 'delete',
+ scope: this
+ });
+
+
+ // Store des versions
+ this.versionStore = this.versionStore || new Ext.data.JsonStore({
+ root: 'versionItems',
+ autoLoad: false,
+ idProperty: 'id',
+ fields: ['id', 'size', {name: "date", type: "date"}, "userName", "statusByUserName", "version", "currentComment", "downloadCount", "viewCount"],
+ sortInfo: {
+ field: 'version',
+ direction: 'DESC'
+ }
+ });
+
+ // action column on version
+ this.action_column = this.action_column || new Ext.grid.ActionColumn({
+ width: 60,
+ sortable: false,
+ menuDisabled: true,
+ header: '',
+ css: 'text-align: left;',
+ items: [
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (this.recordProcessed.get('hideIconViewer') == false) {
+ return 'viewer';
+ }
+ },
+ tooltip: 'Visualiser',
+ scope: this,
+ handler: this.viewVersion
+ },
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (this.recordProcessed.get('hideIconDownload') == false) {
+ return 'download';
+ }
+ },
+ tooltip: 'Télécharger',
+ scope: this,
+ handler: this.downloadVersion
+ },
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (this.recordProcessed.get('hideEditFile') == false) {
+ return 'delete';
+ }
+ },
+ tooltip: 'Supprimer cette version',
+ scope: this,
+ handler: this.deleteVersion
+ }
+ ]
+ });
+
+ this.expanderTpl = new Ext.XTemplate(
+ '<tpl if="currentComment.length > 0">{currentComment}</tpl>'
+ );
+ this.expanderTpl.compile();
+
+
+ this.expander = this.expander || new Ext.ux.grid.RowExpander({
+ tpl : this.expanderTpl
+ });
+
+
+ this.versionGrid = this.versionGrid || new Ext.grid.GridPanel({
+ store: this.versionStore,
+ loadMask: true,
+ autoExpandColumn: 'userName',
+ autoExpandMin: 80,
+ columns: [
+ this.expander,
+ {header: "Version", width: 45, dataIndex: 'version', sortable: true, menuDisabled: true},
+ {header: "Utilisateur", id: "userName", width: 80, dataIndex: 'statusByUserName', sortable: true, menuDisabled: true},
+ {header: "Date", width: 70, dataIndex: 'date', sortable: true, menuDisabled: true, xtype: 'datecolumn', format: 'd M Y, H:i'},
+ {header: "Taille", width: 50, dataIndex: 'size', sortable: true, menuDisabled: true, renderer: function(value){return Ext.util.Format.fileSizeFR(value);}},
+ this.action_column
+ ],
+ plugins: this.expander,
+ height: 180,
+ border: false,
+ hideHeaders: false
+ });
+
+ this.commentFieldSet = this.commentFieldSet || new Ext.form.FieldSet({
+ title: 'Commentaires',
+ collapsible: false,
+ autoHeight:true,
+ items: [
+ {
+ layout: 'table',
+ border: false,
+ width: "100%",
+ bodyStyle: {"background-color":"#DFE8F6"},
+ layoutConfig: {
+ columns: 2
+ },
+ items: [
+ this.versionComment,
+ this.deleteVersionCommentBtn
+ ]
+ }
+ ]
+
+ });
+
+ this.versionFieldSet = this.versionFieldSet || new Ext.form.FieldSet({
+ title: 'Versions',
+ collapsible: true,
+ collapsed: false,
+ autoHeight:true,
+ items: [
+ this.versionGrid
+ ]
+
+ });
+
+ // Store of meta
+ this.metaStore = this.metaStore || new Ext.data.JsonStore({
+ root: 'metaItems',
+ autoLoad: false,
+ idProperty: 'id',
+ fields: ['type', "value"],
+ sortInfo: {
+ field: 'value',
+ direction: 'ASC'
+ }
+ });
+
+ // remove action column on meta data table
+ this.action_columnMeta = this.action_columnMeta || new Ext.grid.ActionColumn({
+ width: 60,
+ sortable: false,
+ menuDisabled: true,
+ header: '',
+ css: 'text-align: left;',
+ items: [
+ {
+ getClass: function(v, meta, rec, row, col, store) { // Or return a class from a function
+ if (this.recordProcessed.get('hideEditFile') == false) {
+ return 'delete';
+ }
+ },
+ tooltip: 'Supprimer cette Meta donnée',
+ scope: this,
+ handler: this.deleteMetaData
+ }
+ ]
+ });
+
+ //Meta data table
+ this.metaGrid = this.metaGrid || new Ext.grid.GridPanel({
+ store: this.metaStore,
+ loadMask: true,
+ autoExpandColumn: 'value',
+ autoExpandMin: 80,
+ columns: [
+ {header: "Type", width: 45, dataIndex: 'type', sortable: true, menuDisabled: true},
+ {header: "Valeur", id: "value", width: 80, dataIndex: 'value', sortable: true, menuDisabled: true},
+ this.action_columnMeta
+ ],
+ height: 180,
+ border: false,
+ hideHeaders: false
+ });
+
+ //Toolbar button, use to add a meta data
+ this.addMetaDataTbButton = this.addMetaDataTbButton || new Ext.Toolbar.Button({
+ text: "Ajouter",
+ tooltip: "Ajouter une meta donnée",
+ handler: this.displayFormMetaData,
+ iconCls: 'addMenu',
+ style: "margin: 0px 5px 0px 5px;",
+ scope: this
+ });
+
+ //Toolbar for the data table in the meta tab
+ this.MetaTBar = this.MetaTBar || new Ext.Toolbar({
+ enableOverflow: true,
+ items: [
+ this.addMetaDataTbButton
+ ]
+ });
+
+ this.consigneMetaPanel = this.consigneMetaPanel || new Ext.Panel({
+ rowspan: 3,
+ border: false,
+ height: 20,
+ bodyStyle: {"background-color":"#DFE8F6"},
+ html: "<p>Saississez les informations en séparant les valeurs par des virgules.</p>"
+ });
+
+ this.typeComboBox = this.typeComboBox || new Ext.form.ComboBox({
+ fieldLabel: "Type ",
+ store: ["Tag", "Lien", "Mot-clé"],
+ editable:false,
+ value: "Tag",
+ triggerAction: 'all',
+ width:200,
+ forceSelection:true,
+ selectOnFocus:true,
+ style:"height: 14px;"
+ });
+
+ this.valueTextField = this.valueTextField || new Ext.form.TextField({
+ fieldLabel:"Valeur ",
+ allowBlank:false,
+ width:200,
+ style:"height: 14px;"
+ });
+
+ this.addMetaBtn = this.addMetaBtn || new Ext.Button({
+ handler: this.addMetaData,
+ text:"Ajouter",
+ tooltip: "Valider l'ajout",
+ margins: "0 0 0 3",
+ scope: this
+ });
+
+ this.cancelMetaBtn = this.cancelMetaBtn || new Ext.Button({
+ handler: this.cancelMetaData,
+ text:"Annuler",
+ tooltip: "Annuler l'ajout",
+ margins: "0 0 0 3",
+ scope: this
+ });
+
+ //The fieldset to diplay the add form
+ this.addMetaFieldSet = this.addMetaFieldSet || new Ext.form.FieldSet({
+ title: 'Ajout de meta données',
+ collapsible: false,
+ collapsed: false,
+ autoHeight:true,
+ hidden: true,
+ items: [
+ this.consigneMetaPanel,
+ this.typeComboBox,
+ this.valueTextField,
+ {
+ layout: 'column',
+ bodyStyle: {"background-color":"#DFE8F6"},
+ border: false,
+ items: [
+ {
+ columnWidth: .10,
+ layout: 'fit',
+ border: false,
+ bodyStyle: {"background-color":"#DFE8F6"},
+ items: [ this.addMetaBtn]
+ },
+ {
+ columnWidth: .10,
+ layout: 'fit',
+ border: false,
+ bodyStyle: {"background-color":"#DFE8F6"},
+ items: [this.cancelMetaBtn]
+ }
+ ]
+ }
+ ]
+ });
+
+ //The fieldset that will contains the meta data
+ this.metaFieldSet = this.metaFieldSet || new Ext.form.FieldSet({
+ title: 'Meta données',
+ collapsible: false,
+ collapsed: false,
+ autoHeight:true,
+ items: [
+ this.MetaTBar,
+ this.addMetaFieldSet,
+ this.metaGrid
+ ]
+
+ });
+
+ this.fileVersionInformationsPanel = this.fileVersionInformationsPanel || new Ext.Panel({
+ title: "Versions",
+ bodyStyle: {"background-color":"#DFE8F6"},
+ items: [
+ {
+ layout: 'column',
+ bodyStyle: {"background-color":"#DFE8F6"},
+ border: false,
+ items: [
+ {
+ columnWidth: .99,
+ layout: 'fit',
+ border: false,
+ bodyStyle: {"background-color":"#DFE8F6"},
+ items: [this.fileInformationsPanel]
+ },
+ {
+ width: 100,
+ layout: "form",
+ border: false,
+ bodyStyle: {"background-color":"#DFE8F6"},
+ items: [
+ {
+ layout: "hbox",
+ border: false,
+ bodyStyle: {"background-color":"#DFE8F6"},
+ layoutConfig: {
+ pack: 'center',
+ align: 'middle'
+ },
+ style: 'margin-top: 5px;',
+ items: [
+ this.viewVersionBtn,
+ this.downloadBtn,
+ this.lockBtn
+ ]
+
+ },
+ {
+ layout: "hbox",
+ border: false,
+ bodyStyle: {"background-color":"#DFE8F6"},
+ layoutConfig: {
+ pack: 'center',
+ align: 'middle'
+ },
+ items: [
+ this.updateContentBtn
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ this.commentFieldSet,
+ this.versionFieldSet
+ ]
+
+ });
+
+ this.fileVersionPermissionsPanel = this.fileVersionPermissionsPanel || new Ext.Panel({
+ title: "Permissions",
+ bodyStyle: {"background-color":"#DFE8F6"},
+ layout: "fit",
+ items: []
+
+ });
+
+ this.fileVersionMetaPanel = this.fileVersionMetaPanel || new Ext.Panel({
+ title: "Meta-données",
+ bodyStyle: {"background-color":"#DFE8F6"},
+ layout: "fit",
+ items: [
+ this.metaFieldSet
+ ]
+
+ });
+
+ this.fileVersionTabPanel = this.fileVersionTabPanel || new Ext.TabPanel({
+ activeTab: 0,
+ border: false,
+ padding: 5,
+ bodyStyle: {"background-color":"#DFE8F6"},
+ items: [
+ this.fileVersionInformationsPanel,
+ this.fileVersionMetaPanel
+ ]
+ });
+
+ EntSavoie.Cartable.FileVersionWindow.superclass.constructor.call(this, {
+ cls: "cartable-portlet",
+ title: this.i18n.Cartable.FileVersionWindow.titleFile,
+ modal: true,
+ width: 600,
+ height: 535,
+ padding: 5,
+ closable: false,
+ layout: "fit",
+ autoScroll: true,
+ items: [],
+ buttons: [
+ {
+ text: this.i18n.Cartable.FileVersionWindow.buttons[0],
+ handler: this.onClose,
+ scope: this
+ }
+ ]
+ });
+
+ this.on("show", this.onShowFileVersionWindow, this);
+ this.fileInformationsPanel.on("afterrender", this.onAfterRenderFileInformationsPanel, this);
+ this.fileVersionPermissionsPanel.on("afterrender", this.onAfterRenderFileVersionPermissionsPanel, this);
+ this.fileVersionMetaPanel.on("afterrender", this.onAfterRenderFileVersionMetaPanel, this);
+};
+
+Ext.extend(EntSavoie.Cartable.FileVersionWindow, Ext.Window, {
+ initComponent: function () {
+ EntSavoie.Cartable.FileVersionWindow.superclass.initComponent.call(this);
+ },
+
+ manageVersion: function(rec, folderId) {
+ this.recordProcessed = rec;
+ this.folderId = folderId;
+ this.show();
+ },
+
+ onShowFileVersionWindow: function(win){
+ this.wait = new Ext.LoadMask(this.id, {msg: "<b>Chargement des informations en cours.</b> <br/> Veuillez patienter ..."});
+ this.wait.show();
+
+ var isFile = this.recordProcessed.get("type")=="Fichier" && this.recordProcessed.get("isSignet")==false;
+
+ if(!isFile){
+ this.setTitle(this.i18n.Cartable.FileVersionWindow.titleFolder);
+ this.setWidth(725);
+ this.setHeight(555);
+ }
+
+ // Bouton de visualisation
+ if(this.recordProcessed.get('hideIconViewer')){
+ this.viewVersionBtn.disable();
+ } else {
+ this.viewVersionBtn.enable();
+ }
+
+ // Mise a jour de l'interface
+ if(this.isGroup){
+ if(isFile){
+ // Informations + Permissions
+ if(this.recordProcessed.get('hideIconPermissions') == false){
+ this.versionComment.setWidth(544);
+ this.versionGrid.setHeight(175);
+ this.fileVersionTabPanel.add(this.fileVersionPermissionsPanel);
+ this.add(this.fileVersionTabPanel);
+ }
+ // Informations
+ else {
+ this.add(this.fileVersionTabPanel);
+ }
+ // Permissions
+ } else {
+ this.add(this.fileVersionPermissionsPanel);
+ }
+ }
+ // Informations
+ else if(isFile) {
+ this.add(this.fileVersionTabPanel);
+ }
+ this.doLayout();
+
+ this.wait.hide();
+ },
+
+ onAfterRenderFileInformationsPanel: function(){
+ this.loadDataVersionStore();
+ },
+
+ onAfterRenderFileVersionPermissionsPanel: function(panel){
+ // Maj des permissions
+ this.permissionsView = new EntSavoie.Cartable.gestionPermissions({
+ renderURLAjax: this.renderURLAjax,
+ actionURLAjax: this.actionURLAjax,
+ type: this.recordProcessed.get("type")=="Dossier" ? "folder" : "file",
+ objectId: this.recordProcessed.get("id"),
+ objectName: this.recordProcessed.get("title")
+ });
+ this.fileVersionPermissionsPanel.add(this.permissionsView);
+ },
+
+ onAfterRenderFileVersionMetaPanel: function(panel){
+ //load the meta data into the grid
+ this.loadDataMetaStore();
+ },
+
+ refreshFileVersionInformations: function(loadVersionStore){
+ var fileInformations = "";
+ var lockInformations = "";
+ var rowspan = 5;
+ if(this.recordProcessed.get("lock")){
+ lockInformations += "<tr>" +
+ "<td>" +
+ "Verrouiller pour une péride de 1 jour" +
+ "</td>" +
+ "</tr>";
+ rowspan = 6;
+ }
+
+ //Add the all the different downloads together to have the file's total number of download
+ if (this.downloadCount == 0){
+ for (var i=0; i<this.versionStore.totalLength; ++i){
+ this.downloadCount += this.versionStore.getAt(i).get("downloadCount");
+ }
+ }
+
+ if (this.viewCount == 0){
+ for (var i=0; i<this.versionStore.totalLength; ++i){
+ this.viewCount += this.versionStore.getAt(i).get("viewCount");
+ }
+ }
+
+ fileInformations += "<table width='100%'>" +
+ "<tr>" +
+ "<td rowspan='" + rowspan + "'>" +
+ "<img width='36' height='36' src='" + this.recordProcessed.get('urlImg') + "'/>" +
+ "</td>" +
+ "<td>" +
+ "<a style='cursor: pointer;' onclick='window.open(\"" + this.recordProcessed.get('pathMain') + "/document_library/get_file?p_l_id="+this.recordProcessed.get('plid')+"&fileEntryId="+this.recordProcessed.get('id')+"&contentDispo=attachment\")'>" +
+ this.recordProcessed.get("title") +
+ "</a>" +
+ " (" + Ext.util.Format.fileSizeFR(this.recordProcessed.get("size")) + ")"+
+ "</td>" +
+ "</tr>" +
+ "<tr>" +
+ "<td>" +
+ "Version " + this.recordProcessed.get("version") +
+ "</td>" +
+ "</tr>" +
+ "<tr>" +
+ "<td>" +
+ "Modifié par " + this.recordProcessed.get("creator") + " le " + Ext.util.Format.date(this.recordProcessed.get("date"), 'd M Y à H:i') +
+ "</td>" +
+ "</tr>" +
+ "<tr>" +
+ "<td>" +
+ "Visionné " + this.viewCount + " fois - " +"Téléchargé " + this.downloadCount + " fois" +
+ "</td>" +
+ "</tr>" +
+ lockInformations +
+ "</table>";
+
+ //MSA
+ if (this.recordProcessed.get('hideEditFile') == false && !this.isCasier) {
+ this.action_columnMeta.hidden = false;
+ this.MetaTBar.show();
+ this.updateContentBtn.show();
+ this.deleteVersionCommentBtn.show();
+ this.versionComment.setReadOnly(false);
+ if(this.isGroup){
+ this.lockBtn.show();
+ if(this.recordProcessed.get("lock")){
+ this.lockBtn.setTooltip("Déverrouiller");
+ this.lockBtn.setIconClass("unlockCls");
+ } else {
+ this.lockBtn.setTooltip("Verrouiller");
+ this.lockBtn.setIconClass("lockCls");
+ }
+ }
+ }
+ else {
+ this.action_columnMeta.hidden = true;
+ this.MetaTBar.hide();
+ this.updateContentBtn.hide();
+ this.deleteVersionCommentBtn.hide();
+ this.versionComment.setReadOnly(true);
+ }
+
+ this.fileInformationsPanel.body.update(fileInformations);
+
+ },
+
+ loadDataVersionStore: function(){
+ Ext.Ajax.request({
+ url: this.renderURLAjax+'&jspPage=%2Fajax%2FlistFileVersion.jsp&fileId=' + this.recordProcessed.get("id")+ '&folderId=' + this.folderId+ '&fileName=' + this.recordProcessed.get("name") + '&version=' + this.recordProcessed.get("version"),
+ success: this.onSuccessLoadDataVersionStore,
+ failure: this.onFailureLoadDataVersionStore,
+ scope: this
+ });
+ },
+
+ onSuccessLoadDataVersionStore:function(response, options) {
+ var backObj = Ext.decode(response.responseText);
+ this.recordProcessed.set("downloadCount", backObj.downloadCount);
+ this.recordProcessed.set("viewCount", backObj.viewCount);
+ this.recordProcessed.set("currentComment", backObj.comment);
+ this.versionStore.loadData(backObj);
+ this.refreshFileVersionInformations(false);
+ this.versionComment.setValue(backObj.currentComment);
+ this.initialComment = backObj.currentComment;
+ },
+
+ onFailureLoadDataVersionStore:function(response, options) {
+ Ext.MessageBox.alert("Informations du fichier", "La mise à jour des versions ne peut être réalisée", function(btn){});
+ },
+
+ // Mise a jour du contenu du fichier
+ onUpdateContent: function (btn) {
+ // Sauvegarde du commentaire au cas ou l'utilisateur en aurait saisi un
+ if ((this.versionComment.getValue()!=this.initialComment) && (this.recordProcessed.get('hideEditFile') == false)) {
+ this.saveEntityInformations(true, false);
+ }
+ var fileChooser = new EntSavoie.FileChooser({
+ renderURLAjax: this.renderURLAjax,
+ mainWindow: Ext.isIE ? this : null,
+ actionURLAjax: this.actionURLAjax,
+ checkExtension: true,
+ extensions: this.recordProcessed.get("fileExtension"),
+ uploadCmd: 'updateFileContent&fileIdTarget='+this.recordProcessed.get("id"),
+ supportedExtensions: [this.recordProcessed.get("fileExtension")],
+ allowUpload: true,
+ callBackFnJQuery: this.onContentUpdatedWithJQueryUploader.createDelegate(this),
+ callBackFn: this.onContentUpdated.createDelegate(this)
+ });
+ fileChooser.show();
+
+ },
+
+ onContentUpdated: function(idFile) {
+ if(!this.wait){
+ this.wait = new Ext.LoadMask(this.id, {msg: "<b>Mise à jour du fichier en cours</b> <br/> Veuillez patienter ..."});
+ }
+ this.wait.show();
+
+ Ext.Ajax.request({
+ url:this.actionURLAjax,
+ params:{
+ cmd: "updateFileContentFromCartable",
+ fileIdSource: idFile,
+ fileIdTarget: this.recordProcessed.get("id")
+ },
+ success: this.onSuccessContentUpdated,
+ failure: this.onFailureContentUpdated,
+ scope: this
+ });
+ },
+
+ onSuccessContentUpdated:function(response, options) {
+ this.wait.hide();
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert("Informations du fichier", "Problème lors de la mise a jour du fichier", function(btn){});
+ }else{
+ Ext.slideMsg.msg("Informations du fichier", "Le fichier a été correctement mis à jour.");
+ this.recordProcessed.set("version", backObj.version);
+ this.recordProcessed.set("size", backObj.size);
+ this.recordProcessed.set("date", backObj.date);
+ this.recordProcessed.set("creator", backObj.creator);
+ this.recordProcessed.set("downloadCount", 0);
+ this.recordProcessed.set("viewCount", 0);
+ this.loadDataVersionStore();
+ }
+ },
+
+ onFailureContentUpdated:function(response, options) {
+ this.wait.hide();
+ Ext.MessageBox.alert("Informations du fichier", "Problème lors de la mise a jour du fichier", function(btn){});
+ },
+
+ onContentUpdatedWithJQueryUploader: function(backObj){
+ // choix depuis le poste local
+ Ext.slideMsg.msg("Informations du fichier", "Le fichier a été correctement mis à jour.");
+ this.recordProcessed.set("version", backObj.version);
+ this.recordProcessed.set("size", backObj.size);
+ this.recordProcessed.set("date", backObj.date);
+ this.recordProcessed.set("creator", backObj.creator);
+ this.recordProcessed.set("downloadCount", 0);
+ this.recordProcessed.set("viewCount", 0);
+ this.loadDataVersionStore();
+ },
+
+
+ /**
+ * Telechargement d'un fichier versionne
+ */
+ download: function(cmp, rowIndex, colIndex){
+ var version = "";
+ if (cmp.getXType() == 'grid') {
+ var record = cmp.getStore().getAt(rowIndex);
+ version = "&version=" + record.get("version");
+ }
+ window.location = this.recordProcessed.get('pathMain')+"/document_library/get_file?p_l_id="+this.recordProcessed.get('plid')+"&fileEntryId="+this.recordProcessed.get('id')+"&contentDispo=attachment" + version;
+ var comment = this.versionComment.getValue();
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "incrementDownloadCount",
+ entityId: this.recordProcessed.get("id"),
+ version: this.recordProcessed.get("version"),
+ comment: comment,
+ downloadCount: this.recordProcessed.get("downloadCount"),
+ viewCount: this.recordProcessed.get("viewCount")
+ },
+ scope: this,
+ success: this.onSuccessIncrementDownloadCount,
+ failure: this.onFailureIncrementDownloadCount
+ });
+ },
+
+ downloadVersion: function(grid, rowIndex, colIndex){
+ var record = grid.getStore().getAt(rowIndex);
+ window.location = this.recordProcessed.get('pathMain') + "/document_library/get_file?p_l_id=" + this.recordProcessed.get('plid') + "&fileEntryId=" + this.recordProcessed.get('id') + "&contentDispo=attachment&version=" + record.get("version");
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "incrementDownloadCount",
+ entityId: this.recordProcessed.get("id"),
+ version: record.get("version"),
+ comment: record.get("currentComment"),
+ downloadCount: record.get("downloadCount"),
+ viewCount: record.get("viewCount")
+ },
+ scope: this,
+ success: this.onSuccessIncrementDownloadCount,
+ failure: this.onFailureIncrementDownloadCount
+ });
+ },
+
+ onSuccessIncrementDownloadCount: function(response, options) {
+ ++ this.downloadCount;
+ this.loadDataVersionStore();
+ //Ext.MessageBox.alert("Download ok Info", "Download ok Info", function(btn){});
+ },
+
+ onFailureIncrementDownloadCount: function(response, options) {
+ Ext.MessageBox.alert("Download ko Info", "Erreur : la mise à jour des téléchargements a échoué !", function(btn){});
+ },
+
+ /**
+ * visu d'un fichier versionne
+ */
+ viewVersion: function(cmp, rowIndex, colIndex){
+ var version = null;
+ if (cmp.getXType() == 'grid') {
+ var tmp = cmp.getStore().getAt(rowIndex);
+ var record = this.recordProcessed.copy();
+ record.set("version", tmp.get("version"));
+ if (rowIndex == 0)
+ record.set("currentComment", this.versionComment.getValue());
+ else
+ record.set("currentComment", tmp.get("currentComment"));
+ record.set("downloadCount", tmp.get("downloadCount"));
+ record.set("viewCount", tmp.get("viewCount"));
+ record.set("size", tmp.get("size"));
+ record.set("userName", tmp.get("userName"));
+ version = record.get("version");
+ this.mainContainer.checkFileSizeOnViewerAction(record, version);
+ }
+ else{
+ this.recordProcessed.set("currentComment", this.versionComment.getValue());
+ this.mainContainer.checkFileSizeOnViewerAction(this.recordProcessed, version);
+ }
+
+ ++ this.viewCount;
+ this.loadDataVersionStore();
+
+ },
+
+ /**
+ * Lock / Unlock d'un file
+ */
+ lockFile: function(btn){
+ if(!this.wait){
+ this.wait = new Ext.LoadMask(this.id, {msg: "<b>Mise à jour du fichier en cours</b> <br/> Veuillez patienter ..."});
+ }
+ this.wait.show();
+
+ Ext.Ajax.request({
+ url:this.actionURLAjax,
+ params:{
+ cmd: "lockFile",
+ fileId: this.recordProcessed.get("id")
+ },
+ success: this.onSuccessLockFile,
+ failure: this.onFailureLockFile,
+ scope: this
+ });
+ },
+
+ onSuccessLockFile: function(response, options) {
+ this.wait.hide();
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert("Informations du fichier", "Problème lors du verrouillage du fichier", function(btn){});
+ }else{
+ this.recordProcessed.set("lock", backObj.lock);
+ this.refreshFileVersionInformations(false);
+ }
+ },
+
+ onFailureLockFile: function(response, options) {
+ this.wait.hide();
+ Ext.MessageBox.alert("Informations du fichier", "Problème lors du verrouillage du fichier", function(btn){});
+ },
+
+ /**
+ * commenter la version
+ */
+ deleteVersionCommentAction: function(btn){
+ this.versionComment.setValue("");
+ },
+
+ saveEntityInformations: function(saveCommentNeeded, savePermissionsNeeded){
+ var entityId = this.recordProcessed.get("id");
+ var version = this.recordProcessed.get("version");
+ var downloadCount = this.recordProcessed.get("downloadCount");
+ var viewCount = this.recordProcessed.get("viewCount");
+ var comment = "";
+ var permissions = new Array();
+ var applyToChildren = false;
+
+ if(saveCommentNeeded && savePermissionsNeeded) {
+ comment = this.versionComment.getValue();
+ permissions = this.permissionsView.getPermissionsArray();
+ applyToChildren = this.permissionsView.getApplyToChildren();
+ } else if(saveCommentNeeded){
+ comment = this.versionComment.getValue();
+ } else if(savePermissionsNeeded) {
+ permissions = this.permissionsView.getPermissionsArray();
+ applyToChildren = this.permissionsView.getApplyToChildren();
+ }
+
+ if(saveCommentNeeded || savePermissionsNeeded){
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "saveInformations",
+ saveComment: saveCommentNeeded,
+ savePermissions: savePermissionsNeeded,
+ entityId: entityId,
+ version: version,
+ comment: comment,
+ downloadCount: downloadCount,
+ viewCount: viewCount,
+ permissions: Ext.util.JSON.encode(permissions),
+ applytoChildren: applyToChildren
+ },
+ scope: this,
+ success: this.onSuccessSaveInformations,
+ failure: this.onFailureSaveInformations
+ });
+ }
+ },
+
+ onSuccessSaveInformations: function(response, options) {
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert("Informations du fichier", "Problème lors de la sauvegarde des informations", function(btn){});
+ } else {}
+ },
+
+ onFailureSaveInformations: function(response, options) {
+ Ext.MessageBox.alert("Informations du fichier", "Problème lors de la sauvegarde des informations", function(btn){});
+ },
+
+ /**
+ * suppression de la version
+ */
+ deleteVersion: function(grid, rowIndex, colIndex){
+ var record = grid.getStore().getAt(rowIndex);
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "deleteVersion",
+ fileId: this.recordProcessed.get("id"),
+ version: record.get("version")
+ },
+ scope: this,
+ success: this.onSuccessDeleteVersion,
+ failure: this.onFailureDeleteVersion
+ });
+ },
+
+ onSuccessDeleteVersion: function(response, options) {
+ // Traitement des messages
+ var backObj = Ext.decode(response.responseText);
+ if (!backObj.success) {
+ Ext.MessageBox.alert("Informations du fichier", "Problème lors de la suppression de la version", function(btn){});
+ } else {
+ Ext.slideMsg.msg("Informations du fichier", "La version a été correctement supprimée.");
+
+ // on met a jour le store des versions version actuelle
+ var index = this.versionStore.find("version", backObj.version);
+ var record = this.versionStore.getAt(index);
+ this.versionStore.remove(record);
+
+ //update the header informations
+ this.downloadCount = 0;
+ this.viewCount = 0;
+ this.recordProcessed.set("version", this.versionStore.getAt(0).get("version"));
+ this.recordProcessed.set("downloadCount", this.versionStore.getAt(0).get("downloadCount"));
+ this.recordProcessed.set("viewCount", this.versionStore.getAt(0).get("viewCount"));
+ this.recordProcessed.set("currentComment", this.versionStore.getAt(0).get("currentComment"));
+ this.loadDataVersionStore();
+ }
+ },
+
+ onFailureDeleteVersion: function(response, options) {
+ Ext.MessageBox.alert("Informations du fichier", "Problème lors de la suppression de la version", function(btn){});
+ },
+
+
+ onClose: function(btn) {
+ var saveCommentNeeded = false;
+ if(this.recordProcessed.get("type")=="Fichier" && this.recordProcessed.get("isSignet")==false){
+ if((this.versionComment.getValue()!=this.initialComment) && (this.recordProcessed.get('hideEditFile') == false)){
+ saveCommentNeeded = true;
+ }
+ }
+ var savePermissionsNeeded = false;
+ if(this.permissionsView != null && this.recordProcessed.get('hideIconPermissions') == false){
+ savePermissionsNeeded = this.permissionsView.hasChanges();
+ }
+ this.saveEntityInformations(saveCommentNeeded, savePermissionsNeeded);
+ this.close();
+ },
+
+ //Load the meta data from the database
+ loadDataMetaStore: function(){
+ Ext.Ajax.request({
+ url: this.renderURLAjax+'&jspPage=%2Fajax%2FlistFileTag.jsp&fileId=' + this.recordProcessed.get("id")+ '&folderId=' + this.folderId+ '&fileName=' + this.recordProcessed.get("name") + '&version=' + this.recordProcessed.get("version"),
+ success: this.onSuccessLoadDataMetaStore,
+ failure: this.onFailureLoadDataMetaStore,
+ scope: this
+ });
+ },
+
+ //Load the data into the grid
+ onSuccessLoadDataMetaStore:function(response, options) {
+ var backObj = Ext.decode(response.responseText);
+
+ this.tags = backObj.tagList.split(",");
+ this.links = backObj.linkList.split(",");
+ this.keywords = backObj.keywordList.split(",");
+
+ var metaData = [];
+ var i, indice = 0;
+ for (i = 0 ; i<this.tags.length ; ++i){
+ if (this.tags[i] != ""){
+ metaData[indice ++] = {type:"Tag", value:this.tags[i]};
+ }
+ }
+ for (i = 0 ; i<this.links.length ; ++i){
+ if (this.links[i] != ""){
+ metaData[indice ++] = {type:"Lien", value:this.links[i]};
+ }
+ }
+ for (i = 0 ; i<this.keywords.length ; ++i){
+ if (this.keywords[i] != ""){
+ metaData[indice ++] = {type:"Mot-clé", value:this.keywords[i]};
+ }
+ }
+ var store = {metaItems:metaData, length:metaData.length};
+ this.metaStore.loadData(store);
+ },
+
+ onFailureLoadDataMetaStore:function(response, options) {
+ Ext.MessageBox.alert("Informations du fichier", "La mise à jour des meta données ne peut être réalisée", function(btn){});
+ },
+
+ //build the strings the each type of meta data
+ metaToString: function() {
+ var i;
+ var metaStrings = [];
+
+ metaStrings[0] = "";
+ this.tags.sort();
+ for (i = 0 ; i<this.tags.length ; ++i){
+
+ if (this.tags[i] != "") {
+ metaStrings[0] += this.tags[i];
+
+ if (i != this.tags.length-1){
+ metaStrings[0] += ",";
+ }
+ }
+ }
+
+ metaStrings[1] = "";
+ this.links.sort();
+ for (i = 0 ; i<this.links.length ; ++i){
+
+ if (this.links[i] != "") {
+ metaStrings[1] += this.links[i];
+
+ if (i != this.links.length-1){
+ metaStrings[1] += ",";
+ }
+ }
+ }
+
+ metaStrings[2] = "";
+ this.keywords.sort();
+ for (i = 0 ; i<this.keywords.length ; ++i){
+
+ if (this.keywords[i] != "") {
+ metaStrings[2] += this.keywords[i];
+
+ if (i != this.keywords.length-1){
+ metaStrings[2] += ",";
+ }
+ }
+ }
+
+ return metaStrings;
+ },
+
+ //display the form panel to add data
+ displayFormMetaData: function(btn) {
+ this.addMetaFieldSet.show();
+ this.valueTextField.focus();
+ },
+
+ //check the text given by the user and add the datas
+ addMetaData: function(btn) {
+
+ if(this.valueTextField.getValue() != "") {
+
+ if(this.typeComboBox.value == "Tag"){
+ var newTags = this.valueTextField.getValue().split(",");
+ for (var i = 0 ; i<newTags.length ; ++i){
+ this.tags[this.tags.length] = newTags[i];
+ }
+ } else if (this.typeComboBox.value == "Lien") {
+ var newLinks = this.valueTextField.getValue().split(",");
+ for (var i = 0 ; i<newLinks.length ; ++i){
+ this.links[this.links.length] = newLinks[i];
+ }
+ } else {
+ var newKeywords = this.valueTextField.getValue().split(",");
+ for (var i = 0 ; i<newKeywords.length ; ++i){
+ this.keywords[this.keywords.length] = newKeywords[i];
+ }
+ }
+
+ var data = this.metaToString();
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "saveFileTags",
+ entityId: this.recordProcessed.get("id"),
+ tagList: data[0],
+ linkList: data[1],
+ keywordList: data[2]
+ },
+ scope: this,
+ success: this.onSuccessSaveFileTags,
+ failure: this.onFailureSaveFileTags
+ });
+ }
+
+
+ },
+
+ onSuccessSaveFileTags: function(response, options) {
+ this.addMetaFieldSet.hide();
+ this.loadDataMetaStore();
+ },
+
+ onFailureSaveFileTags: function(response, options) {
+ Ext.MessageBox.alert("Sauvegarde meta KO", "Erreur : la sauvegarde des meta données a échoué !", function(btn){});
+ },
+
+ cancelMetaData: function(btn) {
+ this.addMetaFieldSet.hide();
+ },
+
+ //remove the data selected
+ deleteMetaData: function(cmp, rowIndex, colIndex) {
+
+ var tmp = cmp.getStore().getAt(rowIndex);
+ if (tmp.get('type') == "Tag")
+ this.tags.remove(tmp.get('value'));
+ else if (tmp.get('type') == "Lien")
+ this.links.remove(tmp.get('value'));
+ else if (tmp.get('type') == "Mot-clé")
+ this.keywords.remove(tmp.get('value'));
+
+ var data = this.metaToString();
+
+ Ext.Ajax.request({
+ url: this.actionURLAjax,
+ params: {
+ cmd: "saveFileTags",
+ entityId: this.recordProcessed.get("id"),
+ tagList: data[0],
+ linkList: data[1],
+ keywordList: data[2]
+ },
+ scope: this,
+ success: this.onSuccessSaveFileTags,
+ failure: this.onFailureSaveFileTags
+ });
+ }
+
+});