123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- MWF.xApplication.portal.PageDesigner.Module.Widgetmodules = MWF.PCWidgetmodules = new Class({
- Extends: MWF.FC$Module,
- Implements: [Options, Events],
- options: {
- "style": "default"
- //"propertyPath": "../x_component_portal_PageDesigner/Module/Radio/radio.html"
- },
- initialize: function(form, options){
- this.setOptions(options);
- this.path = "../x_component_portal_PageDesigner/Module/Widgetmodules/";
- this.cssPath = "../x_component_portal_PageDesigner/Module/Widgetmodules/"+this.options.style+"/css.wcss";
- this._loadCss();
- //this.moduleType = "element";
- //this.moduleName = "radio";
- this.form = form;
- this.page = form;
- this.container = null;
- this.containerNode = null;
- },
- _createMoveNode: function(){
- this.moveNode = new Element("div", {
- "styles": this.css.moduleNodeMove,
- "events": {
- "selectstart": function(){
- return false;
- }
- }
- }).inject(this.form.container);
- },
- _createNode: function(relativeNode, position){
- var module = this;
- var url = this.path+"widgetSelect.html";
- MWF.require("MWF.widget.Dialog", function(){
- var size = $(document.body).getSize();
- var x = size.x/2-180;
- var y = size.y/2-100;
- var dlg = new MWF.DL({
- "title": "Insert",
- "style": "property",
- "top": y,
- "left": x-40,
- "fromTop":size.y/2-65,
- "fromLeft": size.x/2,
- "width": 360,
- "height": 200,
- "url": url,
- "lp": MWF.xApplication.process.FormDesigner.LP.propertyTemplate,
- "buttonList": [
- {
- "text": MWF.APPFD.LP.button.ok,
- "action": function(){
- var widgetid = module.widgetSelect.options[module.widgetSelect.selectedIndex].value;
- if( !widgetid || widgetid==="none" ){
- module.page.designer.notice(module.page.designer.lp.notice.selectWidget, "error");
- return;
- }
- var wrapDiv = "yes";
- dlg.node.getElements(".wrapDiv").each( function (el) {
- if( el.get("checked") )wrapDiv = el.get("value");
- });
- module.appendWidgetModules( widgetid, relativeNode, position, wrapDiv );
- this.close();
- }
- },
- {
- "text": MWF.APPFD.LP.button.cancel,
- "action": function(){
- module._clearDragComplete();
- this.close();
- }
- }
- ],
- "onPostShow": function(){
- o2.Actions.load("x_portal_assemble_designer").PortalAction.list(function (json) {
- var td = dlg.node.getElementById("MWFPortalSelectTd");
- var select = module.appSelect = new Element("select").inject(td);
- var option = new Element("option", {"text": ""}).inject(select);
- json.data.each(function(app){
- var option = new Element("option", {
- "text": app.name,
- "value": app.id
- }).inject(select);
- }.bind(this));
- select.addEvent("change", function(){
- var appid = module.appSelect.options[module.appSelect.selectedIndex].value;
- module.setWidgetSelectOptions( appid );
- })
- });
- var td = dlg.node.getElementById("MWFWidgetSelectTd");
- module.widgetSelect = new Element("select").inject(td);
- module.setWidgetSelectOptions();
- }.bind(this)
- });
- dlg.show();
- }.bind(this));
- },
- setWidgetSelectOptions: function( aplication ){
- var select = this.widgetSelect;
- select.empty();
- this.form.designer.actions.listWidget( aplication || this.form.designer.application.id, function(json){
- var option = new Element("option", {"text": "none"}).inject(select);
- json.data.each(function(widget){
- var option = new Element("option", {
- "text": widget.name,
- "value": widget.id
- }).inject(select);
- }.bind(this));
- }.bind(this));
- },
- _dragComplete: function(relativeNode, position){
- if (!this.node){
- this._createNode(relativeNode, position );
- }else{
- this._clearDragComplete();
- }
- },
- //_dragMoveComplete: function( relativeNode, position ){
- // //this.setStyleTemplate();
- //
- // if( this.injectNoticeNode )this.injectNoticeNode.destroy();
- // //var overflow = this.moveNode.retrieve("overflow");
- // //if( overflow ){
- // // this.moveNode.setStyle("overflow",overflow);
- // // this.moveNode.eliminate("overflow");
- // //}
- //
- // //if (!this.node){
- // // this._createNode();
- // //}
- // //this._resetTreeNode();
- //
- // //if( relativeNode && position ){
- // // this.node.inject( relativeNode, position );
- // //}else{
- // // this.node.inject(this.copyNode, "before");
- // //}
- //
- // //this._initModule();
- //
- // //var thisDisplay = this.node.retrieve("thisDisplay");
- // //if (thisDisplay){
- // // this.node.setStyle("display", thisDisplay);
- // //}
- //
- // this._clearDragComplete();
- //
- // //this.form.json.moduleList[this.json.id] = this.json;
- // //if (this.form.scriptDesigner) this.form.scriptDesigner.createModuleScript(this.json);
- //
- // //this.selected();
- //},
- _clearDragComplete : function(){
- if( this.injectNoticeNode )this.injectNoticeNode.destroy();
- if (this.copyNode) this.copyNode.destroy();
- if (this.moveNode) this.moveNode.destroy();
- this.moveNode = null;
- this.copyNode = null;
- this.nextModule = null;
- this.form.moveModule = null;
- delete this;
- },
- appendWidgetModules: function( widgetid, relativeNode, position, wrapDiv ){
- MWF.Actions.get("x_portal_assemble_designer").getWidget(widgetid, function(json){
- var parentModule = this.parentContainer || this.inContainer || this.onDragModule;
- this.containerModule = this.page.createModuleImmediately("Div", parentModule, relativeNode || this.copyNode, position || "before", false, false);
- this.node = this.containerModule.node;
- var data = this.getWidgetData( json.data );
- var moduleList = this.page.json.moduleList;
- var tmpNode = new Element("div").inject( this.page.container );
- tmpNode.set("html", data.html);
- var html = tmpNode.getFirst().get("html");
- tmpNode.destroy();
- this.node.set("html", html );
- Object.each(data.json.moduleList, function (moduleJson) {
- var oid = moduleJson.id;
- var id = moduleJson.id;
- var idx = 1;
- while (this.page.json.moduleList[id]) {
- id = oid + "_" + idx;
- idx++;
- }
- if (oid != id) {
- moduleJson.id = id;
- var moduleNode = this.node.getElementById(oid);
- if (moduleNode) moduleNode.set("id", id);
- }
- this.page.json.moduleList[moduleJson.id] = moduleJson;
- }.bind(this));
- if( wrapDiv === "no" ){
- this.node.getChildren().each( function (el) {
- if( el.get("MWFType") && el.get("id")){
- var id = el.get("id");
- el.inject( relativeNode || this.copyNode, position || "before" );
- }
- }.bind(this));
- this.page.parseModules( parentModule, parentModule.node);
- //this.containerModule.delete();
- this.page.selected();
- this.containerModule.destroy();
- }else{
- this.page.parseModules(this.containerModule, this.node);
- }
- //var copyModuleNode = this.node.getFirst();
- //while (copyModuleNode) {
- // //copyModuleNode.inject(injectNode, where);
- // var copyModuleJson = this.page.getDomjson(copyModuleNode);
- // var module = this.page.loadModule(copyModuleJson, copyModuleNode, this.containerModule);
- // module._setEditStyle_custom("id");
- // module.selected();
- // //loadModule: function(json, dom, parent)
- //
- // copyModuleNode = copyModuleNode.getNext();
- //}
- this._clearDragComplete();
- //this.setCustomStyles();
- //this.node.setProperties(this.json.properties);
- //this.setNodeEvents();
- //if (this.options.mode==="Mobile"){
- // if (oldStyleValue) this._setEditStyle("pageStyleType", null, oldStyleValue);
- //}
- }.bind(this), null, false);
- },
- getWidgetData: function(data){
- var widgetDataStr = null;
- if (this.page.options.mode !== "Mobile"){
- widgetDataStr = data.data;
- }else{
- widgetDataStr = data.mobileData;
- }
- var d = null;
- if (widgetDataStr){
- d = JSON.decode(MWF.decodeJsonString(widgetDataStr));
- d.updateTime = data.updateTime;
- }
- return d;
- }
- });
|