text: define(["report/dim-set/model","report/dim-set/html-template/main-template","report/dim-set/html-template/normal-template","report/dim-set/html-template/normal-new-line-template","report/dim-set/html-template/date-template","report/dim-set/html-template/date-changed-template","report/dim-set/html-template/callback-template","report/dim-set/html-template/callback-new-line-template","report/dim-set/html-template/custom-template","report/dim-set/html-template/custom-new-line-template","dialog"],function(a,b,c,d,e,f,g,h,i,j,k){var l=k.confirm,m={SETTING_MODULE_MSG:"行",MAIN_TABLE_MSG:"：请选择主数据表",MAIN_TABLE_FIELD_MSG:"：请选择主表字段",RELATION_TABLE__MSG:"：请选择关联数据表",RELATION_TABLE_FIELD__MSG:"：请选择关联表字段"},n={SETTING_MODULE_MSG:"模块",DIM_MSG:"：请选择回调字段",ADDRESS_MSG:"：请填写正确格式的回调地址",INTERVAL_MSG:"：请填写正确格式的时间间隔"},o={RELATION_TABLE_MSG:"：请选择被关联表",DATE_FIELD_MSG:"：请选择时间字段",LEVEL_MSG:"：请选择粒度",FORMAT_MSG:"：请选择时间格式",RELATION_FIELD_MSG:"：请指定关联字段"},p={SETTING_MODULE_MSG:"模块",DIM_MSG:"：请选择回调字段",DIM_NAME_MSG:"：请输入正确格式的维度名称",SQL_MSG:"：请填写正确格式的sql语句"},q=Backbone.View.extend({initialize:function(b){var c=this,d=this.model=new a;this.model.set("id",b.id),d.on("submitSucess",c._initEditReportView,c),d.on("getDimSetDataSucess",c.render,c),d.on("getDateFieldsDataSucess",c._getDateFieldsDataSucess,c),d.getDimSetData()},events:{"click .classification":"_dimTypeClick","click .j-normal-cube-open":"_closeNormalCube","click .j-normal-cube-close":"_openNormalCube","click .j-normal-delete":"_deleteNormalLine","click .j-normal-add":"_addNormalLine","change .j-normal-relation-table-select":"_normalRelationTableChanged","change .j-owner-date-level-select":"_dateTypeChanged","change .j-relation-table-select":"_relationTableChanged","click .j-callback-cube-open":"_closeCallbackCube","click .j-callback-cube-close":"_openCallbackCube","click .j-callback-delete":"_deleteCallbackLine","click .j-callback-add":"_addCallbackLine","click .j-custom-delete":"_deleteCustomLine","click .j-custom-add":"_addCustomLine","click .j-custom-field":"_appendToSqlText","focus .j-custom-sql":"_txtSqlFocus","change .j-custom-sql":"_txtSqlBlur","click .j-dim-set-ok":"_submit","click .j-dim-set-cancel":"_cancel","click .j-dim-set-prev":"_returnSetCube"},render:function(){var a=this,d=a.model,f=d.buildNormalData(),h=d.buildDateData(),i=d.buildCallbackData();$(a.el).html(b.render()),$(".j-dim-setting-body").append(c.render(f)),$(".j-dim-setting-body").append(e.render(h)),$(".j-dim-setting-body").append(g.render(i)),a._renderCustom()},_renderCustom:function(){var a,b,c,d,e,f,g;g=this.model.buildCustomData(),$(".j-dim-setting-body").append(i.render(g)),a=$(".j-custom-main"),b=a.find(".j-custom-main-box");for(var h=0,j=b.length;j>h;h++)c=$(b[h]),f=c.find(".j-custom-relation-box").length,d=c.find(".custom-main-table-fields-box"),e=parseInt(d.css("height")),e+=105*(f-1),d.css("height",e+"px")},destroy:function(){this.stopListening(),this.model.clear({silent:!0}),delete this.model,this.$el.unbind().empty()},_dimTypeClick:function(a){var b;"span"===a.target.tagName.toLowerCase()?b=$(a.target).parent():"li"===a.target.tagName.toLowerCase()&&(b=$(a.target)),this._changeTab(b)},_changeTab:function(a){var b,c;a.addClass("classification-focus").siblings().removeClass("classification-focus"),b=a.attr("id"),c=b.split("-"),$(".dim-container-"+c[c.length-1]).show().siblings().hide()},_normalRelationTableChanged:function(a){var b,c,d,e=[],f=['<option value="0">请选择</option>'],g=this,h=g.model;if(b=$(a.target),d=b.val(),c=b.next("select"),"0"===d)c.html(f.join(""));else{e=h.getFieldListByRelationTable(d);for(var i=0,j=e.length;j>i;i++)f.push('<option value="',e[i].id,'">',e[i].name,"</option>");c.html(f.join(""))}},_closeNormalCube:function(a){var b;b=$(a.target),b.removeClass("normal-cube-open j-normal-cube-open").addClass("normal-cube-close j-normal-cube-close"),b.next("div").hide()},_openNormalCube:function(a){var b;b=$(a.target),b.removeClass("normal-cube-close j-normal-cube-close").addClass("normal-cube-open j-normal-cube-open"),b.next("div").show()},_deleteNormalLine:function(a){var b,c,d,e,f;l("您确定要删除吗？",function(){if(b=$(a.target),c=b.parent(),d=c.prev(),e=c.next(),f=c.parent().find(".j-normal-relation-box").length,1!==f)0===c.find(".normal-broken-line").length&&e&&e.find(".normal-broken-line").remove(),c.find(".j-normal-add").length>0&&d&&d.append('<span class="add j-normal-add"></span>'),b.parent().remove();else for(var g=c.parent().find("select"),h=0,i=g.length;i>h;h++)$(g[h]).val("0")})},_addNormalLine:function(a){var b,c,e,f,g,h=this,i=h.model;b=$(a.target),c=b.parent().parent().parent(),e=b.parent().parent(),g=c.find(".cube-name").attr("cubeId"),f=i.buildNormalNewLineData(g),e.append(d.render(f)),b.remove()},_getNormalData:function(a){for(var b=this,c=[],d=$(".j-normal-main"),e=d.find(".j-normal-main-box"),f=0,g=e.length;g>f;f++){var h=$(e[f]),i=h.find(".j-normal-error-msg"),j=h.find(".j-normal-relation-box"),k=h.find(".cube-name"),l=k.text(),n={};n.cubeId=k.attr("cubeId"),n.children=[];for(var o=0,p=j.length;p>o;o++){var q,r={},s=$(j[o]).find("select");if(r.currDim=$(s[0]).val(),r.relationTable=$(s[1]).val(),r.field=$(s[2]).val(),o!==p-1||"0"!==r.currDim||"0"!==r.relationTable||"0"!==r.field){if(q=""+l+" --- 第"+(o+1)+m.SETTING_MODULE_MSG,"0"===r.currDim)return b._changeTab($("#j-tab-normal")),i.html(q+m.MAIN_TABLE_FIELD_MSG).show(),!1;if("0"===r.relationTable)return b._changeTab($("#j-tab-normal")),i.html(q+m.RELATION_TABLE__MSG).show(),!1;if("0"===r.field)return b._changeTab($("#j-tab-normal")),i.html(q+m.RELATION_TABLE_FIELD__MSG).show(),!1;i.html("").hide(),n.children.push(r)}}c.push(n)}return a.normal=JSON.stringify(c),!0},_dateTypeChanged:function(a){for(var b=this,c=b.model,d=$(a.target),e=d.val(),f=c.getDateTypeByDateLevel(e),g=['<option value="0">请选择</option>'],h=0,i=f.length;i>h;h++)g.push('<option value="',f[h],'">',f[h],"</option>");d.siblings(".j-owner-date-type-select").html(g.join(""))},_relationTableChanged:function(a){var b,c=this,d=c.model,e=$(a.target),f=e.parent().parent(),g=e.parent().parent().parent().find(".cube-name").attr("cubeId");b=e.val(),d.buildDateFieldsData(b,g,f)},_getDateFieldsDataSucess:function(a,b){var c,d;"ownertable"===a.tableId||"0"===a.tableId?b.removeClass("date-relation-normal").addClass("date-relation-owner"):b.removeClass("date-relation-owner").addClass("date-relation-normal"),c=b.find(".j-date-two-part"),d=b.find(".j-date-three-part"),c&&c.remove(),d&&d.remove(),b.append(f.render(a))},_getDateData:function(a){for(var b=this,c=[],d=$(".j-date-main"),e=d.find(".j-date-main-box"),f=0,g=e.length;g>f;f++){var h,i,j=$(e[f]),k=j.find(".j-date-error-msg"),l=j.find(".cube-name"),m=l.text(),n={},p={};if(n.cubeId=l.attr("cubeId"),n.children=[],p.relationTable=j.find(".j-relation-table-select").val(),i=m,"0"===p.relationTable){if(h=j.find(".date-relation-owner").find(".j-date-two-part").find("select"),"0"===$(h[0]).val()&&"0"===$(h[1]).val()&&"0"===$(h[2]).val()){c.push(n);continue}return b._changeTab($("#j-tab-date")),k.html(i+o.RELATION_TABLE_MSG).show(),!1}if("ownertable"===p.relationTable){if(h=j.find(".date-relation-owner").find(".j-date-two-part").find("select"),p.currDim=$(h[0]).val(),p.field=$(h[1]).val(),p.format=$(h[2]).val(),"0"===p.currDim)return b._changeTab($("#j-tab-date")),k.html(i+o.DATE_FIELD_MSG).show(),!1;if("0"===p.field)return b._changeTab($("#j-tab-date")),k.html(i+o.LEVEL_MSG).show(),!1;if("0"===p.format)return b._changeTab($("#j-tab-date")),k.html(i+o.FORMAT_MSG).show(),!1;k.html("").hide()}else{if(h=j.find(".date-relation-normal").find(".j-date-two-part").find("select"),p.currDim=$(h[0]).val(),p.field=$(h[1]).val(),"0"===p.currDim)return b._changeTab($("#j-tab-date")),k.html(i+o.RELATION_FIELD_MSG).show(),!1;if("0"===p.field)return b._changeTab($("#j-tab-date")),k.html(i+o.RELATION_FIELD_MSG).show(),!1;k.html("").hide(),p.dateLevel={},h=j.find(".date-relation-normal").find(".j-date-three-part").find("select");for(var q=0,r=h.length;r>q;q++){var s=$(h[q]).attr("formatKey");p.dateLevel[s]={};var t=p.dateLevel[s]=$(h[q]).val();if("0"===t)return b._changeTab($("#j-tab-date")),k.html(i+o.FORMAT_MSG).show(),!1;k.html("").hide()}}n.children.push(p),c.push(n)}return a.date=JSON.stringify(c),!0},_closeCallbackCube:function(a){var b;b=$(a.target),b.removeClass("callback-cube-open j-callback-cube-open").addClass("callback-cube-close j-callback-cube-close"),b.next("div").hide()},_openCallbackCube:function(a){var b;b=$(a.target),b.removeClass("callback-cube-close j-callback-cube-close").addClass("callback-cube-open j-callback-cube-open"),b.next("div").show()},_addCallbackLine:function(a){var b,c,d,e,f,g,i=this,j=i.model;b=$(a.target),c=b.parent().parent().parent(),d=b.parent().parent(),e=b.parent(),g=c.find(".cube-name").attr("cubeId"),f=j.buildCallbackNewLineData(g),f.boxIndex=c.attr("bodyIndex"),f.lineIndex=parseInt(e.attr("bodyIndex"))+1,d.append(h.render(f)),b.remove()},_deleteCallbackLine:function(a){var b,c,d,e,f;l("您确定要删除吗？",function(){return b=$(a.target),c=b.parent(),d=c.prev(),e=c.next(),f=c.parent().find(".j-callback-relation-box").length,1===f?(c.find("select").val("0"),c.find('input[type="text"]').val(""),c.find('input[type="radio"]').val("1"),void 0):(0===c.find(".normal-broken-line").length&&e&&e.find(".callback-broken-line").remove(),c.find(".j-callback-add").length>0&&d&&d.append('<span class="add j-callback-add"></span>'),b.parent().remove(),void 0)})},_getCallbackData:function(a){function b(a){var b=/[\u4e00-\u9fa5]/;return""===a||b.test(a)?!1:!0}function c(a){var b=/^[1-9]\d*$/;return""!==a&&b.test(a)?!0:!1}for(var d=this,e=[],f=$(".j-callback-main"),g=f.find(".j-callback-main-box"),h=0,i=g.length;i>h;h++){var j=$(g[h]),k=j.find(".j-callback-error-msg"),l=j.find(".j-callback-relation-box"),m=j.find(".cube-name"),o=m.text(),p={children:[]};p.cubeId=m.attr("cubeId");for(var q=0,r=l.length;r>q;q++){var s,t={};if(s=""+o+" --- 第"+(q+1)+n.SETTING_MODULE_MSG,t.currDim=$(l[q]).find("select").val(),t.address=$.trim($(l[q]).find(".j-callback-address-input").val()),t.refreshType=$(l[q]).find('input[type="radio"]:checked').val(),q!==r-1||"0"!==t.currDim||""!==t.address||"1"!==t.refreshType){if("0"===t.currDim)return d._changeTab($("#j-tab-callback")),k.html(s+n.DIM_MSG).show(),!1;if(!b(t.address))return d._changeTab($("#j-tab-callback")),k.html(s+n.ADDRESS_MSG).show(),!1;if(k.html("").hide(),"3"===t.refreshType){if(t.interval=$.trim($(l[q]).find(".j-callback-cache-type-interval").val()),!c(t.interval))return d._changeTab($("#j-tab-callback")),k.html(s+n.INTERVAL_MSG).show(),!1;k.html("").hide()}p.children.push(t)}}e.push(p)}return a.callback=JSON.stringify(e),!0},_deleteCustomLine:function(a){var b,c,d,e,f,g;l("您确定要删除吗？",function(){return b=$(a.target),c=b.parent(),d=c.prev(),e=c.parent().prev(),f=parseInt(e.css("height"))-105,g=c.parent().find(".j-custom-relation-box").length,1===g?(c.find("input[type=text]").val(""),c.find("textarea").val(""),void 0):(c.find(".j-custom-add").length>0&&d&&d.append('<span class="add j-custom-add"></span>'),b.parent().remove(),e.css("height",f+"px"),void 0)})},_addCustomLine:function(a){var b,c,d=$(a.target),e=d.parent().parent();b=e.prev(),e.append(j.render(b.attr("bodyIndex"))),d.remove(),c=parseInt(b.css("height"))+105,b.css("height",c+"px")},_appendToSqlText:function(a){var b,c,d,e,f,g,h;b=$(a.target),c=" "+b.text()+" ",d=$(this.focusTextSql),e=b.attr("bodyIndex"),f=d.attr("bodyIndex"),d&&e===f&&(g=d.val(),h=$.getCursorPosition(d[0]),g=g.slice(0,h)+c+g.slice(h,g.length),d.val(g),d.diFocus(h+c.length))},_txtSqlFocus:function(a){var b=this;b.focusTextSql=a.target},_txtSqlBlur:function(a){var b=this,c=$(a.target);b._validateSql(c.val())?c.next("span").removeClass("custom-create-new-dim-texts-wrong").addClass("custom-create-new-dim-texts-right"):c.next("span").removeClass("custom-create-new-dim-texts-right").addClass("custom-create-new-dim-texts-wrong")},_validateSql:function(a){return $.trim(a)?!0:!1},_getCustomData:function(a){for(var b=this,c=[],d=$(".j-custom-main"),e=d.find(".j-custom-main-box"),f=0,g=e.length;g>f;f++){var h={},i=$(e[f]),j=i.find(".j-custom-relation-box"),k=i.find(".j-custom-error-msg"),l=i.find(".cube-name"),m=l.text();h.cubeId=l.attr("cubeId"),h.children=[];for(var n=0,o=j.length;o>n;n++){var q=""+m+" --- 第"+(n+1)+p.SETTING_MODULE_MSG,r={};if(r.dimName=$.trim($(j[n]).find('input[type="text"]').val()),r.sql=$.trim($(j[n]).find("textarea").val()),n!==o-1||""!==r.dimName||""!==r.sql){if(!r.dimName)return b._changeTab($("#j-tab-custom")),k.html(q+p.DIM_NAME_MSG).show(),!1;if(!r.sql)return b._changeTab($("#j-tab-custom")),k.html(q+p.SQL_MSG).show(),!1;k.html("").hide(),h.children.push(r)}}c.push(h)}return a.custom=JSON.stringify(c),!0},_submit:function(){var a=this,b=a.model,c={};return a._getNormalData(c)?a._getDateData(c)?a._getCallbackData(c)?a._getCustomData(c)?(b.submit(c),void 0):!1:!1:!1:!1},_submitSucess:function(){this._iniLeftPanel()},_cancel:function(){this._initReport()},_returnSetCube:function(){this._initSetCube()},_initEditReportView:function(){var a=this.model,b=a.get("id");require(["report/edit/main-view"],function(a){new a({el:$(".j-main"),id:b,isEdit:!1})}),this.destroy()},_initSetCube:function(){var a=this.model,b=a.get("id");require(["report/set-cube/cube-view"],function(a){new a({el:$(".j-main"),id:b,edit:!0})}),this.destroy()},_initReport:function(){require(["report/list/main-view"],function(a){new a({el:$(".j-main")})}),this.destroy()}});return q});