BpmNodeRule.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. //更新规则内容
  2. function updateContent(item,data){
  3. var nobr = $('<div class="nobr" style="float:left;margin-right:-999em;"></div>'),
  4. flowVarsSelect = $("#flowVarsSelect").clone(true).removeAttr("id"),
  5. paramKey = $("#paramKey").clone(true).removeAttr("id"),
  6. paramCondition = $("#paramCondition").clone(true).removeAttr("id"),
  7. paramValue = $("#paramValue").clone(true).removeAttr("id"),
  8. ruleType;
  9. if(!data){
  10. ruleType= "1";
  11. }
  12. else{
  13. ruleType = data.ruleType;
  14. }
  15. //普通规则
  16. if(ruleType=='1'){
  17. labelSpan = $('<span class="label-span left"></span>').attr("ruleType",ruleType).text('普通规则');
  18. nobr.append(labelSpan).append(flowVarsSelect).append($('<div class="judge left margin-set"></div>'));
  19. $("div.nobr",item).remove();
  20. item.append(nobr);
  21. if(data){
  22. flowVarsSelect.val(data.flowvarKey).trigger("change");
  23. var judgeExp = $("div.judgeExp",item),
  24. judgeExp2 = $("div.judgeExp2",item);
  25. if(judgeExp){
  26. setJudgeValue(judgeExp,data.judgeCon1,true);
  27. setJudgeValue(judgeExp,data.judgeVal1,false);
  28. }
  29. if(judgeExp2){
  30. setJudgeValue(judgeExp2,data.judgeCon2,true);
  31. setJudgeValue(judgeExp2,data.judgeVal2,false);
  32. }
  33. }
  34. }
  35. //脚本规则
  36. else if(ruleType=='2'){
  37. labelSpan = $('<span class="label-span left"></span>').attr("ruleType",ruleType).text('脚本规则');
  38. var judge = $('<div class="judge left margin-set"></div>').append($('<a name="script" href="###" onclick="editConditionScript(this)">脚本</a>'));
  39. nobr.append(labelSpan).append(judge);
  40. $("div.nobr",item).remove();
  41. item.append(nobr);
  42. if(data.script){
  43. item.data("script",data.script);
  44. }
  45. else if(typeof data.script==='undefined'){
  46. addConditionScript(item);
  47. }
  48. }
  49. else {//组织属性、用户属性
  50. if(ruleType=='3'){
  51. labelSpan = $('<span class="label-span left"></span>').attr("ruleType",ruleType).text('用户属性');
  52. }
  53. else {
  54. labelSpan = $('<span class="label-span left"></span>').attr("ruleType",ruleType).text('组织属性');
  55. }
  56. nobr.append(labelSpan).append(paramKey).append(paramCondition).append(paramValue);
  57. $("div.nobr",item).remove();
  58. item.append(nobr);
  59. if(data) {
  60. paramKey.val(data.paramKey);
  61. paramCondition.val(data.paramCondition);
  62. paramValue.val(data.paramValue);
  63. }
  64. }
  65. };
  66. /**
  67. * 添加条件脚本规则
  68. * @param obj
  69. */
  70. function addConditionScript(item){
  71. var defId = $("#defId").val();
  72. ConditionScriptEditDialog({
  73. data:{
  74. defId:defId
  75. },
  76. callback:function(data){
  77. item.data("script",data.script);
  78. }
  79. });
  80. };
  81. /**
  82. * 编辑条件脚本规则
  83. * @param obj
  84. */
  85. function editConditionScript(t){
  86. var me=$(t),
  87. defId = $("#defId").val(),
  88. item = me.parent().parent().parent(),
  89. script = item.data("script");
  90. ConditionScriptEditDialog({
  91. data:{
  92. defId:defId,
  93. script:script
  94. },
  95. callback:function(data){
  96. item.data("script",data.script);
  97. }
  98. });
  99. };
  100. //获取流程变量的类型识别码
  101. function getFlowVarType(opt){
  102. var value = opt.val(),
  103. ctltype = opt.attr("ctltype"),
  104. ftype = opt.attr("ftype");
  105. //流程变量
  106. if(ctltype){
  107. switch(ctltype.toString()){
  108. //用户、角色、岗位、组织选择器
  109. case "4":
  110. case "5":
  111. case "6":
  112. case "7":
  113. case "8":
  114. case "17":
  115. case "18":
  116. case "19":
  117. return 5;
  118. //字典
  119. case "3":
  120. case "11":
  121. case "13":
  122. case "14":
  123. return 4;
  124. //日期
  125. case "15":
  126. return 3;
  127. }
  128. }
  129. //发起人
  130. if(value=="startUser")
  131. return 5;
  132. if(ftype){
  133. //根据变量类型识别
  134. switch(ftype.toLowerCase()){
  135. case "int":
  136. case "number":
  137. return 1;
  138. case "varchar":
  139. case "string":
  140. return 2;
  141. case "date":
  142. return 3;
  143. }
  144. }
  145. return 2;
  146. };
  147. //获取字典类型的 条件值 控件
  148. function getDicControl(option){
  149. var value = option.val(),
  150. ctltype = option.attr("ctltype"),
  151. chosenopt = option.attr("chosenopt"),
  152. opts = eval("("+chosenopt+")"),
  153. html = '',
  154. data = [],
  155. type = "";
  156. var tempHtml = $("#dic-radio-checkbox").val();
  157. if(ctltype.toString()=='13')
  158. type = "checkbox";
  159. else if(ctltype.toString()=='14')
  160. type = "radio";
  161. else{
  162. tempHtml = $("#dic-select").val();
  163. }
  164. for(var i=0,c;c=opts[i++];){
  165. data.push({type:type,name:value,option:c.key,memo:c.value});
  166. }
  167. html = easyTemplate(tempHtml,data).toString();
  168. return $(html);
  169. };
  170. //获取不同类型的选择器
  171. function getSelector(option){
  172. var ctltype = option.attr("ctltype"),
  173. value = option.val(),
  174. str = "user-div";
  175. switch(ctltype.toString()){
  176. case "4"://用户单选
  177. case "8"://用户多选
  178. str = "user-div";
  179. break;
  180. case "5"://角色
  181. case "17"://角色
  182. str = "role-div";
  183. break;
  184. case "6"://组织
  185. case "18"://组织
  186. str = "org-div";
  187. break;
  188. case "7"://岗位
  189. case "19"://岗位
  190. str = "position-div";
  191. break;
  192. }
  193. var control = $("#"+str).clone(true,true).removeAttr("id");
  194. $("input[type='text']",control).attr("name",value);
  195. $("input[type='hidden']",control).attr("name",value+"ID");
  196. $("a.link",control).attr("name",value);
  197. return control;
  198. };
  199. //获取判定值表达式
  200. function getJudgeExp(optType,option){
  201. var datefmt = option.attr("datefmt"),
  202. expDiv = $('<div class="judgeExp left"></div>'),
  203. judgeCon = $("#judgeCon-"+optType).clone(true).removeAttr("id"),
  204. input;
  205. if(!judgeCon||judgeCon.length==0){
  206. judgeCon = $("#judgeCon-1").clone(true).removeAttr("id");
  207. }
  208. expDiv.attr("optType",optType).append(judgeCon);
  209. switch(optType){
  210. case 1:
  211. case 2:
  212. input = $("#normal-input").clone(true).removeAttr("id");
  213. break;
  214. case 3:
  215. input = $("#date-input").clone(true).removeAttr("id").attr("datefmt",datefmt);
  216. break;
  217. case 4:
  218. input = getDicControl(option);
  219. break;
  220. case 5:
  221. input = getSelector(option).children();
  222. break;
  223. }
  224. expDiv.append(input);
  225. return expDiv;
  226. };
  227. //流程变量选择事件
  228. function flowVarChange(){
  229. var me = $(this),
  230. nobr = me.parents("div.nobr"),
  231. option = me.find("option:selected");
  232. if(!option.val())return;
  233. var optType = getFlowVarType(option),
  234. datefmt = option.attr("datefmt"),
  235. judgeCon = null;
  236. var judgeDiv = $("div.judge",nobr).empty(),
  237. judgeExp = getJudgeExp(optType,option);
  238. judgeDiv.append(judgeExp);
  239. if(optType==1||optType==3){
  240. var judgeExp2 = judgeExp.clone(true).removeClass("judgeExp").addClass("judgeExp2");
  241. judgeDiv.append(judgeExp2);
  242. }
  243. };
  244. //获取判定值
  245. function getJudgeValue(p){
  246. if(!p)return false;
  247. var val = [];
  248. p.find("input").each(function(){
  249. var me = $(this),
  250. type = me.attr("type");
  251. if(type=="checkbox"||type=="radio"){
  252. if(me.attr("checked"))
  253. val.push(me.val());
  254. }
  255. else
  256. val.push(me.val());
  257. });
  258. p.find("select").each(function(){
  259. var me = $(this),
  260. name = me.attr("name");
  261. if(name=="judgeCondition")return true;
  262. val.push(me.val());
  263. });
  264. return val.join('&&');
  265. };
  266. //获取判定text
  267. function getJudgeText(p){
  268. if(!p)return '';
  269. var val = [];
  270. p.find("input:visible").each(function(){
  271. var me = $(this),
  272. type = me.attr("type");
  273. if(type=="checkbox"||type=="radio"){
  274. if(me.attr("checked")){
  275. val.push(me.parent().text());
  276. }
  277. }
  278. else
  279. val.push(me.val());
  280. });
  281. p.find("select").each(function(){
  282. var me = $(this),
  283. name = me.attr("name");
  284. if(name=="judgeCondition")return true;
  285. val.push(me.find("option:selected").text());
  286. });
  287. return val.join('&&');
  288. };
  289. //设置判定值
  290. function setJudgeValue(p,val,isJudgeCon){
  291. if(!p)return;
  292. if(!isJudgeCon){
  293. p.find("input").each(function(){
  294. var me = $(this),
  295. value = me.val(),
  296. type = me.attr("type");
  297. if(type=="checkbox"||type=="radio"){
  298. if(val.indexOf(value)>-1){
  299. me.attr("checked","checked");
  300. }
  301. }
  302. else{
  303. if(/\&\&/.test(val)){
  304. var vals = val.split(/\&\&/);
  305. if(me.attr("type")=="hidden")
  306. me.val(vals[0]);
  307. else
  308. me.val(vals[1]);
  309. }
  310. else
  311. me.val(val);
  312. }
  313. });
  314. }
  315. p.find("select").each(function(){
  316. var me = $(this),
  317. name = me.attr("name");
  318. if((name=="judgeCondition")==isJudgeCon){
  319. me.val(val);
  320. }
  321. });
  322. };
  323. /**
  324. * rule生成json
  325. * @params item
  326. * @returns {Object}
  327. */
  328. function rule2json(item){
  329. var jobject = {},
  330. ruleType = $("span.label-span",item).attr("ruleType");
  331. //普通规则
  332. if(ruleType=="1"){
  333. var flowvarKey = $("select[name='flowVars']",item).val(),
  334. flowvarText = $("select[name='flowVars']",item).find("option:selected").text(),
  335. judgeExp = $("div.judgeExp",item),
  336. judgeExp2 = $("div.judgeExp2",item),
  337. conDesc = [];
  338. if(!judgeExp||judgeExp.length==0)return null;
  339. conDesc.push(flowvarText);
  340. var optType = judgeExp.attr("optType");
  341. jobject.optType = optType;
  342. jobject.flowvarKey = flowvarKey;
  343. jobject.judgeCon1 = $("select[name='judgeCondition']",judgeExp).val();
  344. conDesc.push($("select[name='judgeCondition']",judgeExp).find("option:selected").text());
  345. jobject.judgeVal1 = getJudgeValue(judgeExp);
  346. conDesc.push(getJudgeText(judgeExp));
  347. if(judgeExp2&&judgeExp2.length>0){
  348. jobject.judgeCon2 = $("select[name='judgeCondition']",judgeExp2).val();
  349. conDesc.push('并且');
  350. conDesc.push($("select[name='judgeCondition']",judgeExp2).find("option:selected").text());
  351. jobject.judgeVal2 = getJudgeValue(judgeExp2);
  352. conDesc.push(getJudgeText(judgeExp2));
  353. }
  354. jobject.conDesc = conDesc.join(' ');
  355. }
  356. //脚本规则
  357. else if(ruleType=='2'){
  358. var script = item.data("script");
  359. jobject.script = script;
  360. jobject.conDesc = ' 脚本 ';
  361. }
  362. else{//ruleType=3:用户属性 ruleType=4:组织属性
  363. var conDesc = [];
  364. var paramKey = $("select[name='paramKey']",item).val(),
  365. dataType = $("select[name='paramKey']",item).find("option:selected").attr("title");
  366. var paramCondition = $("select[name='paramCondition']",item).val();
  367. var paramValue = $("input[name='paramValue']",item).val();
  368. jobject.paramKey = paramKey;
  369. jobject.paramCondition = paramCondition;
  370. jobject.paramValue = paramValue;
  371. conDesc.push(paramKey);
  372. conDesc.push(paramCondition);
  373. conDesc.push(paramValue);
  374. jobject.conDesc = conDesc.join(' ');
  375. jobject.expression = paramKey+paramCondition+paramValue;
  376. jobject.dataType = dataType;
  377. }
  378. jobject.ruleType = ruleType;
  379. var compType = $("select.computing-select",item).val();
  380. if(compType){
  381. //运算类型
  382. jobject.compType = compType;
  383. }
  384. return jobject;
  385. };