123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
- //MWF.require("MWF.widget.Tree", null, false);
- /** @class Sidebar 侧边操作条。
- * @o2cn 侧边操作条
- * @example
- * //可以在脚本中获取该组件
- * //方法1:
- * var sidebar = this.form.get("fieldId"); //获取侧边操作条
- * //方法2
- * var sidebar = this.target; //在侧边操作条和操作本身的事件脚本中获取
- * @extends MWF.xApplication.process.Xform.$Module
- * @o2category FormComponents
- * @o2range {Process}
- * @hideconstructor
- */
- MWF.xApplication.process.Xform.Sidebar = MWF.APPSidebar = new Class(
- /** @lends MWF.xApplication.process.Xform.Sidebar# */
- {
- Extends: MWF.APP$Module,
- options: {
- /**
- * 组件加载前触发。当前组件的queryLoad事件还没有在form里注册,通过this.form.get("fieldId")不能获取到当前组件,需要用this.target获取当前组件。
- * @event MWF.xApplication.process.Xform.Sidebar#queryLoad
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 组件加载时触发。
- * @event MWF.xApplication.process.Xform.Sidebar#load
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 组件加载后事件.由于加载过程中有异步处理,这个时候操作条有可能还未生成。
- * @event MWF.xApplication.process.Xform.Sidebar#postLoad
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- /**
- * 组件加载后事件。这个时候操作条已生成
- * @event MWF.xApplication.process.Xform.Sidebar#afterLoad
- * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明}
- */
- "moduleEvents": ["load", "queryLoad", "postLoad", "afterLoad"]
- },
- _loadUserInterface: function(){
- this.node.setStyles(this.form.css.sidebar);
- this.node.setStyles({
- "min-width":"126px",
- "max-width":"240px",
- "width": "auto"
- });
- // this.node.setStyle("width", this.node.getSize().x+"px");
- this.toolbarNode = this.node.getFirst("div");
- this.toolbarNode.empty();
- if (this.form.businessData.task){
- MWF.require("MWF.widget.Toolbar", function(){
- var toolbars = [];
- //this.form.businessData.task.routeNameList.each(function(route, i){
- // if (!this.json.defaultTools) this.json.defaultTools = [];
- // var o= {
- // "type": "MWFToolBarButton",
- // "img": "submit.png",
- // "title": route,
- // "action": "processWork:"+route,
- // "text": route,
- // "id": "action_processWork",
- // "control": "allowProcessing",
- // "condition": "",
- // "read": false
- // };
- // toolbars.push(o);
- //}.bind(this));
- ( this.getRouteNameList() || [] ).each(function(route, i){
- if (!this.json.defaultTools) this.json.defaultTools = [];
- var o= {
- "type": "MWFToolBarButton",
- "img": "submit.png",
- "title": route.displayName,
- "action": "processWork:"+route.routeName,
- "text": route.displayName,
- "id": "action_processWork",
- "control": "allowProcessing",
- "condition": "",
- "read": false
- };
- toolbars.push(o);
- }.bind(this));
- this.json.defaultTools = toolbars.concat(this.json.defaultTools);
- //this.json.defaultTools.unshift(o);
- /**
- * @summary Toolbar组件,平台使用该组件生成操作条。
- * @member {o2.widget.Toolbar}
- * @example
- * //可以在脚本中获取该组件
- * var toolbarWidget = this.form.get("fieldId").toolbarWidget; //获取组件对象
- */
- this.toolbarWidget = new MWF.widget.Toolbar(this.toolbarNode, {
- "style": this.json.style,
- "onPostLoad" : function(){
- this.fireEvent("afterLoad");
- }.bind(this)
- }, this);
- //alert(this.readonly)
- if (this.json.hideSystemTools){
- if (this.json.tools.length){
- this.setCustomToolbars(this.json.tools, this.toolbarNode);
- this.toolbarWidget.load();
- }else{
- this.toolbarNode.setStyle("display", "none");
- }
- }else{
- if (this.json.defaultTools.length || this.json.tools.length){
- if (this.json.defaultTools){
- this.setToolbars(this.json.defaultTools, this.toolbarNode, this.readonly);
- this.setCustomToolbars(this.json.tools, this.toolbarNode);
- this.toolbarWidget.load();
- }else{
- MWF.getJSON(this.form.path+"toolbars.json", function(json){
- this.setToolbars(json, this.toolbarNode, this.readonly, true);
- this.setCustomToolbars(this.json.tools, this.toolbarNode);
- this.toolbarWidget.load();
- }.bind(this), false);
- }
- }else{
- this.toolbarNode.setStyle("display", "none");
- }
- }
- if (this.toolbarWidget.children.length){
- //this.form.app.addEvent("resize", this.loadPosition.bind(this));
- this.node.setStyle("display", "none");
- window.setTimeout(this.loadPosition.bind(this), 500);
- var _self = this;
- this.form.app.content.getFirst().addEvent("scroll", function(e){
- _self.loadPosition(this);
- });
- this.form.app.addEvent("resize", function(e){
- _self.loadPosition(this);
- });
- }else{
- this.toolbarNode.setStyle("display", "none");
- }
- }.bind(this));
- }else{
- this.node.setStyle("display", "none");
- }
- },
- loadPosition: function(){
- // this.node.setStyle("display", "block");
- // var parent = this.node.getParent();
- // while(parent && (!parent.get("MWFtype"))) parent = parent.getParent();
- //
- // var top = this.json.styles.top;
- // this.sideNode = parent || this.form.node;
- //
- // var size = this.form.app.content.getSize();
- // var scroll = this.form.app.content.getScroll();
- // var sideSize = this.sideNode.getSize();
- //
- // var y = (scroll.y+size.y/2)-sideSize.y/2;
- // var x = 5;
- //
- // var position = "centerRight";
- // var edge = "centerLeft";
- // if (!parent){
- // edge = "centerRight";
- // x = 5;
- // }
- //
- // if (this.json.barPosition=="left"){
- // position = "centerLeft";
- // edge = "centerRight";
- // x = -5;
- // if (!parent){
- // edge = "centerLeft";
- // x = 5;
- // }
- // }
- //
- // this.node.position({
- // "relativeTo": this.sideNode,
- // "position": position,
- // "edge": edge,
- // "offset" : {"y": y, "x": x}
- // });
- // this.json.styles.top = top;
- // if (top) this.node.setStyle("top", top);
- this.node.setStyle("display", "block");
- var parent = this.node.getParent();
- while(parent && (!parent.get("MWFtype"))) parent = parent.getParent();
- this.sideNode = parent || this.form.node;
- var size = this.form.app.content.getSize();
- //var scroll = this.form.designer.designNode.getScroll();
- var sideSize = this.sideNode.getSize();
- var sidePosition = this.sideNode.getPosition(this.sideNode.getOffsetParent());
- var nodeSize = this.node.getSize();
- if (sideSize.y>size.y){
- var center = (size.y/2-nodeSize.y/2);
- if (center<sidePosition.y){
- this.node.setStyle("top", ""+sidePosition.y+"px");
- }else if (center>(sidePosition.y+sideSize.y)){
- var tmp = (sidePosition.y+sideSize.y)-nodeSize.y;
- this.node.setStyle("top", ""+tmp+"px");
- }else{
- this.node.setStyle("top", ""+center+"px");
- }
- }else{
- var top = sidePosition.y+sideSize.y/2-nodeSize.y/2;
- if (top>size.y){
- if (sidePosition.y+nodeSize.y>size.y){
- this.node.setStyle("top", ""+sidePosition.y+"px");
- }else{
- var tmp = size.y-nodeSize.y;
- this.node.setStyle("top", ""+tmp+"px");
- }
- }else if(top<=0){
- if(sidePosition.y+sideSize.y<nodeSize.y){
- var tmp = sidePosition.y+sideSize.y-nodeSize.y;
- this.node.setStyle("top", ""+tmp+"px");
- }else{
- this.node.setStyle("top", "45px");
- }
- }else{
- this.node.setStyle("top", ""+top+"px");
- }
- }
- //var left = sideSize.x+sidePosition.x+5;
- var x = sidePosition.x+sideSize.x+nodeSize.x;
- var left;
- if( x > size.x ){
- left = size.x - nodeSize.x - 5;
- }else{
- left = sideSize.x+sidePosition.x+5;
- }
- this.node.setStyle("left", ""+left+"px");
- this.node.setStyle("position", "absolute");
- this.node.setStyles({"right": "auto", "bottom": "auto"});
- // this.json.styles = this.node.getStyles(["top", "left", "bottom", "right", "position"]);
- //
- // var p = this.sideNode.getPosition();
- // var s = this.sideNode.getSize();
- // this.sidePosition = {"p": p, "s": s};
- },
- setCustomToolbars: function(tools, node){
- var path = "../x_component_process_FormDesigner/Module/Actionbar/";
- tools.each(function(tool){
- var flag = true;
- if (this.readonly){
- flag = tool.readShow;
- }else{
- flag = tool.editShow;
- }
- if (flag){
- flag = true;
- if (tool.control){
- flag = this.form.businessData.control[tool.control]
- }
- if (tool.condition){
- var hideFlag = this.form.Macro.exec(tool.condition, this);
- flag = !hideFlag;
- }
- if (flag){
- var actionNode = new Element("div", {
- "id": tool.id,
- "MWFnodetype": tool.type,
- //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
- "MWFButtonImage": path+(this.form.options.style||"default") +"/custom/"+tool.img,
- "title": tool.title,
- "MWFButtonAction": "runCustomAction",
- "MWFButtonText": tool.text
- }).inject(node);
- if (tool.actionScript){
- actionNode.store("script", tool.actionScript);
- }
- if (tool.sub){
- var subNode = node.getLast();
- this.setCustomToolbars(tool.sub, subNode);
- }
- }
- }
- }.bind(this));
- },
- setToolbars: function(tools, node, readonly, noCondition){
- var path = "../x_component_process_FormDesigner/Module/Actionbar/";
- tools.each(function(tool){
- var flag = true;
- if (tool.control){
- flag = this.form.businessData.control[tool.control]
- }
- if (!noCondition) if (tool.condition){
- var hideFlag = this.form.Macro.exec(tool.condition, this);
- flag = !hideFlag;
- }
- if (tool.id == "action_processWork"){
- if (!this.form.businessData.task){
- flag = false;
- }
- }
- if (readonly) if (!tool.read) flag = false;
- if (flag){
- var actionNode = new Element("div", {
- "id": tool.id,
- "MWFnodetype": tool.type,
- //"MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+tool.img,
- "MWFButtonImage": path+(this.form.options.style||"default") +"/tools/default/"+tool.img,
- "title": tool.title,
- "MWFButtonAction": tool.action,
- "MWFButtonText": tool.text
- }).inject(node);
- if (tool.sub){
- var subNode = node.getLast();
- this.setToolbars(tool.sub, subNode, readonly, noCondition);
- }
- }
- }.bind(this));
- },
- getRouteNameList: function( routeList ){
- var _self = this;
- var list = [];
- if( !routeList )routeList = this.getRouteDataList();
- routeList.each(function(route, i){
- if( route.hiddenScriptText && this.form && this.form.Macro ){
- if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
- }
- var routeName = route.name;
- if( route.displayNameScriptText && this.form && this.form.Macro ){
- routeName = this.form.Macro.exec(route.displayNameScriptText, this);
- }
- list.push({
- "routeId" : route.id,
- "displayName" : routeName,
- "routeName" : route.name
- })
- }.bind(this));
- return list;
- },
- getRouteDataList : function(){
- if(this.routeDataList)return this.routeDataList;
- if (this.form && this.form.businessData && this.form.businessData.task && this.form.businessData.task.routeNameDisable){
- this.routeDataList = [{
- "id": o2.uuid(),
- "asyncSupported": false,
- "soleDirect": false,
- "name": "继续流转",
- "alias": "",
- "selectConfigList": []
- }];
- return this.routeDataList;
- }
- if( this.form && this.form.businessData && this.form.businessData.routeList ){
- this.form.businessData.routeList.sort( function(a, b){
- var aIdx = parseInt(a.orderNumber || "9999999");
- var bIdx = parseInt(b.orderNumber || "9999999");
- return aIdx - bIdx;
- }.bind(this));
- this.form.businessData.routeList.each( function(d){
- d.selectConfigList = JSON.parse(d.selectConfig || "[]");
- }.bind(this));
- this.routeDataList = this.form.businessData.routeList;
- }
- if( !this.routeDataList && this.form && this.form.businessData && this.form.businessData.task && this.form.businessData.task ){
- o2.Actions.get("x_processplatform_assemble_surface").listRoute( {"valueList":this.form.businessData.task.routeList} , function( json ){
- json.data.sort(function(a, b){
- var aIdx = parseInt(a.orderNumber || "9999999");
- var bIdx = parseInt(b.orderNumber || "9999999");
- return aIdx - bIdx;
- }.bind(this));
- json.data.each( function(d){
- d.selectConfigList = JSON.parse( d.selectConfig || "[]" );
- }.bind(this));
- this.routeDataList = json.data;
- }.bind(this), null, false );
- }
- return this.routeDataList;
- },
- isOpinionRequired: function( routeName ){
- var routeList = this.getRouteDataList();
- for( var i=0; i<routeList.length; i++ ){
- if( routeList[i].name === routeName ){
- return routeList[i].opinionRequired;
- }
- }
- },
- getRouteId: function( routeName ){
- var routeList = this.getRouteDataList();
- for( var i=0; i<routeList.length; i++ ){
- if( routeList[i].name === routeName ){
- return routeList[i].id;
- }
- }
- },
- getRouteData : function( routeId ){
- var routeList = this.getRouteDataList();
- for( var i=0; i<routeList.length; i++ ){
- if( routeList[i].id === routeId ){
- return routeList[i];
- }
- }
- },
- getOrgData: function (routeId) {
- var routeList = this.getRouteDataList();
- for (var i = 0; i < routeList.length; i++) {
- if (routeList[i].id === routeId) {
- return routeList[i].selectConfigList;
- }
- }
- },
- getVisableOrgData: function (routeId) {
- var selectConfigList = this.getOrgData(routeId);
- var list = [];
- (selectConfigList || []).each(function (config) {
- if (!this.isOrgHidden(config)) {
- list.push(config);
- }
- }.bind(this));
- return list;
- },
- isOrgHidden: function (d) {
- if (d.hiddenScript && d.hiddenScript.code) { //如果隐藏路由,返回
- var hidden = this.form.Macro.exec(d.hiddenScript.code, this);
- if (hidden && hidden.toString() === "true") return true;
- }
- return false;
- },
- runCustomAction: function(bt){
- var script = bt.node.retrieve("script");
- this.form.Macro.exec(script, this);
- },
- saveWork: function(){
- this.form.saveWork();
- },
- closeWork: function(){
- this.form.closeWork();
- },
- processWork: function(route){
- var opinion = this.form.getOpinion();
- if( !opinion.opinion && !opinion.medias.length && this.isOpinionRequired(route)){
- this.form.notice(MWF.xApplication.process.Work.LP.opinionRequired, "error");
- return false;
- }
- this.form.Macro.environment.form.currentRouteName = route;
- this.form.Macro.environment.form.opinion = opinion.opinion;
- this.form.Macro.environment.form.medias = opinion.medias;
- var routeId = this.getRouteId( route );
- var routeData = this.getRouteData( routeId );
- if (routeData.validationScriptText) {
- var validation = this.form.Macro.exec(routeData.validationScriptText, this);
- if (!validation || validation.toString() !== "true") {
- validation = typeOf(validation) === "string" ? validation : MWF.xApplication.process.Work.LP.routeValidFailure;
- this.form.notice(validation, "error");
- return false;
- }
- }
- if (!this.form.formCustomValidation()){
- this.form.app.content.unmask();
- // if (callback) callback();
- return false;
- }
- if( this.getVisableOrgData( routeId ).length > 0 ){
- this.form.processWork( routeId );
- }else{
- this.form.submitWork(route, opinion.opinion, opinion.medias)
- }
- // var opinionField = this.json.opinion || "opinion";
- // var data = this.form.getData();
- // var opinion = data[opinionField];
- // data[opinionField] = "";
- // this.form.submitWork(route, opinion, null, null, data);
- },
- resetWork: function(){
- this.form.resetWork();
- },
- retractWork: function(e, ev){
- this.form.retractWork(e, ev);
- },
- rerouteWork: function(e, ev){
- this.form.rerouteWork(e, ev);
- },
- deleteWork: function(){
- this.form.deleteWork();
- },
- printWork: function(){
- this.form.printWork();
- }
- });
|