--- /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.FileChooser = 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';
+
+ //passer des extension valid en param.
+ this.extensions = this.extensions || "";
+ //enable select sur treeElt seulement sur ces extension
+ this.extensionsArray=this.extensions.split(',');
+
+ this.checkExtension = this.checkExtension || false;
+
+ this.callBackFn = this.callBackFn || this.callBackDefaultFn;
+
+ this.supportedExtensions = this.supportedExtensions || [];
+
+ //Defini l'arbre represantant le parcours du cartable
+ this.treeLoader = new Ext.tree.TreeLoader({
+ dataUrl: this.renderURLAjax+"&jspPage=/ajax/chooseFile.jsp"
+ });
+
+ this.treeElt = this.treeElt || new Ext.tree.TreePanel({
+ useArrows: true,
+ autoScroll: true,
+ animate: true,
+ containerScroll: true,
+ border: true,
+ cls: "treeView",
+ loader: this.treeLoader,
+ rootVisible: false,
+ root:{
+ noteType: 'async',
+ text:this.i18n.FileChooser.treeElt.text,
+ id:"0",
+ draggable: false
+ }
+ });
+
+ this.panelTree = this.panelTree || new Ext.Panel({
+ border: false,
+ height: !this.allowImageViewer?437:300,
+ width: 500,
+ layout: 'fit',
+ items: [
+ this.treeElt
+ ]
+ });
+
+ this.panelTreeFieldSet = this.panelTreeFieldSet || new Ext.form.FieldSet({
+ title: this.i18n.FileChooser.panelTreeFieldSet.title,
+ autoHeight:true,
+ collapsed: false,
+ style: "margin-top: 5px;",
+ items :[
+ this.panelTree
+ ]
+ });
+
+ this.orLabel = this.orLabel || new Ext.form.DisplayField({
+ value: this.i18n.FileChooser.orLabel.value,
+ style: 'color: #15428B; font-size: 12px; margin-left: 10px;',
+ hideLabel: true,
+ hidden: !this.allowUpload
+ });
+
+ this.extensionLabel = this.extensionLabel ||new Ext.form.Label({
+ style: 'color: #15428B; font-size: 12px; margin-left: 10px;',
+ text: this.supportedExtensions.length > 0 ? this.i18n.FileChooser.extensionLabel.value[0] + " " + this.supportedExtensions.join().replace(new RegExp(",", 'g'), ", ") : this.i18n.FileChooser.extensionLabel.value[1],
+ hidden: !this.allowUpload
+ });
+
+ this.validBtn = this.validBtn || new Ext.Button({
+ minWidth: 80,
+ text: this.i18n.FileChooser.validBtn.text,
+ handler: this.onValidFn,
+ scope: this
+ });
+
+ this.cancelBtn = this.cancelBtn || new Ext.Button({
+ minWidth: 80,
+ text: this.i18n.FileChooser.cancelBtn.text,
+ handler: this.close,
+ scope: this
+ });
+
+ this.uploadFormPanel = this.uploadFormPanel || new Ext.Panel({
+ border: false,
+ width: 495,
+ bodyStyle:{"background-color": "#DFE8F6"},
+ items: [
+ this.extensionLabel
+ ]
+ });
+
+ this.uploadFieldSet = this.uploadFieldSet || new Ext.form.FieldSet({
+ title: this.i18n.FileChooser.uploadFieldSet.title,
+ autoHeight:true,
+ collapsed: false,
+ hidden: !this.allowUpload,
+ items :[
+ this.uploadFormPanel
+ ]
+ });
+
+ this.storeThumbs = this.storeThumbs || new Ext.data.ArrayStore({
+ fields: ['id', 'name', 'url', 'height', 'width']
+ });
+
+ if(this.allowImageViewer){
+ this.storeThumbs.loadData(this.imageData);
+ }
+
+ this.tplThumbs = this.tplThumbs || new Ext.XTemplate(
+ '<tpl for=".">',
+ '<div class="imageView-box">',
+ '<img width="126" height="42" src="{url}">',
+ '</div>',
+ '</tpl>'
+ );
+ this.tplThumbs.compile();
+
+ this.dvThumbs = this.dvThumbs || new Ext.DataView({
+ autoScroll: true,
+ store: this.storeThumbs,
+ tpl: this.tplThumbs,
+ multiSelect: false,
+ singleSelect: true,
+ style: 'margin: 0 auto;',
+ selectedClass: 'x-imageView-selected',
+ overClass: 'x-imageView-over',
+ itemSelector: 'div.imageView-box',
+ border: false
+ });
+
+ this.imageViewFieldSet = this.imageViewFieldSet || new Ext.form.FieldSet({
+ title: this.imageViewerTitle,
+ height: 120,
+ collapsed: false,
+ autoScroll: true,
+ hidden: !this.allowImageViewer,
+ items: [
+ this.dvThumbs
+ ]
+ });
+
+ this.uploadPictureCKEditorInformationPanel = this.uploadPictureCKEditorInformationPanel || new Ext.Panel({
+ style: 'color: #15428B; font-size: 12px;',
+ border: false,
+ hidden: this.uploadCmd != "uploadPictureCKEditor",
+ bodyStyle:{"background-color": "#DFE8F6"},
+ html: "<i><b>Information : </b>Les images de dimensions supérieures à 500 x 500 seront automatiquement redimensionnées afin d'être consultables dans les différents services de l'ENT. " +
+ "Vous avez cependant la possibilité de la redimensionner à travers l'éditeur (double clic sur l'image).</i>"
+ });
+
+ var myHeight = 670;
+ if(this.supportedExtensions.length>12){
+ myHeight = myHeight + 20;
+ }
+ if(this.uploadCmd == "uploadPictureCKEditor"){
+ myHeight = myHeight + 50;
+ }
+
+ EntSavoie.FileChooser.superclass.constructor.call(this, {
+ title: this.i18n.FileChooser.constructor.title,
+ border: false,
+ height: myHeight,
+ width: 550,
+ y: 30,
+ resizable: true,
+ modal: true,
+ padding: 10,
+ items: [this.uploadFieldSet, this.panelTreeFieldSet, this.imageViewFieldSet, this.uploadPictureCKEditorInformationPanel],
+ buttons: [this.validBtn, this.cancelBtn]
+ });
+
+ this.treeLoader.on("beforeload",this.onBeforeLoadTreeLoader, this);
+ this.treeElt.on("dblclick", this.onDblClickTreeElt, this);
+ this.treeElt.on("click", this.onClickTreeElt, this);
+ this.uploadFormPanel.on("afterrender", this.onAfteRenderUploadFormPanel, this);
+ this.on("show", this.onShowFCWindow, this);
+ this.on("hide", this.onHideFCWindow, this);
+ this.dvThumbs.on("click", this.onClickDvThumbs, this);
+ this.dvThumbs.on("dblclick", this.onDblClickDvThumbs, this);
+
+};
+
+Ext.extend(EntSavoie.FileChooser, Ext.Window, {
+ initComponent: function () {
+ EntSavoie.FileChooser.superclass.initComponent.call(this);
+ },
+
+ onBeforeLoadTreeLoader: function(tl, node){
+ tl.baseParams.extensions = this.extensions;
+ tl.baseParams.checkExtension = this.checkExtension;
+ },
+
+ onClickTreeElt: function(node, e){
+ this.dvThumbs.clearSelections();
+ },
+
+ onDblClickTreeElt: function(node, event){
+ if (node==null || !node.isLeaf()) {
+ return false;
+ }else{
+ this.close();
+ this.callBackFn(node.id, node.text, node.attributes.url, node.attributes.imageHeight, node.attributes.imageWidth);
+ }
+ },
+
+ onValidFn: function(btn){
+ var selectedNode = this.treeElt.getSelectionModel().getSelectedNode();
+ var selectedImagRecords = this.dvThumbs.getSelectedRecords();
+ if ((selectedNode==null || !selectedNode.isLeaf()) && selectedImagRecords.length == 0) {
+ Ext.MessageBox.alert(this.i18n.FileChooser.onValidFn.alert[0], this.i18n.FileChooser.onValidFn.alert[1] + (this.allowUpload?this.i18n.FileChooser.onValidFn.alert[2]:this.i18n.FileChooser.onValidFn.alert[3]), function(btn){});
+ return false;
+ } else if(selectedNode!=null && selectedNode.isLeaf()) {
+ this.close();
+ this.callBackFn(selectedNode.id, selectedNode.text, selectedNode.attributes.url, selectedNode.attributes.imageHeight, selectedNode.attributes.imageWidth);
+ } else {
+ this.close();
+ var selectedImageRecord = selectedImagRecords[0];
+ this.callBackImageViewerFn(selectedImageRecord.get("id"), selectedImageRecord.get("name"), selectedImageRecord.get("url"), selectedImageRecord.get("height"), selectedImageRecord.get("width"));
+ }
+ },
+
+ callBackDefaultFn: function(idFile) {
+ alert(idFile);
+ },
+
+ refreshInterfaceAddFileJQuery: function(backObj) {
+ if (!backObj.success) {
+ Ext.MessageBox.alert(this.i18n.FileChooser.onValidFn.alert[0], backObj.portal_message, function(btn){});
+ }
+ else {
+ this.close();
+ this.callBackFnJQuery(backObj);
+ }
+ },
+
+ onAfteRenderUploadFormPanel: function(panel){
+ var uploadFileBtnPanel = new EntSavoie.JQueryUploader({
+ actionURLAjax: this.actionURLAjax,
+ filesDropZone: document.getElementById(this.id),
+ uploadCmd: this.uploadCmd || 'addFileEntry',
+ resize: this.resize,
+ supportedExtensions: this.supportedExtensions,
+ singleUpload: true,
+ mainContainer: this
+ });
+
+ this.uploadFormPanel.add(uploadFileBtnPanel);
+ this.uploadFormPanel.doLayout();
+ this.doLayout();
+ },
+
+ onShowFCWindow: function(window){
+ if(this.mainWindow){
+ this.mainWindow.hide();
+ }
+ if(this.allowImageViewer){
+ if(this.currentImageSelectedName != ""){
+ var index = this.storeThumbs.find("name", this.currentImageSelectedName);
+ this.dvThumbs.select(index);
+ } else {
+ this.dvThumbs.select(0);
+ }
+ }
+ },
+
+ onHideFCWindow: function(window){
+ if(this.mainWindow){
+ this.mainWindow.show();
+ }
+ },
+
+ onClickDvThumbs: function(dataView, index, node, e){
+ this.treeElt.getSelectionModel().clearSelections();
+ },
+
+ onDblClickDvThumbs: function(dataView, index, node, e){
+ var selectedImageRecord = this.storeThumbs.getAt(index);
+ this.close();
+ this.callBackImageViewerFn(selectedImageRecord.get("id"), selectedImageRecord.get("name"), selectedImageRecord.get("url"), selectedImageRecord.get("height"), selectedImageRecord.get("width"));
+ }
+
+});