CronPicker.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. MWF.xApplication.Template = MWF.xApplication.Template || {};
  2. MWF.xApplication.Template.widget = MWF.xApplication.Template.widget || {};
  3. MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  4. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  5. MWF.xApplication.Template.widget.CronPicker = new Class({
  6. Implements: [Options, Events],
  7. Extends: MTooltips,
  8. options: {
  9. style : "default",
  10. axis: "y", //箭头在x轴还是y轴上展现
  11. position : { //node 固定的位置
  12. x : "auto", //x 轴上left center right, auto 系统自动计算
  13. y : "auto" //y轴上top middle bottom, auto 系统自动计算
  14. },
  15. event : "click", //事件类型,有target 时有效, mouseenter对应mouseleave,click 对应 container 的 click
  16. modules : ["second","mintue","hour","date","month","week","year"],
  17. moudulesLp : { second : "秒", mintue : "分钟", hour : "小时", date : "日", month : "月", week : "周", year : "年"},
  18. isShowResult : true,
  19. isShowText : true,
  20. value : ""
  21. },
  22. _loadCornCss: function(reload){
  23. this.cornCssPath = "../x_component_Template/widget/$CronPicker/"+this.options.style+"/css.wcss";
  24. var key = encodeURIComponent(this.cornCssPath);
  25. if (!reload && MWF.widget.css[key]){
  26. this.css = MWF.widget.css[key];
  27. }else{
  28. this.cornCssPath = (this.cornCssPath.indexOf("?")!=-1) ? this.cornCssPath+"&v="+COMMON.version : this.cornCssPath+"?v="+COMMON.version;
  29. var r = new Request.JSON({
  30. url: this.cornCssPath,
  31. secure: false,
  32. async: false,
  33. method: "get",
  34. noCache: false,
  35. onSuccess: function(responseJSON, responseText){
  36. MWF.widget.css[key] = this.css = Object.merge( this.css || {} , responseJSON );
  37. }.bind(this),
  38. onError: function(text, error){
  39. alert(error + text);
  40. }
  41. });
  42. r.send();
  43. }
  44. },
  45. _customNode : function( node ){
  46. this._loadCornCss();
  47. if( this.options.value ){
  48. this.values = this.options.value.split(" ");
  49. }
  50. this.formStyle = "cronpicker" + ( this.options.style == "default" ? "" : ("_"+this.options.style) );
  51. this.tabNode = new Element("div", {styles : this.css.tabNode }).inject( this.contentNode );
  52. this.options.modules.each( function( m , i ){
  53. var tab = this[ m + "Tab" ] = new Element("div", {
  54. text : this.options.moudulesLp[ m ],
  55. styles : this.css.tab
  56. }).inject( this.tabNode );
  57. this[ m + "Node" ] = new Element("div", {
  58. styles : this.css.moduleNode
  59. }).inject(this.contentNode);
  60. this[ "load"+ m.capitalize() +"Form" ]();
  61. tab.addEvents({
  62. click : function(){
  63. var _self = this.obj;
  64. if( _self.currentTab ){
  65. _self.currentTab.setStyles(_self.css.tab );
  66. }
  67. if( _self.currentNode ){
  68. _self.currentNode.setStyles({ "display" : "none" });
  69. }
  70. _self.currentTab = _self[ this.m + "Tab" ];
  71. _self.currentNode = _self[ this.m + "Node" ];
  72. _self[ this.m + "Tab" ].setStyles(_self.css.tab_current);
  73. _self[ this.m + "Node" ].setStyles({ "display" : "" });
  74. }.bind( {obj : this, m : m} ),
  75. mouseover : function(){
  76. var _self = this.obj;
  77. if( _self[ this.m + "Tab" ] != _self.currentTab ){
  78. _self[ this.m + "Tab"].setStyles(_self.css.tab_over);
  79. }
  80. }.bind( {obj : this, m : m} ),
  81. mouseout : function(){
  82. var _self = this.obj;
  83. if( _self[ this.m + "Tab" ] != _self.currentTab ){
  84. _self[ this.m + "Tab"].setStyles(_self.css.tab);
  85. }
  86. }.bind( {obj : this, m : m} )
  87. });
  88. if( i == 0 )tab.click();
  89. }.bind(this));
  90. this.helpNode = new Element("a", {
  91. styles : this.css.helpNode,
  92. href : '../x_component_Template/widget/$CronPicker/cron_express_description.html',
  93. target: '_blank'
  94. }).inject(this.tabNode);
  95. if( this.options.isShowResult ){
  96. //this.createResultNode()
  97. }
  98. //this.resultInput = new Element("input").inject(this.contentNode);
  99. },
  100. setCronValue : function( value ){
  101. var values = value.split(" ");
  102. this.setSecondItemValue( values[0] );
  103. this.setMintueItemValue( values[1] );
  104. this.setHourItemValue( values[2] );
  105. this.setDateItemValue( values[3] );
  106. this.setMonthItemValue( values[4] );
  107. this.setWeekItemValue( values[5] );
  108. if( values.length > 6 )this.setYearItemValue( values[6] );
  109. },
  110. setValue : function(){
  111. var arr = [];
  112. ["second","mintue","hour","date","month","week","year"].each( function( m ){
  113. var value = this["set"+ m.capitalize() + "Value"]();
  114. if( value ){
  115. arr.push(value)
  116. }
  117. }.bind(this));
  118. //this.resultInput.set("value",arr.join(" "));
  119. this.fireEvent("select",[arr.join(" ")]);
  120. },
  121. addZero : function( str, length ){
  122. var zero = "";
  123. str = str.toString();
  124. for( var i=0; i<length; i++ ){
  125. zero = zero + "0";
  126. }
  127. var s = zero + str;
  128. return s.substr(s.length - length, length );
  129. },
  130. loadSecondForm : function(){
  131. var _self = this;
  132. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable' style='margin-top: 10px; '>" +
  133. "<tr><td styles='formTableValue14' style='width:60px;'>" +
  134. " <div item='second'></div>" +
  135. " </td>" +
  136. " <td styles='formTableValue14' style='vertical-align: top;'>" +
  137. " <div>允许的通配符[, - * /]</div>" +
  138. " <div>从 <span item='sfrom'></span>-<span item='sto'></span> 秒</div>" +
  139. " <div>从<span item='sbegin'></span>秒开始,每<span item='scount'></span>秒执行一次</div>" +
  140. " <div></div>" +
  141. "</td></tr>" +
  142. "<tr><td styles='formTableValue14' item='sspecify' colspan='2' style='padding-left: 10px;'></td></tr>" +
  143. "</table>";
  144. this.secondNode.set("html", html);
  145. this.secondForm = new MForm(this.secondNode, {}, {
  146. isEdited: true,
  147. style : this.formStyle,
  148. hasColon : true,
  149. itemTemplate: {
  150. second : { type:"radio" ,selectValue : ["secondly","cycle","from","specify"], selectText: ["每秒","周期","","指定"], defaultValue : "secondly", event : {
  151. click : function(){ this.setValue() }.bind(this)
  152. }},
  153. sfrom : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  154. sto : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  155. sbegin : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  156. scount : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  157. sspecify : { type:"checkbox" , selectText : function(){
  158. var text = [];
  159. for( var i=0; i<60; i++ ){
  160. text.push( _self.addZero( i, 2 ) );
  161. }
  162. return text;
  163. } , selectValue : function(){
  164. var value = [];
  165. for( var i=0; i<60; i++ ){
  166. value.push( i );
  167. }
  168. return value;
  169. } , event : { change : function(){ this.setValue() }.bind(this) } }
  170. }
  171. });
  172. this.secondForm.load();
  173. if( this.values )this.setSecondItemValue( this.values[0] );
  174. },
  175. setSecondValue : function(){
  176. if( !this.secondForm )return "*";
  177. var result = this.secondForm.getResult(false, null, false, false, true);
  178. switch ( result.second ){
  179. case "secondly":
  180. return "*";
  181. break;
  182. case "cycle":
  183. return result.sfrom+"-"+result.sto;
  184. break;
  185. case "from":
  186. return result.sbegin+"/"+result.scount;
  187. break;
  188. case "specify":
  189. return result.sspecify.length ? result.sspecify.join(",") : "?";
  190. break;
  191. default :
  192. return "*";
  193. }
  194. },
  195. setSecondItemValue : function( value ){
  196. if( !value )return;
  197. if( !this.secondForm )return;
  198. if( value == "*" ){
  199. this.secondForm.getItem("second").setValue("secondly");
  200. }else if( value.indexOf("-") > -1 ){
  201. this.secondForm.getItem("second").setValue("cycle");
  202. var arr = value.split("-");
  203. this.secondForm.getItem("sfrom").setValue(arr[0] || "");
  204. this.secondForm.getItem("sto").setValue(arr[1] || "");
  205. }else if( value.indexOf("/") > -1 ){
  206. this.secondForm.getItem("second").setValue("from");
  207. var arr = value.split("/");
  208. this.secondForm.getItem("sbegin").setValue(arr[0] || "");
  209. this.secondForm.getItem("scount").setValue(arr[1] || "");
  210. }else{
  211. this.secondForm.getItem("second").setValue("specify");
  212. this.secondForm.getItem("sspecify").setValue(value.split(","));
  213. }
  214. },
  215. getSecondDefaultValue : function(){
  216. if( this.options.value ){
  217. this.values = this.options.value.split(" ");
  218. }
  219. var d = {
  220. type : "secondly"
  221. };
  222. if( this.values ){
  223. var value = this.values[0];
  224. if( value == "*" ){
  225. }else if( value.indexOf("-") > -1 ){
  226. d.type = "cycle";
  227. var arr = value.split("-");
  228. d.from = arr[0] || "";
  229. d.to = arr[1] || "";
  230. }else if( value.indexOf("/") > -1 ){
  231. d.type = "from";
  232. var arr = value.split("/");
  233. d.sbegin = arr[0] || "";
  234. d.scount = arr[1] || "";
  235. }else{
  236. d.type = "specify";
  237. d.sspecify = value.split(",");
  238. }
  239. }
  240. return d;
  241. },
  242. loadMintueForm : function(){
  243. var _self = this;
  244. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable' style='margin-top: 10px; '>" +
  245. "<tr><td styles='formTableValue14' style='width:80px;'>" +
  246. " <div item='mintue'></div>" +
  247. " </td>" +
  248. " <td styles='formTableValue14' style='vertical-align: top;'>" +
  249. " <div>允许的通配符[, - * /]</div>" +
  250. " <div>从 <span item='mfrom'></span>-<span item='mto'></span> 分钟</div>" +
  251. " <div>从<span item='mbegin'></span>分钟开始,每<span item='mcount'></span>分钟执行一次</div>" +
  252. " <div></div>" +
  253. "</td></tr>" +
  254. "<tr><td styles='formTableValue14' item='mspecify' colspan='2' style='padding-left: 10px;'></td></tr>" +
  255. "</table>";
  256. this.mintueNode.set("html", html);
  257. this.mintueForm = new MForm(this.mintueNode, {}, {
  258. isEdited: true,
  259. style : this.formStyle,
  260. hasColon : true,
  261. itemTemplate: {
  262. mintue : { type:"radio" ,selectValue : ["mintuely","cycle","from","specify"], selectText: ["每分钟","周期","","指定"],defaultValue : "mintuely", event : {
  263. click : function(){ this.setValue() }.bind(this)
  264. }},
  265. mfrom : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  266. mto : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  267. mbegin : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  268. mcount : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  269. mspecify : { type:"checkbox" , selectText : function(){
  270. var text = [];
  271. for( var i=0; i<60; i++ ){
  272. text.push( _self.addZero( i, 2 ) );
  273. }
  274. return text;
  275. }, selectValue : function(){
  276. var value = [];
  277. for( var i=0; i<60; i++ ){
  278. value.push( i );
  279. }
  280. return value;
  281. } , event : { change : function(){ this.setValue() }.bind(this) } }
  282. }
  283. });
  284. this.mintueForm.load();
  285. if( this.values )this.setMintueItemValue( this.values[1] );
  286. },
  287. setMintueValue : function(){
  288. if( !this.mintueForm )return "*";
  289. var result = this.mintueForm.getResult(false, null, false, false, true);
  290. switch ( result.mintue ){
  291. case "mintuely":
  292. return "*";
  293. break;
  294. case "cycle":
  295. return result.mfrom+"-"+result.mto;
  296. break;
  297. case "from":
  298. return result.mbegin+"/"+result.mcount;
  299. break;
  300. case "specify":
  301. return result.mspecify.length ? result.mspecify.join(",") : "?";
  302. break;
  303. default :
  304. return "*";
  305. }
  306. },
  307. setMintueItemValue : function( value ){
  308. if( !value )return;
  309. if( !this.mintueForm )return;
  310. if( value == "*" ){
  311. this.mintueForm.getItem("mintue").setValue("mintuely");
  312. }else if( value.indexOf("-") > -1 ){
  313. this.mintueForm.getItem("mintue").setValue("cycle");
  314. var arr = value.split("-");
  315. this.mintueForm.getItem("mfrom").setValue(arr[0] || "");
  316. this.mintueForm.getItem("mto").setValue(arr[1] || "");
  317. }else if( value.indexOf("/") > -1 ){
  318. this.mintueForm.getItem("mintue").setValue("from");
  319. var arr = value.split("/");
  320. this.mintueForm.getItem("mbegin").setValue(arr[0] || "");
  321. this.mintueForm.getItem("mcount").setValue(arr[1] || "");
  322. }else{
  323. this.mintueForm.getItem("mintue").setValue("specify");
  324. this.mintueForm.getItem("mspecify").setValue(value.split(","));
  325. }
  326. },
  327. loadHourForm : function(){
  328. var _self = this;
  329. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable' style='margin-top: 10px; '>" +
  330. "<tr><td styles='formTableValue14' style='width:80px;'>" +
  331. " <div item='hour'></div>" +
  332. " </td>" +
  333. " <td styles='formTableValue14' style='vertical-align: top;'>" +
  334. " <div>允许的通配符[, - * /]</div>" +
  335. " <div>从 <span item='hfrom'></span>-<span item='hto'></span> 小时</div>" +
  336. " <div>从<span item='hbegin'></span>小时开始,每<span item='hcount'></span>小时执行一次</div>" +
  337. " <div></div>" +
  338. "</td></tr>" +
  339. "<tr><td styles='formTableValue14' item='hspecify' colspan='2' style='padding-left: 10px;'></td></tr>" +
  340. "</table>";
  341. this.hourNode.set("html", html);
  342. this.hourForm = new MForm(this.hourNode, {}, {
  343. isEdited: true,
  344. style : this.formStyle,
  345. hasColon : true,
  346. itemTemplate: {
  347. hour : { type:"radio" ,selectValue : ["hourly","cycle","from","specify"], selectText: ["每小时","周期","","指定"], defaultValue : "hourly", event : {
  348. click : function(){ this.setValue() }.bind(this)
  349. }},
  350. hfrom : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  351. hto : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  352. hbegin : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  353. hcount : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  354. hspecify : { type:"checkbox" , selectText : function(){
  355. var text = [];
  356. for( var i=0; i<24; i++ ){
  357. text.push( _self.addZero( i, 2 ) );
  358. }
  359. return text;
  360. } , selectValue : function(){
  361. var value = [];
  362. for( var i=0; i<24; i++ ){
  363. value.push( i );
  364. }
  365. return value;
  366. } , event : { change : function(){ this.setValue() }.bind(this) } }
  367. }
  368. });
  369. this.hourForm.load();
  370. if( this.values )this.setHourItemValue( this.values[2] );
  371. },
  372. setHourValue : function(){
  373. if( !this.hourForm )return "*";
  374. var result = this.hourForm.getResult(false, null, false, false, true);
  375. switch ( result.hour ){
  376. case "hourly":
  377. return "*";
  378. break;
  379. case "cycle":
  380. return result.hfrom+"-"+result.hto;
  381. break;
  382. case "from":
  383. return result.hbegin+"/"+result.hcount;
  384. break;
  385. case "specify":
  386. return result.hspecify.length ? result.hspecify.join(",") : "?";
  387. break;
  388. default :
  389. return "*";
  390. }
  391. },
  392. setHourItemValue : function( value ){
  393. if( !value )return;
  394. if( !this.hourForm )return;
  395. if( value == "*" ){
  396. this.hourForm.getItem("hour").setValue("hourly");
  397. }else if( value.indexOf("-") > -1 ){
  398. this.hourForm.getItem("hour").setValue("cycle");
  399. var arr = value.split("-");
  400. this.hourForm.getItem("hfrom").setValue(arr[0] || "");
  401. this.hourForm.getItem("hto").setValue(arr[1] || "");
  402. }else if( value.indexOf("/") > -1 ){
  403. this.hourForm.getItem("hour").setValue("from");
  404. var arr = value.split("/");
  405. this.hourForm.getItem("hbegin").setValue(arr[0] || "");
  406. this.hourForm.getItem("hcount").setValue(arr[1] || "");
  407. }else{
  408. this.hourForm.getItem("hour").setValue("specify");
  409. this.hourForm.getItem("hspecify").setValue(value.split(","));
  410. }
  411. },
  412. loadDateForm : function(){
  413. var _self = this;
  414. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable' style='margin-top: 10px; '>" +
  415. "<tr><td styles='formTableValue14' style='width:120px;'>" +
  416. " <div item='date'></div>" +
  417. " </td>" +
  418. " <td styles='formTableValue14' style='vertical-align: top;'>" +
  419. " <div>允许的通配符[, - * / L W ?]</div>" +
  420. " <div> </div>" +
  421. " <div>从 <span item='dfrom'></span>-<span item='dto'></span> 日</div>" +
  422. " <div>从<span item='dbegin'></span>日开始,每<span item='dcount'></span>天执行一次</div>" +
  423. " <div>每月<span item='dnearly'></span>号最近的那个工作日</div>" +
  424. " <div></div>" +
  425. " <div></div>" +
  426. "</td></tr>" +
  427. "<tr><td styles='formTableValue14' item='dspecify' colspan='2' style='padding-left: 10px;'></td></tr>" +
  428. "</table>";
  429. this.dateNode.set("html", html);
  430. this.dateForm = new MForm(this.dateNode, {}, {
  431. isEdited: true,
  432. style : this.formStyle,
  433. hasColon : true,
  434. itemTemplate: {
  435. date : { type:"radio" ,selectValue : ["daily","notspecify","cycle","from", "nearly", "last","specify"], selectText: ["每天","不指定","周期","","","本月最后一天","指定"], defaultValue : "daily", event : {
  436. click : function(){ this.setValue() }.bind(this)
  437. }},
  438. dfrom : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  439. dto : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  440. dbegin : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  441. dcount : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  442. dnearly : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  443. dspecify : { type:"checkbox" , selectText : function(){
  444. var text = [];
  445. for( var i=1; i<32; i++ ){
  446. text.push( _self.addZero( i, 2 ) );
  447. }
  448. return text;
  449. }, selectValue : function(){
  450. var value = [];
  451. for( var i=1; i<32; i++ ){
  452. value.push( i );
  453. }
  454. return value;
  455. } , event : { change : function(){ this.setValue() }.bind(this) } }
  456. }
  457. });
  458. this.dateForm.load();
  459. if( this.values )this.setDateItemValue( this.values[3] );
  460. },
  461. setDateValue : function(){
  462. if( !this.dateForm )return "*";
  463. var result = this.dateForm.getResult(false, null, false, false, true);
  464. switch ( result.date ){
  465. case "daily":
  466. return "*";
  467. break;
  468. case "notspecify":
  469. return "?";
  470. break;
  471. case "cycle":
  472. return result.dfrom+"-"+result.dto;
  473. break;
  474. case "from":
  475. return result.dbegin+"/"+result.dcount;
  476. break;
  477. case "nearly":
  478. return result.dnearly+"W";
  479. break;
  480. case "last":
  481. return "L";
  482. break;
  483. case "specify":
  484. return result.dspecify.length ? result.dspecify.join(",") : "?";
  485. break;
  486. default :
  487. return "*";
  488. }
  489. },
  490. setDateItemValue : function( value ){
  491. if( !value )return;
  492. if( !this.dateForm )return;
  493. if( value == "*" ) {
  494. this.dateForm.getItem("date").setValue("daily");
  495. }else if( value == "?" ){
  496. this.dateForm.getItem("date").setValue("notspecify");
  497. }else if( value.indexOf("-") > -1 ){
  498. this.dateForm.getItem("date").setValue("cycle");
  499. var arr = value.split("-");
  500. this.dateForm.getItem("dfrom").setValue(arr[0] || "");
  501. this.dateForm.getItem("dto").setValue(arr[1] || "");
  502. }else if( value.indexOf("/") > -1 ){
  503. this.dateForm.getItem("date").setValue("from");
  504. var arr = value.split("/");
  505. this.dateForm.getItem("dbegin").setValue(arr[0] || "");
  506. this.dateForm.getItem("dcount").setValue(arr[1] || "");
  507. }else if( value.substr(value.length-1,1) == "W" ){
  508. this.dateForm.getItem("date").setValue("nearly");
  509. var dnearly = value.substr( 0, value.length - 1 );
  510. this.dateForm.getItem("dnearly").setValue(dnearly);
  511. }else if( value == "L" ){
  512. this.dateForm.getItem("date").setValue("last");
  513. }else{
  514. this.dateForm.getItem("date").setValue("specify");
  515. this.dateForm.getItem("dspecify").setValue(value.split(","));
  516. }
  517. },
  518. loadMonthForm : function(){
  519. var _self = this;
  520. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable' style='margin-top: 10px; '>" +
  521. "<tr><td styles='formTableValue14' style='width:80px;'>" +
  522. " <div item='month'></div>" +
  523. " </td>" +
  524. " <td styles='formTableValue14' style='vertical-align: top;'>" +
  525. " <div>允许的通配符[, - * / ?]</div>" +
  526. " <div> </div>" +
  527. " <div>从 <span item='mofrom'></span>-<span item='moto'></span> 月</div>" +
  528. " <div>从<span item='mobegin'></span>月开始,每<span item='mocount'></span>月执行一次</div>" +
  529. " <div></div>" +
  530. "</td></tr>" +
  531. "<tr><td styles='formTableValue14' item='mospecify' colspan='2' style='padding-left: 10px;'></td></tr>" +
  532. "</table>";
  533. this.monthNode.set("html", html);
  534. this.monthForm = new MForm(this.monthNode, {}, {
  535. isEdited: true,
  536. style : this.formStyle,
  537. hasColon : true,
  538. itemTemplate: {
  539. month : { type:"radio" ,selectValue : ["monthly","notspecify","cycle","from", "specify"], selectText: ["每月","不指定","周期","","指定"], defaultValue : "monthly", event : {
  540. click : function(){ this.setValue() }.bind(this)
  541. }},
  542. mofrom : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  543. moto : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  544. mobegin : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  545. mocount : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  546. monearly : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  547. mospecify : { type:"checkbox" , selectText : function( ){
  548. var text = [];
  549. for( var i=1; i<13; i++ ){
  550. text.push( _self.addZero( i, 2 ) );
  551. }
  552. return text;
  553. } , selectValue : function(){
  554. var value = [];
  555. for( var i=1; i<13; i++ ){
  556. value.push( i );
  557. }
  558. return value;
  559. }, event : { change : function(){ this.setValue() }.bind(this) } }
  560. }
  561. });
  562. this.monthForm.load();
  563. if( this.values )this.setMonthItemValue( this.values[4] );
  564. },
  565. setMonthValue : function(){
  566. if( !this.monthForm )return "*";
  567. var result = this.monthForm.getResult(false, null, false, false, true);
  568. switch ( result.month ){
  569. case "monthly":
  570. return "*";
  571. break;
  572. case "notspecify":
  573. return "?";
  574. break;
  575. case "cycle":
  576. return result.mofrom+"-"+result.moto;
  577. break;
  578. case "from":
  579. return result.mobegin+"/"+result.mocount;
  580. break;
  581. case "specify":
  582. return result.mospecify.length ? result.mospecify.join(",") : "?";
  583. break;
  584. default :
  585. return "*";
  586. }
  587. },
  588. setMonthItemValue : function( value ){
  589. if( !value )return;
  590. if( !this.monthForm )return;
  591. if( value == "*" ) {
  592. this.monthForm.getItem("month").setValue("monthly");
  593. }else if( value == "?" ){
  594. this.monthForm.getItem("month").setValue("notspecify");
  595. }else if( value.indexOf("-") > -1 ){
  596. this.monthForm.getItem("month").setValue("cycle");
  597. var arr = value.split("-");
  598. this.monthForm.getItem("mofrom").setValue(arr[0] || "");
  599. this.monthForm.getItem("moto").setValue(arr[1] || "");
  600. }else if( value.indexOf("/") > -1 ){
  601. this.monthForm.getItem("month").setValue("from");
  602. var arr = value.split("/");
  603. this.monthForm.getItem("mobegin").setValue(arr[0] || "");
  604. this.monthForm.getItem("mocount").setValue(arr[1] || "");
  605. }else{
  606. this.monthForm.getItem("month").setValue("specify");
  607. this.monthForm.getItem("mospecify").setValue(value.split(","));
  608. }
  609. },
  610. loadWeekForm : function(){
  611. var _self = this;
  612. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable' style='margin-top: 10px; '>" +
  613. "<tr><td styles='formTableValue14' style='width:80px;'>" +
  614. " <div item='week'></div>" +
  615. " </td>" +
  616. " <td styles='formTableValue14' style='vertical-align: top;'>" +
  617. " <div>允许的通配符[, - * / L # ?]</div>" +
  618. " <div> </div>" +
  619. " <div>从星期 <span item='wfrom'></span>-<span item='wto'></span> </div>" +
  620. " <div>第<span item='wnumber'></span>周的星期<span item='wday'></span></div>" +
  621. " <div>本月最后一个星期<span item='wlast'></span></div>" +
  622. " <div></div>" +
  623. "</td></tr>" +
  624. "<tr><td styles='formTableValue14' item='wspecify' colspan='2' style='padding-left: 10px;'></td></tr>" +
  625. "</table>";
  626. this.weekNode.set("html", html);
  627. this.weekForm = new MForm(this.weekNode, {}, {
  628. isEdited: true,
  629. style : this.formStyle,
  630. hasColon : true,
  631. itemTemplate: {
  632. week : { type:"radio" ,selectValue : ["weekly","notspecify","cycle","from", "last","specify"], selectText: ["每周","不指定","周期","","","指定"], defaultValue : "notspecify", event : {
  633. click : function(){ this.setValue() }.bind(this)
  634. }},
  635. wfrom : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  636. wto : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  637. wnumber : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  638. wday : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  639. wlast : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  640. wspecify : { type:"checkbox" , selectText : function(){
  641. var text = [];
  642. for( var i=1; i<8; i++ ){
  643. text.push( _self.addZero( i, 2 ) );
  644. }
  645. return text;
  646. } , selectValue : function(){
  647. var value = [];
  648. for( var i=1; i<8; i++ ){
  649. value.push( i );
  650. }
  651. return value;
  652. } , event : { change : function(){ this.setValue() }.bind(this) } }
  653. }
  654. });
  655. this.weekForm.load();
  656. if( this.values )this.setWeekItemValue( this.values[5] );
  657. },
  658. setWeekValue : function(){
  659. if( !this.weekForm )return "?";
  660. var result = this.weekForm.getResult(false, null, false, false, true);
  661. switch ( result.week ){
  662. case "weekly":
  663. return "*";
  664. break;
  665. case "notspecify":
  666. return "?";
  667. break;
  668. case "cycle":
  669. return result.wfrom+"-"+result.wto;
  670. break;
  671. case "from":
  672. return result.wnumber+"/"+result.wday;
  673. break;
  674. case "last":
  675. return result.wlast + "L";
  676. break;
  677. case "specify":
  678. return result.wspecify.length ? result.wspecify.join(",") : "?";
  679. break;
  680. default :
  681. return "?";
  682. }
  683. },
  684. setWeekItemValue : function( value ){
  685. if( !value )return;
  686. if( !this.weekForm )return;
  687. if( value == "*" ) {
  688. this.weekForm.getItem("week").setValue("weekly");
  689. }else if( value == "?" ){
  690. this.weekForm.getItem("week").setValue("notspecify");
  691. }else if( value.indexOf("-") > -1 ){
  692. this.weekForm.getItem("week").setValue("cycle");
  693. var arr = value.split("-");
  694. this.weekForm.getItem("wfrom").setValue(arr[0] || "");
  695. this.weekForm.getItem("wto").setValue(arr[1] || "");
  696. }else if( value.indexOf("/") > -1 ){
  697. this.weekForm.getItem("week").setValue("from");
  698. var arr = value.split("/");
  699. this.weekForm.getItem("wbegin").setValue(arr[0] || "");
  700. this.weekForm.getItem("wcount").setValue(arr[1] || "");
  701. }else if( value.substr(value.length-1,1) == "L" ){
  702. this.weekForm.getItem("week").setValue("last");
  703. var wlast = value.substr( 0, value.length - 1 );
  704. this.weekForm.getItem("wlast").setValue(wlast);
  705. }else{
  706. this.weekForm.getItem("week").setValue("specify");
  707. this.weekForm.getItem("wspecify").setValue(value.split(","));
  708. }
  709. },
  710. loadYearForm : function(){
  711. var _self = this;
  712. var html = "<table width='100%' bordr='0' cellpadding='0' cellspacing='0' styles='formTable' style='margin-top: 10px; '>" +
  713. "<tr><td styles='formTableValue14' style='width:80px;'>" +
  714. " <div item='year'></div>" +
  715. " </td>" +
  716. " <td styles='formTableValue14' style='vertical-align: top;'>" +
  717. " <div>允许的通配符[, - * /] 非必填</div>" +
  718. " <div> </div>" +
  719. " <div>从<span item='yfrom'></span>-<span item='yto'></span>年</div>" +
  720. "</td></tr>" +
  721. "</table>";
  722. this.yearNode.set("html", html);
  723. this.yearForm = new MForm(this.yearNode, {}, {
  724. isEdited: true,
  725. style : this.formStyle,
  726. hasColon : true,
  727. itemTemplate: {
  728. year : { type:"radio" ,selectValue : ["notspecify","yearly","cycle"], selectText: ["不指定","每年","周期"], defaultValue : "notspecify", event : {
  729. click : function(){ this.setValue() }.bind(this)
  730. }},
  731. yfrom : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } },
  732. yto : { tType : "number", event : { blur : function(){ this.setValue() }.bind(this) } }
  733. }
  734. });
  735. this.yearForm.load();
  736. if( this.values && this.values.length > 6 )this.setYearItemValue( this.values[6] );
  737. },
  738. setYearValue : function(){
  739. if( !this.yearForm )return "";
  740. var result = this.yearForm.getResult(false, null, false, false, true);
  741. switch ( result.year ){
  742. case "notspecify":
  743. return "";
  744. break;
  745. case "yearly":
  746. return "*";
  747. break;
  748. case "cycle":
  749. return result.yfrom+"-"+result.yto;
  750. break;
  751. default :
  752. return "";
  753. }
  754. },
  755. setYearItemValue : function( value ){
  756. if( !value )return;
  757. if( !this.yearForm )return;
  758. if( value == "*" ) {
  759. this.yearForm.getItem("year").setValue("yearly");
  760. }else if( value == "?" ){
  761. this.yearForm.getItem("year").setValue("notspecify");
  762. }else if( value.indexOf("-") > -1 ) {
  763. this.yearForm.getItem("year").setValue("cycle");
  764. var arr = value.split("-");
  765. this.yearForm.getItem("yfrom").setValue(arr[0] || "");
  766. this.yearForm.getItem("yto").setValue(arr[1] || "");
  767. }
  768. }
  769. });