﻿/** NewsModule */
Ext.namespace('V12.Cms.Modules.Files');


V12.Cms.Modules.Files = Ext.extend(V12.Cms.Module, {
    commands: [{
        groupName: V12.tr('Files'),
        commandName: V12.tr('Bestanden'),

        groupIcon: "silk-cog",
        iconClass: "silk-link-edit",
        commandFunction: function() {

            var core = V12.Cms.Modules.Core;
            var dialog = null, gridStore;
            function onUploadSuccess() {
                log.info("Upload success");
                if (gridStore && gridStore != null) {
                    gridStore.load();
                    log.debug("Reload store");
                }
            }
            function showDialog() {
                if (dialog == null) {
                    var grid = new V12.Cms.FlashUploader.UploadGrid({
region: 'center',
uploadHandler: V12.Cms.Context.cmsUrl + 'CustomModules/Files/FileUploadHandler.ashx',
fileFilter: "Bestanden,*.png; *.jpg; *.pdf; *.doc; *.docx; *.odf; *.ppt; *.pptx"
                });
                dialog = new Ext.Window({
                title: V12.tr('Upload'),
                modal: true,
                width: 400, height: 300,
                    layout:'border',
                    items: [ grid]
                });
/*
                //alert("Gewenste afbeelding verhouding voor slideshow en overige pagina's is 3:2. Voor de pagina's kan ook vierkante foto's gebruik worden.");
                dialog = new Ext.ux.UploadDialog.Dialog({  //!!           
                    itemId: "dialog",
                    url: V12.Cms.Context.cmsUrl + 'CustomModules/Files/FileUploadHandler.ashx',
                    post_var_name: 'file',
                    permitted_extentions: ['png', 'jpg', 'pdf', 'doc', 'docx', 'odf', 'ppt', 'pptx'],
                    reset_on_hide: true,
                    allow_close_on_upload: true,
                    upload_autostart: false
                });
                dialog.on('uploadcanceled', function() {
                    log.warn("Upload aborted");
                });
                dialog.on('uploadsuccess', onUploadSuccess);
                */
            }
            dialog.show();
        }

        var rightPanel = new Ext.Panel({
            layout: 'fit',
            region: 'center'
        });

        var gridPanel = new V12.Cms.Grid.RichGrid({
            handler: V12.Cms.Context.cmsUrl + 'CustomModules/Files/FileHandler.ashx',
            title: V12.tr('Files'),
            region: 'west',
            width: 500,
            layout: 'fit',
            split: true,
            defaultTopbar: true,
            defaultRecord: {
            //newsItemTitle: 'TITEL'
        },
        onAdd: function(btn, ev) {
            gridStore = this.store;
            var u = new this.store.recordType();
            if (this.store.defaultRecord != null)
                u = new this.store.recordType(this.store.defaultRecord);
            showDialog(this.store);
            //this.stopEditing();
            //this.store.insert(0, u);
            //this.startEditing(0, 1);
        },
        listeners: {
            destroy: function() {
                gridStore = null;
                if (dialog) dialog.hide();
            }
        }
    });
    var mainPanel = new Ext.Panel({
        layout: 'border',
        items: [
                    gridPanel,
                    rightPanel
                    ]
    });
    rightPanel.add({
        html: "<p style=\"font-family:arial; font-size:12px;\"><br/><b>&nbsp;Afbeeldingen</b><br />&nbsp;De gewenste afbeelding verhouding voor slideshow is 3:2<br />&nbsp;De gewenste rechthoekige afbeelding verhouding is ook 3:2<br />&nbsp;De gewenste vierkante afbeelding verhouding is ook 1:1</p>"
    });





    core.requestSwitchPanel(mainPanel);
}
}]
});




