Преглед изворни кода

视图自定义过滤条件添加可选项脚本

unknown пре 5 година
родитељ
комит
86d31f8227

+ 29 - 2
o2web/source/x_component_query_ViewDesigner/$View/view.html

@@ -524,8 +524,14 @@
                     <tr>
                         <td class="editTableTitle"></td>
                         <td class="editTableValue">
-                            <input type="radio" value="restrict" name="text{$.id}viewFilterType" onclick="if (this.checked){ $('text{$.id}viewFilterRestrict').setStyle('display', 'block');}"/>作为默认过滤条件<br>
-                            <input type="radio" value="custom" name="text{$.id}viewFilterType" onclick="if (this.checked){ $('text{$.id}viewFilterRestrict').setStyle('display', 'none');}" checked/>作为自定义过滤数据
+                            <input type="radio" value="restrict" name="text{$.id}viewFilterType" onclick="if (this.checked){
+                                $('text{$.id}viewFilterRestrict').setStyle('display', 'block');
+                                $('text{$.id}viewCustomFilterRestrict').setStyle('display', 'none');
+                            }"/>作为默认过滤条件<br>
+                            <input type="radio" value="custom" name="text{$.id}viewFilterType" onclick="if (this.checked){
+                                $('text{$.id}viewFilterRestrict').setStyle('display', 'none');
+                                $('text{$.id}viewCustomFilterRestrict').setStyle('display', 'block');
+                            }" checked/>作为自定义过滤数据
                         </td>
                     </tr>
                 </table>
@@ -693,6 +699,27 @@
                     </div>
 
                 </div>
+                <div id="text{$.id}viewCustomFilterRestrict"  style="display: block">
+                    <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">
+                        <tr>
+                            <td class="editTableTitle">值:</td>
+                            <td class="editTableValue">
+                                <input class="editTableRadio" onclick="
+                                if (this.checked){
+                                    $('text{$.id}viewCustomFilterValueScriptDiv').setStyle('display', 'none');
+                                }" name="viewCustomFilterValueType" checked type="radio" value="input"/>输入
+                                <input class="editTableRadio" onclick="
+                                if (this.checked){
+                                    $('text{$.id}viewCustomFilterValueScriptDiv').setStyle('display', 'block');
+                                }" name="viewCustomFilterValueType" type="radio" value="script"/>可选
+                            </td>
+                        </tr>
+                    </table>
+                    <div style="display:none" id="text{$.id}viewCustomFilterValueScriptDiv">
+                        <div style="padding: 5px">return ["选项文本|选项值"]</div>
+                        <div name="text{$.id}viewCustomFilterValueScript" title="选项脚本"></div>
+                    </div>
+                </div>
             </div>
             <div></div>
             <div style="height: 20px; line-height: 20px; text-align:center; background-color: #eeeeee">默认过滤条件</div>

+ 86 - 11
o2web/source/x_component_query_ViewDesigner/widget/ViewFilter.js

@@ -65,6 +65,27 @@ MWF.xApplication.query.ViewDesigner.widget.ViewFilter = new Class({
             this.scriptArea.load(v);
         }.bind(this));
     },
+    createCustomFilterValueScriptArea : function(node){
+        var title = node.get("title");
+
+        MWF.require("MWF.widget.ScriptArea", function(){
+            this.customFilterValueScriptArea = new MWF.widget.ScriptArea(node, {
+                "title": title,
+                "isload" : true,
+                "isbind" : false,
+                "maxObj": this.app.formContentNode || this.app.pageContentNode,
+                "onChange": function(){
+                    this.customFilterValueScriptData = this.customFilterValueScriptArea.toJson();
+                }.bind(this),
+                "onSave": function(){
+                    //this.app.saveForm();
+                }.bind(this),
+                "style": "formula"
+            });
+            var v = (this.customFilterValueScriptData) ? this.customFilterValueScriptData.code : "";
+            this.customFilterValueScriptArea.load(v);
+        }.bind(this));
+    },
     getInputNodes: function(){
         this.inputAreaNode = this.node.getFirst("div");
         this.actionAreaNode = this.inputAreaNode.getNext().setStyles(this.css.actionAreaNode);
@@ -95,6 +116,16 @@ MWF.xApplication.query.ViewDesigner.widget.ViewFilter = new Class({
         this.valueDateInput = inputs[7];
         this.valueTimeInput = inputs[8];
 
+        debugger;
+        var dataId = this.app.view.data.id;
+        this.customFilterValueTypes = this.inputAreaNode.getElements("[name='"+dataId+"viewCustomFilterValueType']");
+
+        this.customFilterValueScriptDiv = this.inputAreaNode.getElement("#"+dataId+"viewCustomFilterValueScriptDiv");
+        this.customFilterValueScript = this.inputAreaNode.getElement("[name='"+dataId+"viewCustomFilterValueScript']");
+        if( this.customFilterValueScript ){
+            this.createCustomFilterValueScriptArea(this.customFilterValueScript);
+        }
+
         this.datatypeInput.addEvent("change");
 
         MWF.require("MWF.widget.Calendar", function(){
@@ -287,7 +318,7 @@ MWF.xApplication.query.ViewDesigner.widget.ViewFilter = new Class({
             "logic": "and",
             "path": "",
             "title": "",
-            "type": "",
+            "type": this.restrictFilterInput.checked ? "restrict" : "custom",
             "comparison": "equals",
             "formatType": "textValue",
             "value": "",
@@ -445,16 +476,36 @@ MWF.xApplication.query.ViewDesigner.widget.ViewFilter = new Class({
                 }
                 break;
         }
-        return {
-            "logic": logic,
-            "path": path,
-            "title": title,
-            "type": type,
-            "comparison": comparison,
-            "formatType": formatType,
-            "value": value,
-            "otherValue": value2,
-            "code": this.scriptData
+        if( type === "restrict" ){
+            return {
+                "logic": logic,
+                "path": path,
+                "title": title,
+                "type": type,
+                "comparison": comparison,
+                "formatType": formatType,
+                "value": value,
+                "otherValue": value2,
+                "code": this.scriptData
+            };
+        }else{
+            var valueType = "";
+            this.customFilterValueTypes.each( function (radio) {
+                if( radio.get("checked") )valueType = radio.get("value");
+            });
+            return {
+                "logic": logic,
+                "path": path,
+                "title": title,
+                "type": type,
+                "comparison": comparison,
+                "formatType": formatType,
+                "value": value,
+                "otherValue": value2,
+                "code": this.scriptData,
+                "valueType" : valueType,
+                "valueScript" : this.customFilterValueScriptData
+            };
         }
     },
 
@@ -537,6 +588,30 @@ MWF.xApplication.query.ViewDesigner.widget.ViewFilter = new Class({
         }
         this.scriptData = data.code;
         if (this.scriptArea && this.scriptArea.editor) this.scriptArea.editor.setValue(this.scriptData.code);
+
+        debugger;
+        if( data.type === "custom" ){
+            this.customFilterValueTypes.each( function (radio) {
+                if( data.valueType ){
+                    if( data.valueType === radio.get("value") )radio.set("checked", true);
+                }else{
+                    if( "input" === radio.get("value") )radio.set("checked", true);
+                }
+            });
+            if ( this.customFilterValueScriptArea ){
+                if( !data.valueType || data.valueType === "input" ){
+                    this.customFilterValueScriptDiv.hide();
+                    this.customFilterValueScriptData = "";
+                    this.customFilterValueScriptArea.editor.setValue( "" );
+                }else{
+                    this.customFilterValueScriptDiv.show();
+                    this.customFilterValueScriptData = data.valueScript;
+                    this.customFilterValueScriptArea.editor.setValue( data.valueScript ? data.valueScript.code : "" );
+                }
+            }
+        }
+
+
         this.changeValueInput();
         if(this.datatypeInput.onchange){
             this.datatypeInput.onchange();