HolidayExplorer.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. MWF.xDesktop.requireApp("Attendance", "Explorer", null, false);
  2. MWF.xDesktop.requireApp("Template", "MDomItem", null, false);
  3. MWF.xApplication.Attendance.HolidayExplorer = new Class({
  4. Extends: MWF.xApplication.Attendance.Explorer,
  5. Implements: [Options, Events],
  6. initialize: function(node, app, actions, options){
  7. this.setOptions(options);
  8. this.app = app;
  9. this.path = "../x_component_Attendance/$HolidayExplorer/";
  10. this.cssPath = "../x_component_Attendance/$HolidayExplorer/"+this.options.style+"/css.wcss";
  11. this._loadCss();
  12. this.actions = actions;
  13. this.node = $(node);
  14. this.initData();
  15. if (!this.personActions) this.personActions = new MWF.xAction.org.express.RestActions();
  16. },
  17. loadView : function(){
  18. this.view = new MWF.xApplication.Attendance.HolidayExplorer.View(this.elementContentNode, this.app,this, this.viewData, this.options.searchKey );
  19. this.view.load();
  20. this.setContentSize();
  21. },
  22. createDocument: function(){
  23. if(this.view)this.view._createDocument();
  24. }
  25. });
  26. MWF.xApplication.Attendance.HolidayExplorer.View = new Class({
  27. Extends: MWF.xApplication.Attendance.Explorer.View,
  28. _createItem: function(data){
  29. return new MWF.xApplication.Attendance.HolidayExplorer.Document(this.table, data, this.explorer, this);
  30. },
  31. _getCurrentPageData: function(callback, count){
  32. this.actions.listHolidayAll(function(json){
  33. if (callback) callback(json);
  34. });
  35. },
  36. _removeDocument: function(document, isNotice, callback){
  37. this.actions.listHolidayByYearAndName(document.configYear,document.configName, function( json ){
  38. json.data.each(function(d){
  39. this.actions.deleteHoliday(d.id, function(json){
  40. }.bind(this), null, false);
  41. }.bind(this));
  42. if(!isNotice)this.app.notice(this.app.lp.deleteDocumentOK, "success");
  43. if(callback)callback();
  44. this.explorer.reload();
  45. }.bind(this))
  46. },
  47. _createDocument: function(){
  48. var holiday = new MWF.xApplication.Attendance.HolidayExplorer.Holiday(this.explorer);
  49. holiday.create();
  50. },
  51. _openDocument: function( documentData ){
  52. this.actions.getHoliday( documentData.id, function( json ) {
  53. var data = json.data;
  54. var holidy = {
  55. "configYear" : data.configYear,
  56. "configName" : data.configName,
  57. "makeUpClassDay" : []
  58. };
  59. this.actions.listHolidayByYearAndName(data.configYear,data.configName, function( json ){
  60. var startDate, endDate;
  61. json.data.each(function( d ){
  62. if( d.configType == "Workday" ){
  63. holidy.makeUpClassDay.push( d.configDate )
  64. }else{
  65. if( !startDate ){
  66. startDate = d.configDate;
  67. }else if( new Date(startDate) > new Date(d.configDate) ){
  68. startDate = d.configDate;
  69. }
  70. if( !endDate ){
  71. endDate = d.configDate;
  72. }else if( new Date(endDate) < new Date(d.configDate) ){
  73. endDate = d.configDate;
  74. }
  75. }
  76. }.bind(this));
  77. // holidy.makeUpClassDay = holidy.makeUpClassDay.join(",");
  78. holidy.startDate = startDate;
  79. holidy.endDate = endDate;
  80. var h = new MWF.xApplication.Attendance.HolidayExplorer.Holiday(this.explorer,holidy);
  81. h.edit();
  82. }.bind(this))
  83. }.bind(this))
  84. }
  85. });
  86. MWF.xApplication.Attendance.HolidayExplorer.Document = new Class({
  87. Extends: MWF.xApplication.Attendance.Explorer.Document
  88. });
  89. MWF.xApplication.Attendance.HolidayExplorer.Holiday = new Class({
  90. Extends: MWF.xApplication.Attendance.Explorer.PopupForm,
  91. options : {
  92. "width": 500,
  93. "height": 600,
  94. "hasTop" : true,
  95. "hasBottom" : true,
  96. "title" : MWF.xApplication.Attendance.LP.holiday.setHoliday,
  97. "draggable" : true,
  98. "closeAction" : true,
  99. },
  100. _loadFormCss: function(cssPath){
  101. var css;
  102. var key = encodeURIComponent(cssPath);
  103. if (o2.widget.css[key]){
  104. css = o2.widget.css[key];
  105. }else{
  106. var r = new Request.JSON({
  107. url: o2.filterUrl(cssPath),
  108. secure: false,
  109. async: false,
  110. method: "get",
  111. noCache: false,
  112. onSuccess: function(responseJSON, responseText){
  113. css = responseJSON;
  114. o2.widget.css[key] = responseJSON;
  115. }.bind(this),
  116. onError: function(text, error){
  117. alert(error + text);
  118. }
  119. });
  120. r.send();
  121. }
  122. return css;
  123. },
  124. _createTableContent: function(){
  125. var _self = this;
  126. var lp = this.app.lp.holiday;
  127. var css = this._loadFormCss("../x_component_Template/$MForm/attendance/css.wcss");
  128. debugger;
  129. var inputStyle = "";
  130. for( var key in css.inputText ){
  131. inputStyle += key+":"+ css.inputText[key] + ";"
  132. }
  133. var inputTimeStyle = "";
  134. for( var key in css.inputTime ){
  135. inputTimeStyle += key+":"+ css.inputTime[key] + ";"
  136. }
  137. var makeupClassArea = "";
  138. if( this.data && this.data.makeUpClassDay ){
  139. this.data.makeUpClassDay.each( function ( d, idx ) {
  140. makeupClassArea += "<input type='text' class='makeUpClassDay' " +
  141. "style='" + inputTimeStyle +"'" +
  142. " value='" + ( d || "" ) + "'/>";
  143. if( idx > 0 )makeupClassArea += "<div class='removeMakeUpClassDay' style='color: #354f67;padding-bottom: 5px;cursor: pointer;'>"+this.app.lp.delete+"</div>";
  144. }.bind(this))
  145. }else{
  146. makeupClassArea += "<input type='text' class='makeUpClassDay' " +
  147. "style='" + inputTimeStyle +"'" +
  148. " value='" + ( "" ) + "'/>";
  149. }
  150. var html = "<table width='100%' height='200' border='0' cellPadding='3' cellSpacing='0'>" +
  151. "<tr>"+
  152. "<td style='height: 30px; line-height: 30px; text-align: left; min-width: 80px; width:25%'>" + lp.year + ":</td>" +
  153. "<td style='; text-align: left;' id='yearArea'>"+
  154. //(!this.isNew && !this.isEdited ? "" :
  155. // ("<input type='text' id='configYear' " + "style='" + inputStyle +"'" + " value='" + ( this.data && this.data.configYear ? this.data.configYear : "") + "'/>")) +
  156. "</td>"+
  157. "</tr>" +
  158. "<tr>"+
  159. "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.name+":</td>" +
  160. "<td style='; text-align: right;'>"+
  161. (!this.isNew && !this.isEdited ? "" :
  162. ("<input type='text' id='configName' " + "style='" + inputStyle +"'" + " value='" + ( this.data && this.data.configName ? this.data.configName : "") + "'/>")) +
  163. "</td>" +
  164. "</tr>" +
  165. "<tr>" +
  166. "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.startDate+":</td>" +
  167. "<td style='; text-align: right;'>" +
  168. (!this.isNew && !this.isEdited ? "" :
  169. ("<input type='text' id='startDate' " + "style='" + inputTimeStyle +"'" + " value='" + ( this.data && this.data.startDate ? this.data.startDate : "") + "'/>")) +
  170. "</td>" +
  171. "</tr>" +
  172. "<tr>" +
  173. "<td style='height: 30px; line-height: 30px; text-align: left'>"+lp.endDate+":</td>" +
  174. "<td style='; text-align: right;'>" +
  175. (!this.isNew && !this.isEdited ? "" :
  176. ("<input type='text' id='endDate' " + "style='" + inputTimeStyle +"'" + " value='" + ( this.data && this.data.endDate ? this.data.endDate : "") + "'/>")) +
  177. "</td>" +
  178. "</tr>" +
  179. "<tr>" +
  180. "<td valign='top' style='height: 30px; line-height: 30px; text-align: left'>"+lp.makeUpClassDay+":</td>" +
  181. "<td style='; text-align: right;' id='makeUpClassDayTd'>" +
  182. (!this.isNew && !this.isEdited ? "" :makeupClassArea )+
  183. (!this.isNew && !this.isEdited ? "" : "<div id='addMakeupClass' style='color: #354f67;cursor: pointer;'>"+lp.addMakeUpClassDay+"</div>" )+
  184. "</td>" +
  185. "</tr>" +
  186. "</table>";
  187. this.formTableArea.set("html", html);
  188. //this.configYear = this.formNode.getElement("#configYear");
  189. this.yearArea = this.formNode.getElement("#yearArea");
  190. this.configYear = new MDomItem( this.yearArea, {
  191. "name" : "configYear",
  192. "type" : "select",
  193. "value" : this.data.configYear || new Date().getFullYear(),
  194. "selectValue" : function(){
  195. var years = [];
  196. var year = new Date().getFullYear()+5;
  197. for(var i=0; i<11; i++ ){
  198. years.push( year-- );
  199. }
  200. return years;
  201. }
  202. }, true, this.app, css );
  203. this.configYear.load();
  204. this.configName = this.formNode.getElement("#configName");
  205. this.startDate = this.formNode.getElement("#startDate");
  206. this.endDate = this.formNode.getElement("#endDate");
  207. this.makeUpClassDay = this.formNode.getElements(".makeUpClassDay");
  208. this.removeMakeUpClassDay = this.formNode.getElements(".removeMakeUpClassDay");
  209. this.addMakeupClass = this.formNode.getElement("#addMakeupClass");
  210. this.makeUpClassDayTd = this.formNode.getElement("#makeUpClassDayTd");
  211. this.startDate.addEvent("click",function(){
  212. _self.selectCalendar(this);
  213. });
  214. this.endDate.addEvent("click",function(){
  215. _self.selectCalendar(this);
  216. });
  217. this.makeUpClassDay.addEvent("click",function(){
  218. _self.selectCalendar(this);
  219. });
  220. this.removeMakeUpClassDay.addEvent("click", function () {
  221. var input = this.getPrevious();
  222. if(input && input.get('tag') === "input")input.destroy();
  223. this.destroy();
  224. });
  225. this.addMakeupClass.addEvent("click",function(){
  226. var input = new Element("input",{
  227. class : "makeUpClassDay",
  228. style : inputTimeStyle,
  229. value : "",
  230. events : {
  231. click : function () {
  232. _self.selectCalendar(this);
  233. }
  234. }
  235. }).inject(this, "before");
  236. var div = new Element("div",{
  237. "class" : "removeMakeUpClassDay",
  238. style : "color: #354f67;padding-bottom: 5px;cursor: pointer;",
  239. text : this.app.lp.delete,
  240. events : {
  241. click : function () {
  242. var input = this.getPrevious();
  243. if(input && input.get('tag') === "input")input.destroy();
  244. this.destroy();
  245. }
  246. }
  247. }).inject(this, "before")
  248. });
  249. // this.cancelActionNode = new Element("div", {
  250. // "styles": this.css.createCancelActionNode,
  251. // "text": this.app.lp.cancel
  252. // }).inject(this.formNode);
  253. // this.createOkActionNode = new Element("div", {
  254. // "styles": this.css.createOkActionNode,
  255. // "text": this.app.lp.ok
  256. // }).inject(this.formNode);
  257. //
  258. // this.cancelActionNode.addEvent("click", function(e){
  259. // this.cancelCreate(e);
  260. // }.bind(this));
  261. // this.createOkActionNode.addEvent("click", function(e){
  262. // this.okCreate(e);
  263. // }.bind(this));
  264. },
  265. ok: function(e){
  266. var data = {
  267. "id" : (this.data && this.data.id) ? this.data.id : this.app.restActions.getUUID(),
  268. "configYear": this.configYear.get("value"),
  269. "configName": this.configName.get("value"),
  270. "startDate": this.startDate.get("value"),
  271. "endDate": this.endDate.get("value")
  272. // "makeUpClassDay": this.makeUpClassDay.get("value")
  273. };
  274. if (data.configYear && data.configName && data.startDate && data.endDate ){
  275. var endDate = new Date( data.endDate );
  276. var startDate = new Date( data.startDate );
  277. if( startDate > endDate ){
  278. this.app.notice( this.app.lp.holiday.beginGreateThanEndNotice ,"error");
  279. return;
  280. }
  281. var flag = true;
  282. var save = function(){
  283. var error = "";
  284. this.getDateByRange(startDate,endDate).each(function( date ){
  285. this.app.restActions.saveHoliday({
  286. "configName" : data.configName,
  287. "configYear" : data.configYear,
  288. "configDate": date,
  289. "configType": "Holiday"
  290. }, function(json){
  291. if( json.type == "ERROR" ){error=json.message}
  292. }.bind(this),
  293. function(json){
  294. flag = false;
  295. }.bind(this),false);
  296. }.bind(this));
  297. this.formNode.getElements(".makeUpClassDay").each( function(el){
  298. if(el.get("value")){
  299. this.app.restActions.saveHoliday({
  300. "configName" : data.configName,
  301. "configYear" : data.configYear,
  302. "configDate": this.dateFormat( new Date(el.get("value")),"yyyy-MM-dd"),
  303. "configType": "Workday"
  304. }, function(json){
  305. if( json.type == "ERROR" ){error=json.message}
  306. },function(json){
  307. flag = false;
  308. }.bind(this),false);
  309. }
  310. }.bind(this))
  311. if(error==""){
  312. if( this.formMaskNode )this.formMaskNode.destroy();
  313. if( this.formAreaNode )this.formAreaNode.destroy();
  314. if (this.explorer && this.explorer.view)this.explorer.view.reload();
  315. this.app.notice( this.isNew ? this.app.lp.createSuccess : this.app.lp.updateSuccess , "success");
  316. }else{
  317. this.app.notice( error , "error");
  318. }
  319. }.bind(this);
  320. if(!this.isNew){
  321. this.explorer.view._removeDocument(data, false, save )
  322. }else{
  323. save();
  324. }
  325. }else{
  326. this.configName.setStyle("border-color", "red");
  327. this.configName.focus();
  328. this.app.notice( this.app.lp.holiday.inputValid, "error");
  329. }
  330. },
  331. selectCalendar : function( calendarNode ){
  332. MWF.require("MWF.widget.Calendar", function(){
  333. var calendar = new MWF.widget.Calendar( calendarNode, {
  334. "style": "xform",
  335. "isTime": false,
  336. "target": this.app.content
  337. });
  338. calendar.show();
  339. }.bind(this));
  340. },
  341. getDateByRange : function(startDate, endDate){
  342. var days = [];
  343. while (startDate <= endDate) {
  344. days.push( this.dateFormat(startDate,"yyyy-MM-dd") );
  345. startDate.setDate(startDate.getDate() + 1);
  346. }
  347. return days;
  348. },
  349. dateFormat : function(date, fmt){
  350. var o = {
  351. "M+" : date.getMonth()+1, //月份
  352. "d+" : date.getDate(), //日
  353. "h+" : date.getHours(), //小时
  354. "m+" : date.getMinutes(), //分
  355. "s+" : date.getSeconds(), //秒
  356. "q+" : Math.floor((date.getMonth()+3)/3), //季度
  357. "S" : date.getMilliseconds() //毫秒
  358. };
  359. if(/(y+)/.test(fmt))
  360. fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
  361. for(var k in o)
  362. if(new RegExp("("+ k +")").test(fmt))
  363. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  364. return fmt;
  365. }
  366. });