Main.js 10.2 KB
Newer Older
R
roo00 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
MWF.xApplication.query.Query.options.multitask = true;
MWF.xApplication.query.Query.Main = new Class({
	Extends: MWF.xApplication.Common.Main,
	Implements: [Options, Events],

	options: {
		"style": "default",
		"name": "query.Query",
		"icon": "icon.png",
		"width": "1200",
		"height": "700",
		"title": MWF.xApplication.query.Query.LP.title,
        "isControl": false,
        "taskObject": null,
        "parameters": "",
        "readonly": false
	},
	onQueryLoad: function(){
		this.lp = MWF.xApplication.query.Query.LP;
        if (this.status){
            this.options.id = this.status.id;
            this.options.viewId = this.status.viewId;
            this.options.statId = this.status.statId;
        }
	},
    loadApplication: function(callback){
        this.content.setStyle("background-color", "#ffffff");
        this.node = new Element("div", {"styles": this.css.content}).inject(this.content);
        this.formNode = new Element("div", {"styles": {"min-height": "100%", "font-size": "14px"}}).inject(this.node);
        this.action = MWF.Actions.get("x_query_assemble_surface");
        // if (!this.options.isRefresh){
        //     this.maxSize(function(){
        //         this.loadQuery(this.options.parameters);
        //     }.bind(this));
        // }else{
             this.loadQuery(this.options.parameters);
        // }
        if (callback) callback();
    },

    loadQuery: function(par){
        this.action.getQuery(this.options.id, function(json){
            this.query = json.data;
            this.setTitle(this.query.name);

            if (this.query.icon){
                if (this.taskitem){
                    this.taskitem.iconNode.setStyles({
                        "background-image": "url(data:image/png;base64,"+this.query.icon+")",
                        "background-size": "24px 24px"
                    });
                }
            }
            this.createLayout();
            this.createNavi();

            this.addEvent("resize", function(){
                if (this.currentItem){
                    if (this.currentItem.viewer){
                        this.currentItem.viewer.setContentHeight();
                    }
                }
            }.bind(this));
        }.bind(this));
    },
    createLayout: function(){
        if (!layout.mobile){
            this.createLayoutPC();
        }else{
            this.createLayoutMobile();
        }
    },
    createLayoutPC: function(){
        this.naviNode = new Element("div", {"styles": this.css.naviNode}).inject(this.content);
        this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.content);
        this.naviTitleNode = new Element("div", {"styles": this.css.naviTitleNode}).inject(this.naviNode);
        this.naviContentNode = new Element("div", {"styles": this.css.naviContentNode}).inject(this.naviNode);
        this.naviViewTitleNode = new Element("div", {"styles": this.css.naviViewTitleNode, "text": this.lp.view}).inject(this.naviContentNode);
        this.naviViewContentNode = new Element("div", {"styles": this.css.naviViewContentNode}).inject(this.naviContentNode);
        this.naviStatTitleNode = new Element("div", {"styles": this.css.naviStatTitleNode, "text": this.lp.stat}).inject(this.naviContentNode);
        this.naviStatContentNode = new Element("div", {"styles": this.css.naviStatContentNode}).inject(this.naviContentNode);
U
unknown 已提交
82

U
unknown 已提交
83
        this.naviStatementTitleNode = new Element("div", {"styles": this.css.naviStatementTitleNode, "text": this.lp.statement}).inject(this.naviContentNode);
U
unknown 已提交
84 85
        this.naviStatementContentNode = new Element("div", {"styles": this.css.naviStatementContentNode}).inject(this.naviContentNode);

R
roo00 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
        this.setContentHeightFun = this.setContentHeight.bind(this);
        this.addEvent("resize", this.setContentHeightFun);
        this.setContentHeightFun();

        this.naviIconTitleNode = new Element("div", {"styles": this.css.naviIconTitleNode}).inject(this.naviTitleNode);
        if (this.query.icon){
            this.naviIconTitleNode.setStyles({
                "background-image": "url(data:image/png;base64,"+this.query.icon+")",
            });
        }

        this.naviRightTitleNode = new Element("div", {"styles": this.css.naviRightTitleNode}).inject(this.naviTitleNode);
        this.naviTextTitleNode = new Element("div", {"styles": this.css.naviTextTitleNode, "text": this.query.name}).inject(this.naviRightTitleNode);
        this.naviDescriptionTitleNode = new Element("div", {"styles": this.css.naviDescriptionTitleNode, "text": this.query.description || this.lp.noDescription}).inject(this.naviRightTitleNode);
    },
    createLayoutMobile: function(){},

    setContentHeight: function(){
        var size = this.content.getSize();
        var titleSize = this.naviTitleNode.getSize();
        var y = size.y-titleSize.y;
        this.naviContentNode.setStyle("height", ""+y+"px");
    },

    createNavi: function(){
        this.action.listView(this.options.id, function(json){
            if (json.data){
                json.data.each(function(view){
R
roo00 已提交
114
                    if(view.display) {
NoSubject's avatar
NoSubject 已提交
115 116 117 118
                        var item = this.createViewNaviItem(view);
                        if( view.id === this.options.viewId ){
                            item.selected()
                        }
R
roo00 已提交
119
                    }
R
roo00 已提交
120 121 122
                }.bind(this));
            }
        }.bind(this));
NoSubject's avatar
NoSubject 已提交
123
        MWF.Actions.get("x_query_assemble_surface").listStat(this.options.id, function(json){
R
roo00 已提交
124 125 126
        //this.action.listStat(this.options.id, function(json){
            if (json.data){
                json.data.each(function(stat){
NoSubject's avatar
NoSubject 已提交
127 128 129 130
                    var item = this.createStatNaviItem(stat);
                    if( stat.id === this.options.statId ){
                        item.selected()
                    }
R
roo00 已提交
131 132 133
                }.bind(this));
            }
        }.bind(this));
U
unknown 已提交
134 135 136 137
        MWF.Actions.load("x_query_assemble_surface").StatementAction.listWithQuery(this.options.id, {
            "justSelect" : true,
            "hasView" : true
        }, function(json){
U
unknown 已提交
138 139 140 141 142 143 144 145 146 147 148
            //this.action.listStat(this.options.id, function(json){
            if (json.data){
                json.data.each(function(statement){
                    debugger;
                    var item = this.createStatementNaviItem(statement);
                    if( statement.id === this.options.statementId ){
                        item.selected()
                    }
                }.bind(this));
            }
        }.bind(this));
R
roo00 已提交
149 150 151
    },
    createViewNaviItem: function(view){
        var item = new MWF.xApplication.query.Query.ViewItem(view, this);
NoSubject's avatar
NoSubject 已提交
152
        return item;
R
roo00 已提交
153 154 155
    },
    createStatNaviItem: function(stat){
        var item = new MWF.xApplication.query.Query.StatItem(stat, this);
NoSubject's avatar
NoSubject 已提交
156
        return item;
R
roo00 已提交
157
    },
U
unknown 已提交
158 159
    createStatementNaviItem: function(statement){
        var item = new MWF.xApplication.query.Query.StatementItem(statement, this);
U
unknown 已提交
160 161
        return item;
    },
R
roo00 已提交
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212


    recordStatus: function(){
        return {"id": this.options.id};
    }

});

MWF.xApplication.query.Query.ViewItem = new Class({
    initialize: function(view, app){
        this.view = view;
        this.app = app;
        this.css = this.app.css;
        this.lp = this.app.lp;
        this.isSelected = false;
        this.content = this.getContentNode();
        this.viewContent = this.getViewContentNode();
        this.load();
    },
    getContentNode: function(){
        return this.app.naviViewContentNode;
    },
    getViewContentNode: function(){
        return this.app.contentNode;
    },
    load: function(){
        this.node = new Element("div", {
            "styles": this.css.naviViewContentItemNode,
            "text": this.view.name,
            "title": this.view.name
        }).inject(this.content);

        this.node.addEvents({
            "mouseover": function(){if (!this.isSelected) this.node.setStyles(this.css.naviViewContentItemNode_over); }.bind(this),
            "mouseout": function(){if (!this.isSelected) this.node.setStyles(this.css.naviViewContentItemNode); }.bind(this),
            "click": function(){this.selected();}.bind(this)
        });
    },
    selected: function(){
        if (this.app.currentItem) this.app.currentItem.unselected();
        this.node.setStyles(this.css.naviViewContentItemNode_selected);
        this.app.currentItem = this;
        this.isSelected = true;
        this.loadView();
    },
    unselected: function(){
        this.node.setStyles(this.css.naviViewContentItemNode);
        this.app.currentItem = null;
        this.isSelected = false;
    },
    loadView: function(){
NoSubject's avatar
NoSubject 已提交
213
        debugger;
R
roo00 已提交
214 215
        MWF.xDesktop.requireApp("query.Query", "Viewer",function(){
            this.viewContent.empty();
NoSubject's avatar
NoSubject 已提交
216
            var data = JSON.parse(this.view.data);
R
roo00 已提交
217 218
            this.viewer = new MWF.QViewer(this.viewContent, {
                "application": this.view.query,
NoSubject's avatar
NoSubject 已提交
219 220
                "viewName": this.view.name,
                "isExpand": data.isExpand
U
unknown 已提交
221
            }, {"export": true}, this.app);
R
roo00 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
        }.bind(this));
    }

});


MWF.xApplication.query.Query.StatItem = new Class({
    Extends: MWF.xApplication.query.Query.ViewItem,
    getContentNode: function(){
        return this.app.naviStatContentNode;
    },
    loadView: function(){
        MWF.xDesktop.requireApp("query.Query", "Statistician",function(){
            this.viewContent.empty();
            this.viewer = new MWF.QStatistician(this.app, this.viewContent, {
                "application": this.view.query,
                "statName": this.view.name,
                "isTable": true,
                "isChart": true,
                "isLegend": true
            });
        }.bind(this));
    }
U
unknown 已提交
245 246 247 248 249 250 251 252 253 254
});

MWF.xApplication.query.Query.StatementItem = new Class({
    Extends: MWF.xApplication.query.Query.ViewItem,
    getContentNode: function(){
        return this.app.naviStatementContentNode;
    },
    loadView: function(){
        MWF.xDesktop.requireApp("query.Query", "Statement",function(){
            this.viewContent.empty();
U
unknown 已提交
255 256
            debugger;
            this.viewer = new MWF.QStatement( this.viewContent, {
U
unknown 已提交
257
                "application": this.view.query,
U
unknown 已提交
258 259
                "statementName": this.view.name,
                "statementId" : this.view.id
U
unknown 已提交
260
            },{}, this.app);
U
unknown 已提交
261 262
        }.bind(this));
    }
R
roo00 已提交
263
});