﻿/** NewsModule */

Ext.namespace('V12.Cms.Modules.News');


V12.Cms.Modules.News = Ext.extend(V12.Cms.Module, {
    commands: [{
        groupName: V12.tr('News'),
        commandName: V12.tr('Nieuwsberichten'),

        groupIcon: "silk-cog",
        iconClass: "silk-link-edit",
        commandFunction: function() {
            var core = V12.Cms.Modules.Core;

            V12.Cms.Ui.Editor.ImageChooserOptions = {
                documentTypes: {
                    folders: [1],
                    images: [2]
                },
                treehandler: V12.Cms.Context.cmsUrl + 'CustomModules/Files/TinyMceTreeHandler.ashx',
                gridhandler: V12.Cms.Context.cmsUrl + 'CustomModules/Files/TinyMceTreeHandler.ashx',
                getThumbUrl: function(documentId, documentName, siteRoot) {
                    return siteRoot + 'documents/getFile.ashx?type=image&thumb=1&id=' + documentId;
                },
                getWebUrl: function(documentId, documentName, siteRoot) {
                    return siteRoot + 'documents/getFile.ashx?type=image&id=' + documentId;
                    //return siteRoot + 'documents/web/' + documentId + '/' + escape(documentName) + '.aspx';
                }
            };

            V12.Cms.Ui.Editor.FileChooserOptions = {
                documentTypes: {
                    folders: [1],
                    images: [1]
                },
                treehandler: V12.Cms.Context.cmsUrl + 'CustomModules/Files/TinyMceTreeHandler.ashx',
                gridhandler: V12.Cms.Context.cmsUrl + 'CustomModules/Files/TinyMceTreeHandler.ashx',
                getWebUrl: function(documentId, documentName, siteRoot) {
                    return siteRoot + 'documents/getFile.ashx?type=download&id=' + documentId;
                    //return siteRoot + 'documents/web/' + documentId + '/' + escape(documentName) + '.aspx';
                }
            };

            if (!V12.Cms.Modules.News.externalJsLoaded) {
                V12.Cms.Modules.News.externalJsLoaded = true;
                $.ajaxSetup({ async: false });
                $.getScript(V12.Cms.Context.cmsUrl + '../cms-hack/TinyMceFileBrowser.js');
                $.ajaxSetup({ async: true });
            }

            var rightPanel = new Ext.Panel({
                layout: 'fit',
                region: 'center'
            });
            function setRightPanel(form1) {
                rightPanel.removeAll();
                if (form1) {
                    rightPanel.add(form1);
                } 
                rightPanel.doLayout();
            }

            var newsGrid = new V12.Cms.Grid.RichGrid({
                handler: V12.Cms.Context.cmsUrl + 'CustomModules/News/NewsHandler.ashx',
                preferenceName: 'NewsModule',
                layout: 'fit',
                split: true,
                title: V12.tr('Nieuws'),
                //indexProperty: 'newsIndex',
                region: 'west',
                width: 400,
                listeners: {
                    rowclick: function(g, index, ev) {
                        currRecord = g.store.getAt(index);
                        var updateForm = new V12.Cms.Form.AutoForm({
                            title: 'Update bericht ' + currRecord.data.newsItemTitle,
                            formType: 'update',
                            buildForm: function() {
                            return [
                                {
                                    text: 'Intro',
                                    xtype: 'label'
                                },
                                 new Ext.ux.TinyMCE({
                                                    fieldLabel: "Rich text",
                                                    itemId: "richSummaryText",

                                                    hideLabel: true,
                                                    fieldLabel: 'Summary',
                                                    name: 'newsItemSummaryText',
                                                    autoWidth: true,
                                                    height: 230,
                                                    tinymceSettings: {
                                                        //handle_event_callback: onChangeCallback,
                                                        theme: "advanced",
                                                        plugins: "safari,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
                                                        theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontsizeselect",
                                                        theme_advanced_buttons2: "pastetext,pasteword,|,bullist,numlist,undo,redo,|,link,unlink,anchor,image,cleanup,code,forecolor,hr,removeformat,|,sub,sup,|,charmap",
                                                        theme_advanced_buttons3: "",
                                                        theme_advanced_buttons4: "",
                                                        theme_advanced_toolbar_location: "top",
                                                        theme_advanced_toolbar_align: "left",
                                                        theme_advanced_statusbar_location: "bottom",
                                                        theme_advanced_resizing: false,
                                                        //extended_valid_elements: "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
                                                        //template_external_list_url: "example_template_list.js",
                                                        relative_urls: false, // Default value
                                                        document_base_url: V12.Cms.Context.TinyMceBaseUrl,
                                                        file_browser_callback: 'V12.Cms.Ui.Editor.FileBrowser'

                                                    }
                                                }),

                                {
                                    text: 'Bericht',
                                    xtype: 'label'
                                },
                                                new Ext.ux.TinyMCE({
                                                    fieldLabel: "Rich text",
                                                    itemId: "richText",
                                                    hideLabel: true,
                                                    fieldLabel: 'Content',
                                                    name: 'newsItemContent',
                                                    autoWidth: true,
                                                    height: 430,
                                                    tinymceSettings: {
                                                        //handle_event_callback: onChangeCallback,
                                                        theme: "advanced",
                                                        plugins: "safari,pagebreak,style,layer,table,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
                                                        theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontsizeselect",
                                                        theme_advanced_buttons2: "pastetext,pasteword,|,bullist,numlist,undo,redo,|,link,unlink,anchor,image,cleanup,code,forecolor,hr,removeformat,|,sub,sup,|,charmap",
                                                        theme_advanced_buttons3: "",
                                                        theme_advanced_buttons4: "",
                                                        theme_advanced_toolbar_location: "top",
                                                        theme_advanced_toolbar_align: "left",
                                                        theme_advanced_statusbar_location: "bottom",
                                                        theme_advanced_resizing: false,
                                                        //extended_valid_elements: "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
                                                        //template_external_list_url: "example_template_list.js",
                                                        relative_urls: false, // Default value
                                                        document_base_url: V12.Cms.Context.TinyMceBaseUrl,
                                                        file_browser_callback: 'V12.Cms.Ui.Editor.FileBrowser'

                                                    }
                                                })
                                            ];
                            }
                        });

                        
                        setRightPanel(updateForm);
                        updateForm.loadRecord(currRecord); 
                    }
                }
            });


            var panel = {
                xtype: 'panel',
                layout: 'border',
                items: [newsGrid, rightPanel]
            };

            core.requestSwitchPanel(panel);
        }
    }
    ]
});

