Source: widgets/SpwContextChooser.js

Retour à la documentation
/**
 * @class spw.widgets.SpwContextChooser
 */
define(
[
    "dojo/_base/declare",
    "dojo/text!./templates/SpwContextChooser.html",
    "dojo/i18n!./nls/SpwContextChooser",
    "dojo/_base/lang",
    "dojo/dom-construct",
    "dojo/on",

    "spw/api/SpwBaseTemplatedWidget",
    "spw/api/ConfigLoader",
    "spw/api/Utils",
    "spw/api/ContextManager",

    "dijit/layout/ContentPane"
],
function(declare, template, labels, lang, domConstruct, on,
         SpwBaseTemplatedWidget, ConfigLoader, Utils, ContextManager) {

    return declare("spw.widgets.SpwContextChooser", [SpwBaseTemplatedWidget], /** @lends spw.widgets.SpwContextChooser.prototype */ {

        templateString: template,
        labels: labels,

        tabViewerContexts: null,
        tabAppContexts: null,

        acceptedContexts: null,
        rejectedContexts: null,

        widgetTitle: "Contextes",
        // helpContent: "http://geoportail.wallonie.be/aideWalOnMap",
        iconClass: "contextsIcon",
        style: {
            width: "350px"
        },

        constructor: function() {
            this.inherited(arguments);
        },

        postCreate: function() {
            this.inherited(arguments);

            this.descriptionNode.innerHTML = labels.description;

            var contextes = ConfigLoader.getInstance().get('context');

            for (var i = 0; i < contextes.length; ++i)
            {
                if(this.isContextAllowed(contextes[i].name)) {
                    this.processContextConfig(contextes[i]);
                }
            }
        },

        onDeactivate: function() {
            this.inherited(arguments);
        },

        onActivate: function() {
            this.inherited(arguments);
        },

        isContextAllowed: function(contextCode) {
            if(this.acceptedContexts){
                return this.acceptedContexts.indexOf(contextCode) > -1;
            } else if(this.rejectedContexts && this.rejectedContexts.indexOf(contextCode) > -1){
                return false;
            }
            return true;
        },

        processContextConfig : function(context) {

            if (context.url || context.contexts || context.separator) {
                return;
            }

            var tr = domConstruct.create('tr', null, this.tbodyNode);

            this.own(
                    on(tr, 'click', lang.hitch(this, this.selectContextViewer, context))
            );

            var tdImg = domConstruct.create('td', {
                style: 'vertical-align: top; width: 50px;'
            }, tr);

            var pImage = domConstruct.create('p', {
                style: 'width: 50px; height: 50px; margin: 0;',
                'class': context.iconClass
            }, tdImg);

            var tdContent = domConstruct.create('td', {
                style: 'vertical-align: top;',
                'class': ConfigLoader.getInstance().currentContext === context.name ? 'checked' : null
            }, tr);

            var pTitle = domConstruct.create('p', {
                style: 'margin: 0;',
                innerHTML: '<b style="text-shadow: 1px 0px; font-size: 14px;">' + context.label + '</b>'
            });

            var pDesc = domConstruct.create('p', {
                style: 'margin: 0; font-size: 0.9em;',
                innerHTML: context.description
            });

            domConstruct.place(pTitle, tdContent, 'first');
            domConstruct.place(pDesc, tdContent, 'last');
        },

        selectContextViewer:function(context){
            this.applyContext(context);
        },

        applyContext:function(context){
            ContextManager.getInstance().changeContext(context.name);
        },
        
        destroy: function(){
        	if(this.domNode && this.getParent()){
        		dijit.popup.close(this.getParent());
        	}
        	this.inherited(arguments);
        }
    });

});