unknown 5 лет назад
Родитель
Сommit
67e17e8e71

+ 1 - 1
o2web/source/x_component_query_StatementDesigner/$Statement/statementDesigner.html

@@ -11,7 +11,7 @@
             <select>
                 <option value="official" {{if $.data.entityCategory!=='dynamic' && $.data.entityCategory!=='custom'}} selected {{end if}}>系统表</option>
                 <option value="dynamic" {{if $.data.entityCategory=='dynamic'}} selected {{end if}}>自建数据表</option>
-                <option value="custom" {{if $.data.entityCategory=='custom'}} selected {{end if}}>自定义应用</option>
+<!--                <option value="custom" {{if $.data.entityCategory=='custom'}} selected {{end if}}>自定义应用</option>-->
             </select>
         </div>
     </div>

+ 17 - 0
o2web/source/x_component_query_StatementDesigner/$Statement/view.html

@@ -100,10 +100,23 @@
         <div class="MWFViewFilter">
             <div class="inputAreaNode_vf">
                 <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable restrictViewFilterTable_vf">
+                    <tr id="text{$.id}pathInputSelectTr">
+                        <td class="editTableTitle">选择:</td>
+                        <td class="editTableValue">
+                            <select class="pathInputSelect_vf"></select>
+                            <!--                            <div style="line-height: 20px;color:#999;">注:选择路径后,需在选择的值前面加上"表别名.",如:o.</div>-->
+                        </td>
+                    </tr>
                     <tr>
                         <td class="editTableTitle">标题:</td>
                         <td class="editTableValue"><input type="text" class="editTableInput titleInput_vf"/></td>
                     </tr>
+                    <tr id="text{$.id}parameterInputSelectTr" style="display: none">
+                        <td class="editTableTitle">选择参数:</td>
+                        <td class="editTableValue">
+                            <select class="parameterInputSelect_vf"></select>
+                        </td>
+                    </tr>
                     <tr id="text{$.id}parameterInputTr" style="display: none">
                         <td class="editTableTitle">参数:</td>
                         <td class="editTableValue">
@@ -161,14 +174,18 @@
                                 debugger;
                                 $('text{$.id}viewFilterRestrict').setStyle('display', 'block');
                                 $('text{$.id}parameterInputTr').setStyle('display', 'table-row');
+                                $('text{$.id}parameterInputSelectTr').setStyle('display', 'table-row');
                                 $('text{$.id}viewCustomFilterRestrict').setStyle('display', 'none');
                                 $('text{$.id}pathInputTr').setStyle('display', 'none');
+                                $('text{$.id}pathInputSelectTr').setStyle('display', 'none');
                             }"/>作为默认过滤条件<br>
                             <input type="radio" class="customFilterInput_vf" value="custom" name="text{$.id}viewFilterType" onclick="if (this.checked){
                                 $('text{$.id}viewFilterRestrict').setStyle('display', 'none');
                                 $('text{$.id}parameterInputTr').setStyle('display', 'none');
+                                $('text{$.id}parameterInputSelectTr').setStyle('display', 'none');
                                 $('text{$.id}viewCustomFilterRestrict').setStyle('display', 'block');
                                 $('text{$.id}pathInputTr').setStyle('display', 'table-row');
+                                $('text{$.id}pathInputSelectTr').setStyle('display', 'table-row');
                             }" checked/>作为自定义过滤数据
                         </td>
                     </tr>

+ 1 - 1
o2web/source/x_component_query_StatementDesigner/Property.js

@@ -63,7 +63,7 @@ MWF.xApplication.query.StatementDesigner.Property = MWF.SDProperty = new Class({
         nodes.each(function (node) {
             MWF.xDesktop.requireApp("query.StatementDesigner", "widget.ViewFilter", function () {
                 var _slef = this;
-                new MWF.xApplication.query.StatementDesigner.widget.ViewFilter(node, this.view.designer, {
+                this.viewFilter = new MWF.xApplication.query.StatementDesigner.widget.ViewFilter(node, this.view.designer, {
                     "filtrData": filtrData,
                     "customData": customData
                 }, {

+ 45 - 22
o2web/source/x_component_query_StatementDesigner/Statement.js

@@ -576,28 +576,7 @@ MWF.xApplication.query.StatementDesigner.Statement = new Class({
             debugger;
             var entityClassName = e.target.options[e.target.selectedIndex].value;
             this.json.entityClassName = entityClassName;
-            if (this.json.format == "jpql") {
-                if (this.editor) {
-                    var re = /(.*from\s*)/ig;
-                    if (this.json.type == "update") re = /(.*update\s*)/ig;
-
-                    //if (this.json.type=="select" && this.editor){
-                    var v = this.json.data;
-
-                    var re2 = /(\s+)/ig;
-                    var arr = re.exec(v);
-                    if (arr && arr[0]) {
-                        var left = arr[0]
-                        v = v.substring(left.length, v.length);
-                        //var ar = re2.exec(v);
-                        var right = v.substring(v.indexOf(" "), v.length);
-                        this.json.data = left + entityClassName + right;
-                        this.editor.editor.setValue(this.json.data);
-                    }
-                    //}
-                }
-
-            }
+            this.changeEditorEntityClassName( entityClassName.split(".").getLast() );
 
 
             //     var className = e.target.options[e.target.selectedIndex].value;
@@ -649,6 +628,47 @@ MWF.xApplication.query.StatementDesigner.Statement = new Class({
             }
         }.bind(this));
     },
+    changeEditorEntityClassName : function( entityClassName ){
+        if (this.json.format == "jpql") {
+            if (this.editor) {
+                var re = /(.*from\s*)/ig;
+                if (this.json.type == "update") re = /(.*update\s*)/ig;
+
+                //if (this.json.type=="select" && this.editor){
+                var v = this.json.data;
+
+                var re2 = /(\s+)/ig;
+                var arr = re.exec(v);
+                if (arr && arr[0]) {
+                    var left = arr[0]
+                    v = v.substring(left.length, v.length);
+                    //var ar = re2.exec(v);
+                    var right = v.substring(v.indexOf(" "), v.length);
+                    this.json.data = left + entityClassName + right;
+                    this.editor.editor.setValue(this.json.data);
+                }
+
+                //}
+            }
+
+            if( this.countEditor ){
+                var re = /(.*from\s*)/ig;
+                var v = this.json.countData;
+
+                var re2 = /(\s+)/ig;
+                var arr = re.exec(v);
+                if (arr && arr[0]) {
+                    var left = arr[0]
+                    v = v.substring(left.length, v.length);
+                    //var ar = re2.exec(v);
+                    var right = v.substring(v.indexOf(" "), v.length);
+                    this.json.countData = left + entityClassName + right;
+                    this.countEditor.editor.setValue(this.json.countData);
+                }
+            }
+
+        }
+    },
 
     selectTable: function () {
         new MWF.O2Selector(this.designer.content, {
@@ -663,9 +683,12 @@ MWF.xApplication.query.StatementDesigner.Statement = new Class({
                     this.dynamicTableContent.set("text", name);
                     this.json.table = name;
                     this.json.tableObj = items[0].data;
+                    this.changeEditorEntityClassName( name );
+                    if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
                 } else {
                     this.dynamicTableContent.set("text", "");
                     this.json.table = "";
+                    if(this.view && this.view.property && this.view.property.viewFilter)this.view.property.viewFilter.setPathInputSelectOptions();
                 }
             }.bind(this)
         });

+ 124 - 0
o2web/source/x_component_query_StatementDesigner/widget/ViewFilter.js

@@ -124,7 +124,9 @@ MWF.xApplication.query.StatementDesigner.widget.ViewFilter = new Class({
 
         this.titleInput = this.inputAreaNode.getElement(".titleInput_vf");
         this.pathInput = this.inputAreaNode.getElement(".pathInput_vf");
+        this.pathInputSelect = this.inputAreaNode.getElement(".pathInputSelect_vf");
         this.parameterInput = this.inputAreaNode.getElement(".parameterInput_vf");
+        this.parameterInputSelect = this.inputAreaNode.getElement(".parameterInputSelect_vf");
         this.datatypeInput = this.inputAreaNode.getElement(".datatypeInput_vf");
 
         this.restrictFilterInput = this.inputAreaNode.getElement(".restrictFilterInput_vf");
@@ -199,6 +201,84 @@ MWF.xApplication.query.StatementDesigner.widget.ViewFilter = new Class({
             if (e.code == 13) this.modifyOrAddFilterItem();
         }.bind(this));
 
+        this.pathInputSelect.addEvent("change", function ( ev ) {
+            var option = ev.target.options[ev.target.selectedIndex];
+            debugger;
+            var type = option.retrieve("type");
+            var d = this.app.statement.data;
+            if( type === "dynamic" ){
+                var field = option.retrieve("field");
+                if( field ){
+                    this.titleInput.set("value", field.description || field.name);
+                    if( field.name ){
+                        var path = this.pathInput.get("value");
+                        if( path.indexOf(".") > -1 ){
+                            path = path.split(".")[0] +"."+ field.name;
+                        }else{
+                            var alias;
+                            var tableName = option.retrieve("tableName");
+                            if( d.data.indexOf(tableName) > -1){
+                                var str = d.data.split(tableName)[1].trim();
+                                if( str.indexOf(" ") )alias = str.split(" ")[0];
+                            }
+                            path = alias ? ( alias +"."+ field.name ) : field.name;
+                        }
+                        this.pathInput.set("value", path);
+                    }
+                    if( field.type ){
+                        var t;
+                        switch (field.type) {
+                            case "string":
+                            case "stringList":
+                            case "stringLob":
+                            case "stringMap":
+                                t = "textValue";
+                                break;
+                            case "integer":
+                            case "long":
+                            case "double":
+                            case "integerList":
+                            case "longList":
+                            case "doubleList":
+                                t = "numberValue";
+                                break;
+                            case "dateTime":
+                                t = "dateTimeValue";
+                                break;
+                            case "date":
+                                t = "dateValue";
+                                break;
+                            case "time":
+                                t = "timeValue";
+                                break;
+                            case "boolean":
+                            case "booleanList":
+                                t = "booleanValue";
+                                break;
+                            default:
+                                t = "textValue";
+                                break;
+                        }
+                        for (var i = 0; i < this.datatypeInput.options.length; i++) {
+                            if (this.datatypeInput.options[i].value === t) {
+                                this.datatypeInput.options[i].set("selected", true);
+                                this.switchInputDisplay();
+                                if (this.datatypeInput.onchange) this.datatypeInput.onchange();
+                                break;
+                            }
+                        }
+                    }
+                }else{
+                    this.titleInput.set("value", "");
+                    this.pathInput.set("value", "");
+                    this.datatypeInput.options[0].set("selected", true);
+                    this.switchInputDisplay();
+                    if (this.datatypeInput.onchange)this.datatypeInput.onchange();
+                }
+            }
+        }.bind(this))
+        this.setPathInputSelectOptions()
+
         //if (this.app.statement.view){
         //    var id = this.app.view.data.id;
         //     var div = this.node.getElement("#"+id+"viewFilterValueArea2");
@@ -246,6 +326,38 @@ MWF.xApplication.query.StatementDesigner.widget.ViewFilter = new Class({
         //     }
         // }
     },
+    setPathInputSelectOptions : function(){
+        debugger;
+        var d = this.app.statement.data;
+        this.pathInputSelect.empty();
+        if( d.entityCategory ==='dynamic' && d.table ){
+            o2.Actions.load("x_query_assemble_designer").TableAction.get( d.table, function(json){
+                if( json.data.data ){
+
+                    var ps = this.pathInput.get("value").split(".");
+                    var p = ps[1] ? ps[1] : ps[0];
+
+                    var option = new Element("option", { "text": "", "value": "" }).inject(this.pathInputSelect);
+                    option.store("type", "dynamic");
+                    option.store("tableName", json.data.name);
+
+                    var fieldJson = JSON.parse( json.data.data );
+                    fieldJson.fieldList.each( function ( field ) {
+                        var option = new Element("option", {
+                            "text": field.name + ( field.description ? ("-" + field.description) : "" ),
+                            "value": field.name,
+                            "selected": (field.name===p)
+                        }).inject(this.pathInputSelect);
+                        option.store("field", field);
+                        option.store("type", "dynamic");
+                        option.store("tableName", json.data.name);
+                    }.bind(this))
+                }
+            }.bind(this))
+        }else if( d.entityCategory ==='official' ){
+
+        }
+    },
     switchInputDisplay: function () {
         var id = "";
         if (this.app.statement.view) {
@@ -591,6 +703,18 @@ MWF.xApplication.query.StatementDesigner.widget.ViewFilter = new Class({
             }
         }
 
+        var ps = this.pathInput.get("value").split(".");
+        var p = ps[1] ? ps[1] : ps[0];
+        var flag = true;
+        for (var i = 0; i < this.pathInputSelect.options.length; i++) {
+            if (this.pathInputSelect.options[i].value === p) {
+                this.pathInputSelect.options[i].set("selected", true);
+                flag = false;
+                break;
+            }
+        }
+        if(flag)this.pathInputSelect.options[0].set("selected", true);
+
         switch (data.formatType) {
             case "textValue":
                 this.valueTextInput.set("value", data.value);