Calendar.js 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500
  1. o2.widget = o2.widget || {};
  2. o2.widget.Calendar = o2.Calendar = new Class({
  3. Implements: [Options, Events],
  4. Extends: o2.widget.Common,
  5. options: {
  6. "style": "default",
  7. "path": o2.session.path+"/widget/$Calendar/" ,
  8. "defaultView": "day", //day, month, year
  9. "baseDate": new Date(),
  10. "secondEnable" : false,
  11. "timeSelectType" : "slider",
  12. "isTime": false,
  13. "isMulti": false,
  14. "before": null,
  15. "after": null,
  16. "timeOnly": false,
  17. "yearOnly" : false,
  18. "monthOnly": false,
  19. "defaultDate": null,
  20. "beforeCurrent": true,
  21. "clearEnable": true,
  22. "range": false,
  23. "rangeNodes": [],
  24. "rangeRule": "asc", //asc + , des -
  25. "target": null,
  26. // "enableDate": function (date) { //一个function,参数为日期,return true不可选
  27. // return date > new Date();
  28. // },
  29. // "enableHours": function (date) {
  30. // if( date > new Date() ){
  31. // return [];
  32. // }else{
  33. // return [[0, 8], [16, 24]];
  34. // }
  35. //}, //一个function, 参数为日期
  36. // "enableMinutes": null, //一个function, 参数为日期,hour
  37. // "enableSeconds": null, //一个function, 参数为日期,hour,minutes
  38. },
  39. initialize: function(node, options){
  40. Locale.use("zh-CHS");
  41. this.setOptions(options);
  42. this.options.defaultTime = ""+this.options.baseDate.getHours()+":"+this.options.baseDate.getMinutes()+":"+this.options.baseDate.getSeconds();
  43. this.path = o2.session.path+"/widget/$Calendar/";
  44. this.cssPath = o2.session.path+"/widget/$Calendar/"+this.options.style+"/css.wcss";
  45. this._loadCss();
  46. // this.options.containerPath = this.path+this.style+"/container.html";
  47. // this.options.dayPath = this.path+this.style+"/day.html";
  48. // this.options.monthPath = this.path+this.style+"/month.html";
  49. // this.options.yearPath = this.path+this.style+"/year.html";
  50. // this.options.timePath = this.path+this.style+"/time.html";
  51. if (!this.options.format){
  52. if (this.options.isTime){
  53. //this.options.format = Locale.get("Date").shortDate + " " + Locale.get("Date").shortTime;
  54. if(this.options.timeOnly){
  55. this.options.format="%H:%M";
  56. }
  57. else{
  58. this.options.format = Locale.get("Date").shortDate + " " + "%H:%M";
  59. }
  60. }else{
  61. this.options.format = Locale.get("Date").shortDate;
  62. }
  63. }
  64. this.options.containerPath = this.options.path+this.options.style+"/container.html";
  65. this.options.dayPath = this.options.path+this.options.style+"/day.html";
  66. this.options.monthPath = this.options.path+this.options.style+"/month.html";
  67. this.options.yearPath = this.options.path+this.options.style+"/year.html";
  68. this.options.timePath = this.options.path+this.options.style+"/time.html";
  69. this.today = new Date();
  70. this.currentView = this.options.defaultView;
  71. this.node = $(node);
  72. this.visible = false;
  73. this.setRange();
  74. this.container = this.createContainer();
  75. this.container.inject((this.options.target) || $(document.body));
  76. this.contentTable = this.createContentTable();
  77. this.contentTable.inject(this.contentDateNode);
  78. this.addEvents();
  79. this.container.set({
  80. styles: {
  81. "display": "none",
  82. "opacity": 1
  83. }
  84. });
  85. this.fireEvent("init");
  86. //this.move = true;
  87. //this.containerDrag = new Drag.Move(this.container);
  88. if( layout.mobile ){
  89. this.maskNode = new Element("div.maskNode",{
  90. styles : {
  91. "width": "100%",
  92. "height": "100%",
  93. "opacity": 0.6,
  94. "position": "absolute",
  95. "background-color": "#CCC",
  96. "top": "0px",
  97. "left": "0px",
  98. "z-index" : 150,
  99. "-webkit-user-select": "none",
  100. "-moz-user-select": "none",
  101. "user-select" : "none"
  102. },
  103. events : {
  104. "touchmove" : function(ev){
  105. ev.stopPropagation();
  106. ev.preventDefault();
  107. }
  108. }
  109. }).inject((this.options.target) || $(document.body));
  110. this.container.addEvents({
  111. "touchmove" : function(ev){
  112. ev.stopPropagation();
  113. ev.preventDefault();
  114. },
  115. "touchend" : function(ev){
  116. ev.stopPropagation();
  117. //ev.preventDefault();
  118. }
  119. })
  120. }
  121. },
  122. addEvents: function(){
  123. this.node.addEvent("focus", function(){
  124. this.show();
  125. }.bind(this));
  126. this.node.addEvent("click", function(){
  127. this.show();
  128. }.bind(this));
  129. this.prevNode.addEvent("click", function(){
  130. this.getPrev();
  131. }.bind(this));
  132. this.nextNode.addEvent("click", function(){
  133. this.getNext();
  134. }.bind(this));
  135. this.currentTextNode.addEvent("click", function(){
  136. this.changeView();
  137. }.bind(this));
  138. if( !layout.mobile ){
  139. this.titleNode.addEvent("mousedown", function(){
  140. this.move();
  141. }.bind(this));
  142. this.titleNode.addEvent("mouseup", function(){
  143. this.unmove();
  144. }.bind(this));
  145. }
  146. document.addEvent('mousedown', this.outsideClick.bind(this));
  147. },
  148. move: function(){
  149. this.containerDrag = new Drag.Move(this.container, {
  150. "onDrag": function(e){
  151. if (this.iframe){
  152. var p = this.container.getPosition();
  153. this.iframe.setStyles({
  154. "top": ""+p.y+"px",
  155. "left": ""+p.x+"px"
  156. });
  157. }
  158. }.bind(this)
  159. });
  160. },
  161. unmove: function(){
  162. this.container.removeEvents("mousedown");
  163. this.titleNode.addEvent("mousedown", function(){
  164. this.move();
  165. }.bind(this));
  166. },
  167. changeView: function(){
  168. var view = "day";
  169. switch (this.currentView) {
  170. case "day" :
  171. this.changeViewToMonth();
  172. break;
  173. case "month" :
  174. this.changeViewToYear();
  175. break;
  176. case "year" :
  177. if( this.options.yearOnly ){
  178. break;
  179. }else if( this.options.monthOnly ){
  180. this.changeViewToMonth();
  181. }else{
  182. this.changeViewToDay();
  183. }
  184. break;
  185. case "time" :
  186. this.changeViewToDay();
  187. //this.changeViewToDay();
  188. break;
  189. default :
  190. //nothing;
  191. }
  192. },
  193. changeViewToMonth: function(year){
  194. this.currentView = "month";
  195. if (!this.contentMonthTable){
  196. this.contentMonthTable = this.createContentTable();
  197. this.contentMonthTable.inject(this.contentDateNode);
  198. }
  199. if (this.contentTable) this.contentTable.setStyle("display", "none");
  200. if (this.contentYearTable) this.contentYearTable.setStyle("display", "none");
  201. if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "none");
  202. // if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "block");
  203. if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "table");
  204. var year = (year!=undefined) ? year : this.currentTextNode.retrieve("year");
  205. var month = this.currentTextNode.retrieve("month");
  206. this.showMonth(year, month);
  207. this.fireEvent("changeViewToMonth");
  208. },
  209. changeViewToYear: function(year){
  210. this.currentView = "year";
  211. if (!this.contentYearTable){
  212. this.contentYearTable = this.createContentTable();
  213. this.contentYearTable.inject(this.contentDateNode);
  214. }
  215. if (this.contentTable) this.contentTable.setStyle("display", "none");
  216. if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "none");
  217. if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "none");
  218. // if (this.contentYearTable) this.contentYearTable.setStyle("display", "block");
  219. if (this.contentYearTable) this.contentYearTable.setStyle("display", "table");
  220. this.showYear(year);
  221. this.fireEvent("changeViewToYear");
  222. },
  223. changeViewToDay: function(year, month){
  224. this.currentView = "day";
  225. if (!this.contentTable){
  226. this.contentTable = this.createContentTable();
  227. this.contentTable.inject(this.contentDateNode);
  228. }
  229. if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "none");
  230. if (this.contentYearTable) this.contentYearTable.setStyle("display", "none");
  231. if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "none");
  232. // if (this.contentTable) this.contentTable.setStyle("display", "block");
  233. if (this.contentTable) this.contentTable.setStyle("display", "table");
  234. this.showDay(year, month);
  235. this.showMonthYearButton();
  236. this.fireEvent("changeViewToDay");
  237. },
  238. hideMonthYearButton : function(){
  239. if(this.clearButton_month){
  240. this.clearButton_month.hide();
  241. }
  242. },
  243. showMonthYearButton : function(){
  244. if( this.options.clearEnable && this.buttonArea && !this.clearButton_month ){
  245. this.container.setStyle("height","auto");
  246. this.clearButton_month = new Element("div", {"text": o2.LP.widget.clear }).inject(this.buttonArea);
  247. this.clearButton_month.addEvent("click", function(){
  248. var t = this.node.get("value");
  249. this.node.set("value", "");
  250. if( t )this.fireEvent("change");
  251. this.fireEvent("clear");
  252. this.hide();
  253. }.bind(this));
  254. this.clearButton_month.setStyles(this.css.calendarMonthActionButton);
  255. }
  256. if(this.clearButton_month){
  257. this.clearButton_month.show();
  258. }
  259. },
  260. getNext: function(){
  261. switch (this.currentView) {
  262. case "time" :
  263. this.getNextDate();
  264. break;
  265. case "day" :
  266. this.getNextDay();
  267. break;
  268. case "month" :
  269. this.getNextMonth();
  270. break;
  271. case "year" :
  272. this.getNextYear();
  273. break;
  274. default :
  275. //nothing
  276. }
  277. },
  278. getPrev: function(){
  279. switch (this.currentView) {
  280. case "time" :
  281. this.getPrevDate();
  282. break;
  283. case "day" :
  284. this.getPrevDay();
  285. break;
  286. case "month" :
  287. this.getPrevMonth();
  288. break;
  289. case "year" :
  290. this.getPrevYear();
  291. break;
  292. default :
  293. //nothing
  294. }
  295. },
  296. getNextDate: function(){
  297. var date = this.currentTextNode.retrieve("date");
  298. if( this.currentView === "time" && this.options.enableDate ){
  299. var d = date.clone().increment("day", 1);
  300. if( !this.isEnableDate(d) )return;
  301. }
  302. // var year = this.currentTextNode.retrieve("year");
  303. // var month = this.currentTextNode.retrieve("month");
  304. // month--;
  305. // var day = this.currentTextNode.retrieve("day");
  306. // var date = new Date(year, month, day);
  307. date.increment("day", 1);
  308. this._setTimeTitle(null, date);
  309. if( this.options.enableHours || this.options.enableMinutes || this.options.enableSeconds ){
  310. this._resetTimeDate();
  311. }
  312. },
  313. getPrevDate: function(){
  314. var date = this.currentTextNode.retrieve("date");
  315. if( this.currentView === "time" && this.options.enableDate ){
  316. var d = date.clone().increment("day", -1);
  317. if( !this.isEnableDate(d) )return;
  318. }
  319. date.increment("day", -1);
  320. this._setTimeTitle(null, date);
  321. if( this.options.enableHours || this.options.enableMinutes || this.options.enableSeconds ){
  322. this._resetTimeDate();
  323. }
  324. },
  325. getNextDay: function(){
  326. var year = this.currentTextNode.retrieve("year");
  327. var month = this.currentTextNode.retrieve("month");
  328. month--;
  329. var date = new Date(year, month, 1);
  330. date.increment("month", 1);
  331. var thisYear = date.getFullYear();
  332. var thisMonth = date.getMonth();
  333. this._setDayTitle(null, thisYear, thisMonth);
  334. this._setDayDate(null,thisYear, thisMonth);
  335. this.fireEvent("changeViewToDay");
  336. },
  337. getPrevDay: function(){
  338. var year = this.currentTextNode.retrieve("year");
  339. var month = this.currentTextNode.retrieve("month");
  340. month--;
  341. var date = new Date(year, month, 1);
  342. date.increment("month", -1)
  343. var thisYear = date.getFullYear();
  344. var thisMonth = date.getMonth();
  345. this._setDayTitle(null, thisYear, thisMonth);
  346. this._setDayDate(null,thisYear, thisMonth);
  347. this.fireEvent("changeViewToDay");
  348. },
  349. getNextMonth: function(){
  350. var year = this.currentTextNode.retrieve("year");
  351. var date = new Date(year, 1, 1);
  352. date.increment("year", 1)
  353. var thisYear = date.getFullYear();
  354. this.showMonth(thisYear);
  355. this.fireEvent("changeViewToMonth");
  356. },
  357. getPrevMonth: function(){
  358. var year = this.currentTextNode.retrieve("year");
  359. var date = new Date(year, 1, 1);
  360. date.increment("year", -1)
  361. var thisYear = date.getFullYear();
  362. this.showMonth(thisYear);
  363. this.fireEvent("changeViewToMonth");
  364. },
  365. getNextYear: function(){
  366. var year = this.currentTextNode.retrieve("year");
  367. var date = new Date(year, 1, 1);
  368. date.increment("year", this.yearLength)
  369. var thisYear = date.getFullYear();
  370. this.showYear(thisYear);
  371. this.fireEvent("changeViewToYear");
  372. },
  373. getPrevYear: function(){
  374. var year = this.currentTextNode.retrieve("year");
  375. var date = new Date(year, 1, 1);
  376. date.increment("year", 0-this.yearLength)
  377. var thisYear = date.getFullYear();
  378. this.showYear(thisYear);
  379. this.fireEvent("changeViewToYear");
  380. },
  381. outsideClick: function(e) {
  382. if(this.visible) {
  383. var elementCoords, targetCoords, page;
  384. if ( !layout.inBrowser && layout.userLayout && layout.userLayout.scale && layout.userLayout.scale!==1){
  385. elementCoords = this.container.getCoordinates( this.options.target );
  386. targetCoords = this.node.getCoordinates( this.options.target );
  387. var containerSize = this.options.target.getPosition();
  388. page = e.page;
  389. // elementCoords.left = elementCoords.left * layout.userLayout.scale;
  390. // elementCoords.top = elementCoords.top * layout.userLayout.scale;
  391. //
  392. // targetCoords.left = targetCoords.left * layout.userLayout.scale;
  393. // targetCoords.top = targetCoords.top * layout.userLayout.scale;
  394. //
  395. // containerSize.x = containerSize.x * layout.userLayout.scale;
  396. // containerSize.y = containerSize.y * layout.userLayout.scale;
  397. page.x = page.x / layout.userLayout.scale - containerSize.x;
  398. page.y = page.y / layout.userLayout.scale - containerSize.y;
  399. }else{
  400. elementCoords = this.container.getCoordinates();
  401. targetCoords = this.node.getCoordinates();
  402. page = e.page;
  403. }
  404. if(((page.x < elementCoords.left || page.x > (elementCoords.left + elementCoords.width)) ||
  405. (page.y < elementCoords.top || page.y > (elementCoords.top + elementCoords.height))) &&
  406. ((page.x < targetCoords.left || page.x > (targetCoords.left + targetCoords.width)) ||
  407. (page.y < targetCoords.top || page.y > (targetCoords.top + targetCoords.height))) ) this.hide();
  408. }
  409. },
  410. hide: function(){
  411. if (this.visible){
  412. // if (!this.morph){
  413. // this.morph = new Fx.Morph(this.container, {"duration": 200});
  414. // }
  415. this.visible = false;
  416. // this.changeViewToDay();
  417. // this.morph.start({"opacity": 0}).chain(function(){
  418. this.container.setStyle("display", "none");
  419. if (this.iframe) this.iframe.destroy();
  420. if (layout.desktop.offices){
  421. Object.each(layout.desktop.offices, function(office){
  422. office.show();
  423. });
  424. }
  425. if( this.maskNode ){
  426. this.maskNode.hide();
  427. }
  428. // }.bind(this));
  429. this.fireEvent("hide");
  430. }
  431. },
  432. show: function(){
  433. if (!this.visible){
  434. var dStr = this.node.get("value");
  435. if (dStr && Date.isValid(dStr)){
  436. this.options.baseDate = Date.parse(dStr.substr(0,10));
  437. }
  438. if(this.options.timeOnly){
  439. this.currentView = "time";
  440. }
  441. else{
  442. this.currentView = this.options.defaultView;
  443. }
  444. switch (this.currentView) {
  445. case "day" :
  446. this.changeViewToDay();
  447. break;
  448. case "month" :
  449. //this.showMonth();
  450. this.changeViewToMonth();
  451. break;
  452. case "year" :
  453. if( this.options.yearOnly ){
  454. this.changeViewToYear()
  455. }else{
  456. this.showYear();
  457. }
  458. break;
  459. case "time" :
  460. //this.showTime(this.options.baseDate);
  461. this.changeViewToTime(this.options.defaultDate);
  462. //this.changeViewToTime(this.options.baseDate);
  463. break;
  464. default :
  465. this.showDay();
  466. }
  467. // if (!this.morph){
  468. // this.morph = new Fx.Morph(this.container, {"duration": 200});
  469. // }
  470. this.container.setStyle("display", "block");
  471. this.setPosition();
  472. // var p = this.container.getPosition();
  473. // var s = this.container.getSize();
  474. // var zidx = this.container.getStyle("z-index");
  475. // this.iframe = new Element("iframe", {"styles":{
  476. // "border": "0px",
  477. // "margin": "0px",
  478. // "padding": "0px",
  479. // "opacity": 0,
  480. // "z-index": (zidx) ? zidx-1 : 0,
  481. // "top": ""+p.y+"px",
  482. // "left": ""+p.x+"px",
  483. // "width": ""+s.x+"px",
  484. // "height": ""+s.y+"px",
  485. // "position": "absolute"
  486. // }}).inject(this.container, "before");
  487. if (layout.desktop.offices){
  488. Object.each(layout.desktop.offices, function(office){
  489. if (this.container.isOverlap(office.officeNode)){
  490. office.hide();
  491. }
  492. }.bind(this));
  493. }
  494. if( this.maskNode ){
  495. this.maskNode.show();
  496. }
  497. // this.morph.start({"opacity": 1}).chain(function(){
  498. this.visible = true;
  499. // }.bind(this));
  500. this.fireEvent("show");
  501. }
  502. },
  503. setPosition: function(){
  504. //if (this.container.position && (!layout || !layout.userLayout || !layout.userLayout.scale || layout.userLayout.scale===1) ){
  505. var postY = "bottom";
  506. var postX = "left";
  507. this.container.position({
  508. relativeTo: this.node,
  509. position: 'bottomLeft',
  510. edge: 'upperLeft'
  511. });
  512. // var offsetPNode = this.node.getOffsetParent();
  513. var cp = this.container.getPosition(this.options.target || null);
  514. var cSize = this.container.getSize();
  515. //var fp = (this.options.target) ? this.options.target.getPosition() : $(document.body).getPosition()
  516. var fsize = (this.options.target) ? this.options.target.getSize() : $(document.body).getSize();
  517. //if (cp.y+cSize.y>fsize.y+fp.y){
  518. if (cp.y+cSize.y>fsize.y){
  519. // this.container.position({
  520. // relativeTo: this.node,
  521. // position: 'upperLeft',
  522. // edge: 'bottomLeft'
  523. // });
  524. postY = "upper";
  525. }
  526. if( cp.x+cSize.x>fsize.x ){
  527. postX = "right";
  528. }
  529. if( postY === "upper" && postX === "left" ){
  530. this.container.position({
  531. relativeTo: this.node,
  532. position: 'upperLeft',
  533. edge: 'bottomLeft'
  534. });
  535. }else if( postX === "right" ){
  536. if( postY === "bottom" ){
  537. this.container.position({
  538. relativeTo: this.node,
  539. position: 'bottomRight',
  540. edge: 'upperRight'
  541. });
  542. }else{
  543. this.container.position({
  544. relativeTo: this.node,
  545. position: 'upperRight',
  546. edge: 'bottomRight'
  547. });
  548. }
  549. }
  550. this.postY = postY;
  551. this.postX = postX;
  552. // }else{
  553. // var p = this.node.getPosition(this.options.target || null);
  554. // var size = this.node.getSize();
  555. // var containerSize = this.container.getSize();
  556. // var bodySize = (this.options.target) ? this.options.target.getSize() : $(document.body).getSize(); //$(document.body).getSize();
  557. //
  558. // bodySize.x = bodySize.x * layout.userLayout.scale;
  559. // bodySize.y = bodySize.y * layout.userLayout.scale;
  560. //
  561. // var left = p.x;
  562. // left = left * layout.userLayout.scale;
  563. // if ((left + containerSize.x + 40) > bodySize.x){
  564. // left = bodySize.x - containerSize.x - 40;
  565. // }
  566. //
  567. // var top = p.y+size.y+2;
  568. // top = top * layout.userLayout.scale;
  569. // if( top + containerSize.y > bodySize.y ){
  570. // top = bodySize.y - containerSize.y ;
  571. // }
  572. //
  573. //
  574. // this.container.setStyle("top", top);
  575. // this.container.setStyle("left", left);
  576. // }
  577. },
  578. showYear: function(year){
  579. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  580. var date = new Date(thisYear, 1, 1);
  581. date.increment("year", -2);
  582. var beginYear = date.getFullYear();
  583. date.increment("year", this.yearLength-1);
  584. var endYear = date.getFullYear();
  585. this._setYearTitle(null, beginYear, endYear, thisYear);
  586. this._setYearDate(null, beginYear, endYear, thisYear);
  587. this.showMonthYearButton();
  588. // if (!this.move){
  589. // this.move = true;
  590. // this.containerDrag = new Drag.Move(this.container);
  591. // }
  592. },
  593. _setYearTitle:function(node, beginYear, endYear, thisYear){
  594. var thisNode = node || this.currentTextNode;
  595. thisNode.set("text", beginYear+"-"+endYear);
  596. thisNode.store("year", thisYear);
  597. this.setTitleStyle();
  598. },
  599. _setYearDate: function(table, beginYear, endYear, year){
  600. var yearTable = table || this.contentYearTable;
  601. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  602. var tbody = yearTable.getElement("tbody");
  603. var tds = tbody.getElements("td");
  604. tds.each(function(item, idx){
  605. var y = beginYear+idx;
  606. item.set("text", y);
  607. item.store("year", y);
  608. if (y==this.options.baseDate.getFullYear()){
  609. item.addClass("current_"+this.options.style);
  610. }else{
  611. item.removeClass("current_"+this.options.style);
  612. }
  613. if( this.options.enableDate ){
  614. if( !this.isEnableDate(y+"-01-01") && !this.isEnableDate(y+"-12-12") ){
  615. // item.addClass("disable_"+this.options.style);
  616. item.setStyles(this.css["disable_"+this.options.style]);
  617. }else{
  618. // item.removeClass("disable_"+this.options.style);
  619. item.setStyles(this.css["notdisable_"+this.options.style]);
  620. }
  621. }
  622. }.bind(this));
  623. },
  624. showMonth: function(year, month){
  625. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  626. var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
  627. this._setMonthTitle(null, thisYear, thisMonth);
  628. this._setMonthDate(null, thisYear, thisMonth);
  629. this.showMonthYearButton();
  630. // if (!this.move){
  631. // this.move = true;
  632. // this.containerDrag = new Drag.Move(this.container);
  633. // }
  634. },
  635. _setMonthTitle:function(node, year){
  636. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  637. var thisNode = node || this.currentTextNode;
  638. thisNode.set("text", thisYear);
  639. thisNode.store("year", thisYear);
  640. this.setTitleStyle();
  641. },
  642. _setMonthDate: function(table, year, month){
  643. //var months = Locale.get("Date").months;
  644. var months = o2.LP.widget.months;
  645. var monthTable = table || this.contentMonthTable;
  646. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  647. var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
  648. var tbody = monthTable.getElement("tbody");
  649. var tds = tbody.getElements("td");
  650. tds.each(function(item, idx){
  651. item.set("text", months[idx].substr(0,2));
  652. item.store("year", thisYear);
  653. item.store("month", idx);
  654. if ((thisYear==this.options.baseDate.getFullYear()) && (idx==this.options.baseDate.getMonth())){
  655. item.addClass("current_"+this.options.style);
  656. }else{
  657. item.removeClass("current_"+this.options.style);
  658. }
  659. if( this.options.enableDate ){
  660. var flag = false;
  661. var m = this.addZero(idx + 1, 2 );
  662. if (this.isEnableDate(thisYear+"-"+m+"-01")){
  663. flag = true;
  664. }else if(this.isEnableDate(thisYear+"-"+m+"-"+new Date(thisYear+"-"+m+"-01").get('lastdayofmonth'))){
  665. flag = true;
  666. }
  667. if( !flag ){
  668. // item.addClass("disable_"+this.options.style);
  669. item.setStyles(this.css["disable_"+this.options.style]);
  670. }else{
  671. // item.removeClass("disable_"+this.options.style);
  672. item.setStyles(this.css["notdisable_"+this.options.style]);
  673. }
  674. }
  675. }.bind(this));
  676. },
  677. showDay: function(year, month){
  678. this._setDayTitle(null, year, month);
  679. this._setDayWeekTitleTh();
  680. this._setDayDate(null, year, month);
  681. // if (!this.move){
  682. // this.move = true;
  683. // this.containerDrag = new Drag.Move(this.container);
  684. // }
  685. },
  686. _setDayTitle: function(node, year, month){
  687. var thisYear = (year!=undefined) ? year : this.options.baseDate.getFullYear();
  688. var thisMonth = (month!=undefined) ? month : this.options.baseDate.getMonth();
  689. thisMonth++;
  690. var text = thisYear+ o2.LP.widget.year +thisMonth+ o2.LP.widget.month;
  691. var thisNode = node || this.currentTextNode;
  692. thisNode.set("text", text);
  693. thisNode.store("year", thisYear);
  694. thisNode.store("month", thisMonth);
  695. this.setTitleStyle();
  696. },
  697. _setDayDate: function(table, year, month){
  698. var dayTable = table || this.contentTable;
  699. var baseDate = this.options.baseDate;
  700. if ((year!=undefined) && (month!=undefined)){
  701. baseDate = new Date();
  702. baseDate.setDate(1);
  703. baseDate.setFullYear(year);
  704. baseDate.setMonth(month);
  705. baseDate.setHours( this.options.baseDate.getHours() );
  706. baseDate.setMinutes( this.options.baseDate.getMinutes() );
  707. baseDate.setSeconds( this.options.baseDate.getSeconds() );
  708. }
  709. var tbody = dayTable.getElement("tbody");
  710. var tds = tbody.getElements("td");
  711. var firstDate = baseDate.clone();
  712. firstDate.setDate(1);
  713. var day = firstDate.getDay();
  714. var tmpDate = firstDate.clone();
  715. for (var i=day-1; i>=0; i--){
  716. if( this.options.enableDate ){
  717. if( !this.isEnableDate(firstDate) ){
  718. tds[i].addClass("disable_"+this.options.style);
  719. tds[i].setStyles(this.css["disable_"+this.options.style]);
  720. }else{
  721. tds[i].removeClass("disable_"+this.options.style);
  722. tds[i].setStyles(this.css["notdisable_"+this.options.style]);
  723. }
  724. }
  725. tmpDate.increment("day", -1);
  726. tds[i].set("text", tmpDate.getDate());
  727. tds[i].addClass("gray_"+this.options.style);
  728. tds[i].setStyles(this.css["gray_"+this.options.style]);
  729. tds[i].store("dateValue", tmpDate.toString());
  730. tds[i].removeClass("today_"+this.options.style);
  731. tds[i].removeClass("current_"+this.options.style);
  732. tds[i].removeClass("past_"+this.options.style);
  733. if( this.options.todayClass ){
  734. tds[i].removeClass( this.options.todayClass );
  735. }
  736. }
  737. for (var i=day; i<tds.length; i++){
  738. tds[i].set("text", firstDate.getDate());
  739. if( this.options.enableDate ){
  740. if( !this.isEnableDate(firstDate) ){
  741. // tds[i].addClass("disable_"+this.options.style);
  742. tds[i].setStyles(this.css["disable_"+this.options.style]);
  743. }else{
  744. // tds[i].removeClass("disable_"+this.options.style);
  745. tds[i].setStyles(this.css["notdisable_"+this.options.style]);
  746. }
  747. }
  748. if (firstDate.toString() == this.options.baseDate.toString()){
  749. tds[i].addClass("current_"+this.options.style);
  750. tds[i].setStyles(this.css["current_"+this.options.style]);
  751. tds[i].removeClass("past_"+this.options.style);
  752. tds[i].removeClass("gray_"+this.options.style);
  753. tds[i].setStyle("border", "1px solid #FFF");
  754. }else if (firstDate.getMonth()!=baseDate.getMonth()){
  755. tds[i].addClass("gray_"+this.options.style);
  756. tds[i].setStyles(this.css["gray_"+this.options.style]);
  757. tds[i].removeClass("current_"+this.options.style);
  758. tds[i].removeClass("past_"+this.options.style);
  759. tds[i].setStyle("border", "1px solid #FFF");
  760. }else{
  761. tds[i].setStyles(this.css["normal_"+this.options.style]);
  762. tds[i].removeClass("current_"+this.options.style);
  763. tds[i].removeClass("gray_"+this.options.style);
  764. tds[i].removeClass("past_"+this.options.style);
  765. tds[i].setStyle("border", "1px solid #FFF");
  766. }
  767. var tmp = firstDate.clone();
  768. if (tmp.clearTime().toString() == this.today.clearTime().toString()){
  769. tds[i].addClass("today_"+this.options.style);
  770. tds[i].removeClass("past_"+this.options.style);
  771. tds[i].setStyles(this.css["today_"+this.options.style]);
  772. tds[i].setStyle("border", "0px solid #AAA");
  773. if( this.options.todayClass ){
  774. tds[i].addClass( this.options.todayClass );
  775. }
  776. }else{
  777. tds[i].removeClass("today_"+this.options.style);
  778. if( this.options.todayClass ){
  779. tds[i].removeClass( this.options.todayClass );
  780. }
  781. }
  782. if (tmp.diff(this.today)>0){
  783. if (this.css["past_"+this.options.style]) tds[i].setStyles(this.css["past_"+this.options.style]);
  784. tds[i].addClass("past_"+this.options.style);
  785. }
  786. tds[i].store("dateValue", firstDate.toString());
  787. firstDate.increment("day", 1);
  788. }
  789. },
  790. changeViewToTime: function(date){
  791. this.currentView = "time";
  792. if (!this.contentTimeTable){
  793. this.contentTimeTable = this.createContentTable();
  794. this.contentTimeTable.inject(this.contentDateNode);
  795. }
  796. if (this.contentTable) this.contentTable.setStyle("display", "none");
  797. if (this.contentYearTable) this.contentYearTable.setStyle("display", "none");
  798. if (this.contentMonthTable) this.contentMonthTable.setStyle("display", "none");
  799. if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "block");
  800. // if (this.contentTimeTable) this.contentTimeTable.setStyle("display", "table");
  801. var thisDate = date || this.options.baseDate;
  802. this.showTime(thisDate);
  803. this.hideMonthYearButton();
  804. },
  805. showTime: function(date){
  806. var thisHour = (date || this.options.baseDate).getHours();
  807. var thisMinutes = (date || this.options.baseDate).getMinutes();
  808. var thisSeconds = (date || this.options.baseDate).getSeconds();
  809. // var times = this.options.defaultTime.split(":");
  810. //
  811. // var thisHour = (times[0]) ? times[0] : "0";
  812. // var thisMinutes = (times[1]) ? times[1] : "0";
  813. // var thisSeconds = (times[2]) ? times[2] : "0";
  814. this._setTimeTitle(null, date);
  815. if( this.options.style.indexOf("mobile") > -1 ){
  816. this._setTimeDate_mobile(null, thisHour, thisMinutes, thisSeconds);
  817. }else{
  818. this._setTimeDate(null, thisHour, thisMinutes, thisSeconds);
  819. }
  820. // if (this.move){
  821. // this.move = false;
  822. // this.container.removeEvents("mousedown");
  823. // }
  824. },
  825. _setTimeTitle: function(node, date){
  826. var thisDate = date || this.options.baseDate;
  827. var thisNode = node || this.currentTextNode;
  828. var y = thisDate.getFullYear();
  829. var m = thisDate.getMonth()+1;
  830. var d = thisDate.getDate();
  831. var text = "" + y + o2.LP.widget.year + m + o2.LP.widget.month + d + o2.LP.widget.date;
  832. if (this.options.timeOnly){
  833. thisNode.hide();
  834. if (this.prevNode) this.prevNode.hide();
  835. if (this.nextNode) this.nextNode.hide();
  836. }
  837. thisNode.set("text", text);
  838. thisNode.store("date", date);
  839. this.cDate = date;
  840. this.setTitleStyle();
  841. },
  842. _setTimeDate_mobile: function(node, h, m, s){
  843. var _self = this;
  844. this.itmeHNode = this.contentTimeTable.getElement(".MWF_calendar_time_h");
  845. this.itmeMNode = this.contentTimeTable.getElement(".MWF_calendar_time_m");
  846. this.itmeSNode = this.contentTimeTable.getElement(".MWF_calendar_time_s");
  847. this.showActionNode = this.contentTimeTable.getElement(".MWF_calendar_action_show");
  848. var calendar = this;
  849. var div, items;
  850. this.calculateCurrentHour(h);
  851. if( this.hMobileSelect ){
  852. this.itmeHNode.empty();
  853. this.hMobileSelect = null;
  854. }
  855. items = [];
  856. for( var i=0; i<24; i++ ) {
  857. div = new Element("div.hselect", {
  858. "text": this.addZero(i, 2),
  859. "styles": this.css.calendarTimeSelectItem_mobile
  860. }).inject(this.itmeHNode);
  861. div.store("d", i);
  862. if (!this.isEnableHour(this.cDate, i)){
  863. div.hide();
  864. }else{
  865. items.push(i);
  866. }
  867. }
  868. this.selectedHour = this.cHour; //this.addZero(h, 2 );
  869. this.hMobileSelect = new o2.Calendar.MobileSelect( this.itmeHNode.getParent(), {
  870. "lineHeight" : 40,
  871. "items" : items, //24,
  872. "currentItem" : parseInt( this.cHour ),
  873. "onChange": function(value){
  874. this.selectedHour = value; //this.addZero(value, 2 );
  875. this.cHour = this.selectedHour;
  876. if( this.options.enableMinutes )this._resetMinuteSelect_mobile();
  877. if( this.options.enableSeconds )this._resetSecondSelect_mobile();
  878. //this.showHNode.set("text", this.addZero(i, 2 ));
  879. //this.itmeHNode.getFirst().set("text", this.addZero(i, 2 ));
  880. }.bind(this)
  881. });
  882. this.hMobileSelect.load();
  883. this.calculateCurrentMinute(m);
  884. if( this.mMobileSelect ){
  885. this.itmeMNode.empty();
  886. this.mMobileSelect = null;
  887. }
  888. items = [];
  889. for (var i = 0; i < 60; i++) {
  890. div = new Element("div.mselect", {
  891. "text": this.addZero(i, 2),
  892. "styles": this.css.calendarTimeSelectItem_mobile
  893. }).inject(this.itmeMNode);
  894. div.store("d", i);
  895. if (!this.isEnableMinute(this.cDate, this.cHour, i)) {
  896. div.hide();
  897. }else{
  898. items.push(i);
  899. }
  900. }
  901. this.selectedMinute = this.cMinute; //this.addZero(m, 2);
  902. this.mMobileSelect = new o2.Calendar.MobileSelect(this.itmeMNode.getParent(), {
  903. "lineHeight": 40,
  904. "items": items, //60,
  905. "currentItem": parseInt(this.cMinute),
  906. "onChange": function (value) {
  907. this.selectedMinute = value; //this.addZero(value, 2);
  908. //this.showHNode.set("text", this.addZero(i, 2 ));
  909. //this.itmeHNode.getFirst().set("text", this.addZero(i, 2 ));
  910. this.cMinute = this.selectedMinute;
  911. if( this.options.enableSeconds )this._resetSecondSelect_mobile();
  912. }.bind(this)
  913. });
  914. this.mMobileSelect.load();
  915. if(this.options.secondEnable ){
  916. this.calculateCurrentSecond(s);
  917. if( this.sMobileSelect ){
  918. this.itmeSNode.empty();
  919. this.sMobileSelect = null;
  920. }
  921. items = [];
  922. for( var i=0; i<60; i++ ){
  923. div = new Element("div.sselect",{
  924. "text" : this.addZero(i, 2 ),
  925. "styles" : this.css.calendarTimeSelectItem_mobile
  926. }).inject( this.itmeSNode );
  927. div.store("d", i);
  928. if (!this.isEnableMinute(this.cDate, this.cHour, this.cMinute, i)) {
  929. div.hide();
  930. }else{
  931. items.push(i);
  932. }
  933. }
  934. this.selectedSecond = this.cSecond; //this.addZero(s, 2 );
  935. this.sMobileSelect = new o2.Calendar.MobileSelect( this.itmeSNode.getParent(), {
  936. "lineHeight" : 40,
  937. "items" : items, //60,
  938. "currentItem" : parseInt(this.cSecond),
  939. "onChange": function(value){
  940. this.selectedSecond = value; //this.addZero(value, 2 );
  941. //this.showHNode.set("text", this.addZero(i, 2 ));
  942. //this.itmeHNode.getFirst().set("text", this.addZero(i, 2 ));
  943. this.cSecond = this.selectedSecond;
  944. }.bind(this)
  945. });
  946. this.sMobileSelect.load();
  947. }else{
  948. this.itmeSNode.hide();
  949. }
  950. if( this.options.secondEnable ){
  951. this.contentTimeTable.getElements(".calendarTimeWheel_mobile").setStyle("width","33.3%");
  952. }else{
  953. this.contentTimeTable.getElements(".calendarTimeWheel_mobile").setStyle("width","50%");
  954. }
  955. if( this.options.secondEnable && this.showSNode ){
  956. this.showSNode.set("text", this.addZero( s.toInt(), 2) );
  957. }
  958. if (!this.okButton){
  959. this.okButton = new Element("button.mainColor_bg", {"text": o2.LP.widget.ok }).inject(this.showActionNode);
  960. this.okButton.addEvent("click", function(){
  961. this._selectTime();
  962. this.hide();
  963. }.bind(this));
  964. this.okButton.setStyles(this.css.calendarActionShowButton_mobile_ok);
  965. }
  966. if (!this.clearButton && this.options.clearEnable){
  967. this.clearButton = new Element("button", {"text": o2.LP.widget.clear }).inject(this.showActionNode);
  968. this.clearButton.addEvent("click", function(){
  969. var t = this.node.get("value");
  970. this.node.set("value", "");
  971. if( t )this.fireEvent("change");
  972. this.fireEvent("clear");
  973. this.hide();
  974. }.bind(this));
  975. this.clearButton.setStyles(this.css.calendarActionShowButton_mobile_cancel);
  976. }
  977. },
  978. _setTimeDate: function(node, h, m, s){
  979. if( !this.options.secondEnable ){
  980. var div = this.contentTimeTable.getElement(".MWF_calendar_time_s");
  981. if( div )div.hide();
  982. div = this.contentTimeTable.getElement(".MWF_calendar_time_show_s");
  983. if( div )div.hide();
  984. }
  985. this.itmeHNode = this.contentTimeTable.getElement(".MWF_calendar_time_h_slider");
  986. this.itmeMNode = this.contentTimeTable.getElement(".MWF_calendar_time_m_slider");
  987. this.itmeSNode = this.contentTimeTable.getElement(".MWF_calendar_time_s_slider");
  988. this.timeShowNode = this.contentTimeTable.getElement(".MWF_calendar_time_show");
  989. this.timeShowNode.addEvent("click", function(){
  990. this._selectTime();
  991. }.bind(this));
  992. this.showHNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_h");
  993. this.showMNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_m");
  994. this.showSNode = this.contentTimeTable.getElement(".MWF_calendar_time_show_s");
  995. this.showActionNode = this.contentTimeTable.getElement(".MWF_calendar_action_show");
  996. var calendar = this;
  997. if ( COMMON.Browser.Platform.isMobile ){
  998. this.showHNode.set("text", this.addZero( h.toInt(), 2) );
  999. this.showMNode.set("text", this.addZero( m.toInt(), 2));
  1000. if( this.options.secondEnable && this.showSNode ){
  1001. this.showSNode.set("text", this.addZero( s.toInt(), 2) );
  1002. }
  1003. }else{
  1004. if(this.options.timeSelectType === "select"){
  1005. this.loadHourSelect(h);
  1006. this.loadMinuteSelect(m);
  1007. this.loadSecondSelect(s);
  1008. }else {
  1009. this.calculateCurrentHour(h);
  1010. this.createDisabledNodes(this.itmeHNode, 24, "h");
  1011. this.hSlider = new Slider(this.itmeHNode, this.itmeHNode.getFirst(), {
  1012. range: [0, 23],
  1013. initialStep: this.cHour,
  1014. onChange: function(value){
  1015. var v = value.toInt();
  1016. if( this.isEnableHour(this.cDate, v) ){
  1017. this.selectedHour = v;
  1018. this.cHour = v;
  1019. this.showHNode.set("text", this.addZero(v, 2));
  1020. this.itmeHNode.getFirst().set("text", this.addZero(v, 2));
  1021. if( this.options.enableMinutes ){
  1022. this.calculateCurrentMinute();
  1023. this.createDisabledNodes(this.itmeMNode, 60, "m");
  1024. this.mSlider.set( this.cMinute );
  1025. this.itmeMNode.getFirst().set("text", this.addZero( this.cMinute, 2));
  1026. this.showMNode.set("text", this.addZero( this.cMinute, 2));
  1027. }
  1028. if( this.options.enableSeconds && this.sSlider ){
  1029. this.calculateCurrentSecond();
  1030. this.createDisabledNodes(this.itmeSNode, 60, "s");
  1031. this.sSlider.set( this.cSecond );
  1032. this.itmeSNode.getFirst().set("text", this.addZero( this.cSecond, 2));
  1033. this.showSNode.set("text", this.addZero( this.cSecond, 2) );
  1034. }
  1035. }
  1036. }.bind(this)
  1037. });
  1038. // if( this.options.enableHours ){
  1039. // this.hSlider.setRange( this.getEnableHourStartEnd(this.cDate) );
  1040. // }
  1041. this.itmeHNode.getFirst().set("text", this.addZero( this.cHour, 2));
  1042. this.showHNode.set("text", this.addZero( this.cHour, 2) );
  1043. this.calculateCurrentMinute(m);
  1044. this.createDisabledNodes(this.itmeMNode, 60, "m");
  1045. this.mSlider = new Slider(this.itmeMNode, this.itmeMNode.getFirst(), {
  1046. range: [0, 59],
  1047. initialStep: this.cMinute,
  1048. onChange: function(value){
  1049. var v = value.toInt();
  1050. if( this.isEnableMinute(this.cDate, this.cHour, v) ){
  1051. this.selectedMinute = v;
  1052. this.cMinute = v;
  1053. this.showMNode.set("text", this.addZero( v, 2));
  1054. this.itmeMNode.getFirst().set("text", this.addZero( v, 2));
  1055. if( this.options.enableSeconds && this.sSlider ){
  1056. this.calculateCurrentSecond();
  1057. this.createDisabledNodes(this.itmeSNode, 60, "s");
  1058. this.sSlider.set( this.cSecond );
  1059. this.itmeSNode.getFirst().set("text", this.addZero( this.cSecond, 2));
  1060. this.showSNode.set("text", this.addZero( this.cSecond, 2) );
  1061. }
  1062. }
  1063. }.bind(this)
  1064. });
  1065. this.itmeMNode.getFirst().set("text", this.addZero( this.cMinute, 2));
  1066. this.showMNode.set("text", this.addZero( this.cMinute, 2));
  1067. if( this.options.secondEnable && this.itmeSNode ){
  1068. this.calculateCurrentSecond(s);
  1069. this.createDisabledNodes(this.itmeSNode, 60, "s");
  1070. this.sSlider = new Slider(this.itmeSNode, this.itmeSNode.getFirst(), {
  1071. range: [0, 59],
  1072. initialStep: this.cSecond,
  1073. onChange: function(value){
  1074. var v = value.toInt();
  1075. if( this.isEnableSecond(this.cDate, this.cHour, this.cMinute, v) ){
  1076. this.selectedSecond = v;
  1077. this.cSecond = v;
  1078. this.showSNode.set("text", this.addZero( v, 2));
  1079. this.itmeSNode.getFirst().set("text", this.addZero( v, 2));
  1080. }
  1081. }.bind(this)
  1082. });
  1083. this.itmeSNode.getFirst().set("text", this.addZero( this.cSecond, 2));
  1084. this.showSNode.set("text", this.addZero( this.cSecond, 2) );
  1085. }
  1086. // this.showHNode.set("text", this.addZero( h.toInt(), 2) );
  1087. // this.showMNode.set("text", this.addZero( m.toInt(), 2));
  1088. // if( this.options.secondEnable && this.showSNode ){
  1089. // this.showSNode.set("text", this.addZero( s.toInt(), 2) );
  1090. // }
  1091. }
  1092. }
  1093. if (!this.okButton){
  1094. this.okButton = new Element("button", {"text": o2.LP.widget.ok}).inject(this.showActionNode);
  1095. this.okButton.addEvent("click", function(){
  1096. this._selectTime();
  1097. this.hide();
  1098. }.bind(this));
  1099. this.okButton.setStyles(this.css.calendarActionShowButton);
  1100. }
  1101. if (!this.clearButton && this.options.clearEnable){
  1102. this.clearButton = new Element("button", {"text": o2.LP.widget.clear }).inject(this.showActionNode);
  1103. this.clearButton.addEvent("click", function(){
  1104. var t = this.node.get("value");
  1105. this.node.set("value", "");
  1106. if( t )this.fireEvent("change");
  1107. this.fireEvent("clear");
  1108. this.hide();
  1109. }.bind(this));
  1110. this.clearButton.setStyles(this.css.calendarActionShowButton);
  1111. }
  1112. },
  1113. _resetTimeDate: function(){
  1114. if( this.options.style.indexOf("mobile") > -1 ){
  1115. if( this.options.enableHours )this._resetHourSelect_mobile();
  1116. if( this.options.enableMinutes )this._resetMinuteSelect_mobile();
  1117. if( this.options.enableSeconds )this._resetSecondSelect_mobile();
  1118. }else{
  1119. if(this.options.timeSelectType === "select"){
  1120. if( this.options.enableHours )this.loadHourSelect();
  1121. if( this.options.enableMinutes )this.loadMinuteSelect();
  1122. if( this.options.enableSeconds )this.loadSecondSelect();
  1123. }else {
  1124. if( this.options.enableHours ){
  1125. this.calculateCurrentHour();
  1126. this.createDisabledNodes(this.itmeHNode, 24, "h");
  1127. this.hSlider.set( this.cHour );
  1128. this.itmeHNode.getFirst().set("text", this.addZero( this.cHour, 2));
  1129. this.showHNode.set("text", this.addZero( this.cHour, 2) );
  1130. }
  1131. if( this.options.enableMinutes ){
  1132. this.calculateCurrentMinute();
  1133. this.createDisabledNodes(this.itmeMNode, 60, "m");
  1134. this.mSlider.set( this.cMinute );
  1135. this.itmeMNode.getFirst().set("text", this.addZero( this.cMinute, 2));
  1136. this.showMNode.set("text", this.addZero( this.cMinute, 2));
  1137. }
  1138. if( this.options.enableSeconds && this.sSlider ){
  1139. this.calculateCurrentSecond();
  1140. this.createDisabledNodes(this.itmeSNode, 60, "s");
  1141. this.sSlider.set( this.cSecond );
  1142. this.itmeSNode.getFirst().set("text", this.addZero( this.cSecond, 2));
  1143. this.showSNode.set("text", this.addZero( this.cSecond, 2) );
  1144. }
  1145. }
  1146. }
  1147. },
  1148. _resetHourSelect_mobile: function(){
  1149. if( this.options.enableHours ){
  1150. this.calculateCurrentHour();
  1151. var items = [];
  1152. this.itmeHNode.getElements(".hselect").each(function(div, i){
  1153. if( this.isEnableHour(this.cDate, div.retrieve("d")) ){
  1154. items.push(i);
  1155. div.show();
  1156. }else{
  1157. div.hide();
  1158. }
  1159. }.bind(this));
  1160. this.selectedHour = this.cHour;
  1161. this.hMobileSelect.resetItems(items, parseInt(this.cHour));
  1162. }
  1163. },
  1164. _resetMinuteSelect_mobile: function(){
  1165. if( this.options.enableMinutes ) {
  1166. this.calculateCurrentMinute();
  1167. var items = [];
  1168. this.itmeMNode.getElements(".mselect").each(function(div, i){
  1169. if( this.isEnableMinute(this.cDate, this.cHour, div.retrieve("d")) ){
  1170. items.push(i);
  1171. div.show();
  1172. }else{
  1173. div.hide();
  1174. }
  1175. }.bind(this));
  1176. this.selectedMinute = this.cMinute;
  1177. this.mMobileSelect.resetItems(items, parseInt(this.cMinute));
  1178. }
  1179. },
  1180. _resetSecondSelect_mobile: function(){
  1181. if( this.options.enableSeconds && this.options.secondEnable ){
  1182. this.calculateCurrentSecond();
  1183. var items = [];
  1184. this.itmeSNode.getElements(".sselect").each(function(div, i){
  1185. if( this.isEnableSecond(this.cDate, this.cHour, this.cMinute, div.retrieve("d")) ){
  1186. items.push(i);
  1187. div.show();
  1188. }else{
  1189. div.hide();
  1190. }
  1191. }.bind(this));
  1192. this.selectedSecond = this.cSecond;
  1193. if(this.sMobileSelect)this.sMobileSelect.resetItems(items, parseInt(this.cSecond));
  1194. }
  1195. },
  1196. loadHourSelect: function (h) {
  1197. this.itmeHNode = this.contentTimeTable.getElement(".MWF_calendar_time_h").empty();
  1198. new Element("span",{"text": o2.LP.widget.hour + ":"}).inject(this.itmeHNode);
  1199. this.itmeSelectHNode = new Element("select").inject(this.itmeHNode);
  1200. this.calculateCurrentHour(h);
  1201. for( var i=0; i<24; i++ ){
  1202. if( this.isEnableHour(this.cDate, i) ){
  1203. var opt = new Element("option",{
  1204. "text" : this.addZero(i, 2 ),
  1205. "value" : this.addZero(i, 2 ),
  1206. "styles" : this.css.calendarTimeSelectItem_mobile
  1207. }).inject( this.itmeSelectHNode );
  1208. if (Browser.name === "firefox") {
  1209. opt.addEvent( "mousedown", function(e){ e.stopPropagation(); });
  1210. }
  1211. if( i === this.cHour )opt.set("selected", true);
  1212. }
  1213. }
  1214. // this.itmeSelectHNode.set("value",this.addZero( this.cHour, 2));
  1215. this.showHNode.set("text", this.addZero( this.cHour, 2) );
  1216. this.itmeSelectHNode.addEvent("change",function(){
  1217. this.cHour = this.itmeSelectHNode.get("value").toInt();
  1218. this.selectedHour = this.cHour;
  1219. this.showHNode.set("text", this.itmeSelectHNode.get("value") );
  1220. if( this.options.enableMinutes )this.loadMinuteSelect();
  1221. if( this.options.enableSeconds )this.loadSecondSelect();
  1222. }.bind(this));
  1223. },
  1224. loadMinuteSelect: function (m) {
  1225. this.itmeMNode = this.contentTimeTable.getElement(".MWF_calendar_time_m").empty();
  1226. new Element("span", {"text": o2.LP.widget.minute + ":"}).inject(this.itmeMNode);
  1227. this.itmeSelectMNode = new Element("select").inject(this.itmeMNode);
  1228. this.calculateCurrentMinute(m);
  1229. for (var i = 0; i < 60; i++) {
  1230. if (this.isEnableMinute(this.cDate, this.cHour || 0, i)) {
  1231. var opt = new Element("option", {
  1232. "text": this.addZero(i, 2),
  1233. "value": this.addZero(i, 2),
  1234. "styles": this.css.calendarTimeSelectItem_mobile
  1235. }).inject(this.itmeSelectMNode);
  1236. if (Browser.name === "firefox") {
  1237. opt.addEvent( "mousedown", function(e){ e.stopPropagation(); });
  1238. }
  1239. if( i === this.cMinute )opt.set("selected", true);
  1240. }
  1241. }
  1242. // this.itmeSelectMNode.set("value", this.addZero(this.cMinute, 2));
  1243. this.showMNode.set("text", this.addZero( this.cMinute, 2) );
  1244. this.itmeSelectMNode.addEvent("change", function () {
  1245. this.cMinute = this.itmeSelectMNode.get("value").toInt();
  1246. this.selectedMinute = this.cMinute;
  1247. this.showMNode.set("text", this.itmeSelectMNode.get("value"));
  1248. if( this.options.enableSeconds )this.loadSecondSelect();
  1249. }.bind(this));
  1250. },
  1251. loadSecondSelect: function (s) {
  1252. this.itmeSNode = this.contentTimeTable.getElement(".MWF_calendar_time_s").empty();
  1253. this.cSecond = typeOf(s) !== "null" ? s.toInt() : 0;
  1254. if( this.options.secondEnable && this.itmeSNode ){
  1255. new Element("span",{"text":o2.LP.widget.second + ":"}).inject(this.itmeSNode);
  1256. this.itmeSelectSNode = new Element("select").inject(this.itmeSNode);
  1257. this.calculateCurrentSecond(s);
  1258. for( var i=0; i<60; i++ ){
  1259. if( this.isEnableSecond(this.cDate, this.cHour || 0, this.cMinute || 0, i) ){
  1260. var opt = new Element("option",{
  1261. "text" : this.addZero(i, 2 ),
  1262. "value" : this.addZero(i, 2 ),
  1263. "styles" : this.css.calendarTimeSelectItem_mobile,
  1264. "events": { click: function(e){ e.stopPropagation(); e.preventDefault(); } }
  1265. }).inject( this.itmeSelectSNode );
  1266. if (Browser.name === "firefox") {
  1267. opt.addEvent( "mousedown", function(e){ e.stopPropagation(); });
  1268. }
  1269. if( i === this.cSecond )opt.set("selected", true);
  1270. }
  1271. }
  1272. // this.itmeSelectSNode.set("value",this.addZero( this.cSecond, 2));
  1273. this.showSNode.set("text", this.addZero( this.cSecond, 2) );
  1274. this.itmeSelectSNode.addEvent("change",function(){
  1275. this.cSecond = this.itmeSelectSNode.get("value").toInt();
  1276. this.selectedSecond = this.cSecond;
  1277. this.showSNode.set("text", this.itmeSelectSNode.get("value") );
  1278. }.bind(this));
  1279. }
  1280. },
  1281. calculateCurrentHour: function(h){
  1282. if( typeOf(h) !== "null" ){
  1283. this.cHour = h.toInt();
  1284. }else if( typeOf(this.selectedHour) !== "null" ){
  1285. this.cHour = this.selectedHour;
  1286. }else{
  1287. this.cHour = 0;
  1288. }
  1289. if( !this.isEnableHour(this.cDate, this.cHour) ) {
  1290. var eHours = this.getEnableHours(this.cDate);
  1291. if( eHours.length ){
  1292. this.cHour = typeOf( eHours[0] ) === "array" ? eHours[0][0] : eHours[0];
  1293. }else{
  1294. this.cHour = 0;
  1295. }
  1296. }
  1297. this.selectedHour = this.cHour;
  1298. return this.cHour;
  1299. },
  1300. calculateCurrentMinute: function(m){
  1301. if( typeOf(m) !== "null" ){
  1302. this.cMinute = m.toInt();
  1303. }else if( typeOf(this.selectedMinute) !== "null" ){
  1304. this.cMinute = this.selectedMinute;
  1305. }else{
  1306. this.cMinute = 0;
  1307. }
  1308. if( !this.isEnableMinute(this.cDate, this.cHour, this.cMinute) ){
  1309. var eMinutes = this.getEnableMinutes(this.cDate, this.cHour);
  1310. if( eMinutes.length ){
  1311. this.cMinute = typeOf( eMinutes[0] ) === "array" ? eMinutes[0][0] : eMinutes[0]
  1312. }else{
  1313. this.cMinute = 0;
  1314. }
  1315. }
  1316. this.selectedMinute = this.cMinute;
  1317. return this.cMinute;
  1318. },
  1319. calculateCurrentSecond: function(s){
  1320. if( typeOf(s) !== "null" ){
  1321. this.cSecond = s.toInt();
  1322. }else if( typeOf(this.selectedSecond) !== "null" ){
  1323. this.cSecond = this.selectedSecond;
  1324. }else{
  1325. this.cSecond = 0;
  1326. }
  1327. if( !this.isEnableSecond(this.cDate, this.cHour, this.cMinute, this.cSecond) ){
  1328. var eSeconds = this.getEnableSeconds(this.cDate, this.cHour, this.cMinute);
  1329. if( eSeconds.length ){
  1330. this.cSecond = typeOf( eSeconds[0] ) === "array" ? eSeconds[0][0] : eSeconds[0]
  1331. }else{
  1332. this.cSecond = 0;
  1333. }
  1334. }
  1335. this.selectedSecond = this.cSecond;
  1336. return this.cSecond;
  1337. },
  1338. createDisabledNodes: function(area, length, type){
  1339. area.getElements(".disable_node").destroy();
  1340. var array;
  1341. switch(type){
  1342. case "h": array = this.getDisabledHours(this.cDate); break;
  1343. case "m": array = this.getDisabledMinutes(this.cDate, this.cHour || 0); break;
  1344. case "s": array = this.getDisabledSeconds(this.cDate, this.cHour || 0, this.cMinute || 0); break;
  1345. }
  1346. if( !array || !array.length )return false;
  1347. area.setStyle("position", "relative");
  1348. if( typeOf(array[0]) === "array" ){
  1349. for( var i=0; i< array.length; i++ ){
  1350. this.createDisabledNode( area, length, array[i] );
  1351. }
  1352. }else{
  1353. this.createDisabledNode( area, length, array );
  1354. }
  1355. },
  1356. createDisabledNode: function(area, length, range){
  1357. var s = area.getSize();
  1358. var width = s.x / length * (range[1] - range[0] + 1);
  1359. var left = s.x / length * range[0];
  1360. new Element("div.disable_node", {
  1361. styles: {
  1362. "position": "absolute",
  1363. "background": "#ccc",
  1364. "width": width+"px",
  1365. "height": s.y,
  1366. "left": left,
  1367. "top": "0px"
  1368. }
  1369. }).inject(area);
  1370. },
  1371. addZero : function( str, length ){
  1372. var zero = "";
  1373. str = str.toString();
  1374. for( var i=0; i<length; i++ ){
  1375. zero = zero + "0";
  1376. }
  1377. var s = zero + str;
  1378. return s.substr(s.length - length, length );
  1379. },
  1380. _selectTime: function(){
  1381. var date = this.currentTextNode.retrieve("date");
  1382. var h = typeOf(this.selectedHour) !== "null" ? this.selectedHour : this.showHNode.get("text");
  1383. var m = typeOf(this.selectedMinute) !== "null" ? this.selectedMinute : this.showMNode.get("text");
  1384. date.setHours(h);
  1385. date.setMinutes(m);
  1386. if( this.options.secondEnable && ( typeOf(this.selectedSecond) !== "null" || this.showSNode) ){
  1387. var s = typeOf(this.selectedSecond) !== "null" ? this.selectedSecond : this.showSNode.get("text");
  1388. date.setSeconds(s);
  1389. }
  1390. if (!this.options.beforeCurrent){
  1391. var now = new Date();
  1392. if (date.getTime()-now.getTime()<0){
  1393. alert( o2.LP.widget.dateGreaterThanCurrentNotice );
  1394. this.node.focus();
  1395. return false;
  1396. }
  1397. }
  1398. var dv = date.format(this.options.format);
  1399. if (this.fireEvent("queryComplate", [dv, date])){
  1400. var t = this.node.get("value");
  1401. this.options.defaultTime = ""+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
  1402. this.node.set("value", dv);
  1403. // this.node.focus();
  1404. this.hide();
  1405. if (t!=dv) this.fireEvent("change", [dv, date, t]);
  1406. this.fireEvent("complate", [dv, date]);
  1407. }
  1408. },
  1409. _selectDate: function(dateStr){
  1410. if( this.options.yearOnly ){
  1411. dateStr = dateStr+"-01-01"
  1412. }else if( this.options.monthOnly ){
  1413. dateStr = dateStr+"-01"
  1414. }
  1415. var date = new Date(dateStr);
  1416. this.options.baseDate = date;
  1417. var dv = date.format(this.options.format);
  1418. if (this.options.isTime){
  1419. this.changeViewToTime(date);
  1420. }else{
  1421. if (!this.options.beforeCurrent){
  1422. var now = new Date();
  1423. date.setHours(23,59,59);
  1424. if (date.getTime()-now.getTime()<0){
  1425. alert( o2.LP.widget.dateGreaterThanCurrentNotice );
  1426. this.node.focus();
  1427. return false;
  1428. }
  1429. }
  1430. if (this.fireEvent("queryComplate", [dv, date])){
  1431. var t = this.node.get("value");
  1432. this.node.set("value", dv);
  1433. this.hide();
  1434. if (t!=dv) this.fireEvent("change", [dv, date, t]);
  1435. this.fireEvent("complate", [dv, date, t]);
  1436. }
  1437. }
  1438. },
  1439. _setDayWeekTitleTh: function(table){
  1440. var dayTable = table || this.contentTable;
  1441. var thead = dayTable.getElement("thead");
  1442. var cells = thead.getElements("th");
  1443. if (this.css.calendarDaysContentTh) cells.setStyles(this.css.calendarDaysContentTh);
  1444. //var days_abbr = Locale.get("Date").days_abbr;
  1445. var days_abbr = o2.LP.widget.days_abbr;
  1446. cells.each(function(item, idx){
  1447. item.set("text", days_abbr[idx]);
  1448. });
  1449. return cells;
  1450. },
  1451. setTitleStyle: function(){
  1452. if( this.options.enableDate ){
  1453. if( this.currentView === "time" ){
  1454. var date = this.currentTextNode.retrieve("date");
  1455. if( this.isEnableDate(date.clone().decrement()) ){
  1456. this.prevNode.setStyles(this.css["notdisable_"+this.options.style]);
  1457. }else{
  1458. this.prevNode.setStyles(this.css["disable_"+this.options.style]);
  1459. }
  1460. if( this.isEnableDate(date.clone().increment()) ){
  1461. this.nextNode.setStyles(this.css["notdisable_"+this.options.style]);
  1462. }else{
  1463. this.nextNode.setStyles(this.css["disable_"+this.options.style]);
  1464. }
  1465. }else{
  1466. this.prevNode.setStyles(this.css["notdisable_"+this.options.style]);
  1467. this.nextNode.setStyles(this.css["notdisable_"+this.options.style]);
  1468. }
  1469. }
  1470. },
  1471. createContainer: function(){
  1472. var div = null;
  1473. var request = new Request.HTML({
  1474. url: this.options.containerPath,
  1475. method: "GET",
  1476. async: false,
  1477. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  1478. div = responseTree[0];
  1479. }
  1480. });
  1481. request.send();
  1482. //this.containerNode = div.getElement(".MWF_calendar_container");
  1483. this.titleNode = div.getElement(".MWF_calendar_title");
  1484. this.prevNode = div.getElement(".MWF_calendar_prev");
  1485. this.currentNode = div.getElement(".MWF_calendar_current");
  1486. this.currentTextNode = div.getElement(".MWF_calendar_currentText");
  1487. this.nextNode = div.getElement(".MWF_calendar_next");
  1488. this.contentNode = div.getElement(".MWF_calendar_content");
  1489. this.contentDateNode = div.getElement(".MWF_calendar_content_date");
  1490. this.contentTimeNode = div.getElement(".MWF_calendar_content_time");
  1491. this.buttonArea = div.getElement(".MWF_calendar_button_area");
  1492. this.bottomNode = div.getElement(".MWF_calendar_bottom");
  1493. div.setStyles(this.css.container);
  1494. this.titleNode.setStyles(this.css.dateTitle);
  1495. this.prevNode.setStyles(this.css.datePrev);
  1496. this.currentNode.setStyles(this.css.dateCurrent);
  1497. debugger;
  1498. this.currentTextNode.setStyles(this.css.dateCurrentText);
  1499. this.nextNode.setStyles(this.css.dateNext);
  1500. this.contentNode.setStyles(this.css.calendarContent);
  1501. if(this.buttonArea)this.buttonArea.setStyles(this.css.buttonArea);
  1502. this.bottomNode.setStyles(this.css.dateBottom);
  1503. return div;
  1504. },
  1505. createContentTable: function(){
  1506. var table = null;
  1507. var request = new Request.HTML({
  1508. url: this.options[this.currentView+"Path"],
  1509. method: "GET",
  1510. async: false,
  1511. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  1512. table = responseTree[0];
  1513. }
  1514. });
  1515. request.send();
  1516. var tbody = table.getElement("tbody");
  1517. if (tbody){
  1518. var tds = tbody.getElements("td");
  1519. var calendar = this;
  1520. tds.addEvent("click", function(){
  1521. switch (calendar.currentView) {
  1522. case "day" :
  1523. var d = this.retrieve("dateValue");
  1524. if( calendar.isEnableDate(d) ){
  1525. calendar._selectDate(d, this);
  1526. }
  1527. break;
  1528. case "month" :
  1529. var flag = true;
  1530. if( calendar.options.enableDate ){
  1531. flag = false;
  1532. d = calendar.addZero(this.retrieve("month").toInt() + 1, 2 );
  1533. var y = this.retrieve("year");
  1534. if (calendar.isEnableDate(y+"-"+d+"-01")){
  1535. flag = true;
  1536. }else if(calendar.isEnableDate(y+"-"+d+"-"+new Date(y+"-"+d+"-01").get('lastdayofmonth'))){
  1537. flag = true;
  1538. }
  1539. }
  1540. if( flag ){
  1541. if( calendar.options.monthOnly ){
  1542. var m = calendar.addZero(this.retrieve("month").toInt() + 1, 2 );
  1543. calendar._selectDate(this.retrieve("year")+"-"+ m , this);
  1544. }else{
  1545. calendar.changeViewToDay(this.retrieve("year"), this.retrieve("month"));
  1546. }
  1547. }
  1548. break;
  1549. case "year" :
  1550. d = this.retrieve("year");
  1551. if (calendar.isEnableDate(d+"-01-01") || calendar.isEnableDate(d+"-12-12")){
  1552. if( calendar.options.yearOnly ){
  1553. calendar._selectDate(this.retrieve("year"), this);
  1554. }else{
  1555. calendar.changeViewToMonth(this.retrieve("year"));
  1556. }
  1557. }
  1558. break;
  1559. case "time" :
  1560. //nothing
  1561. break;
  1562. default :
  1563. //nothing;
  1564. }
  1565. });
  1566. switch (this.currentView) {
  1567. case "day" :
  1568. if (!table.display) table.display="";
  1569. if (!table.style.display) table.style.display="";
  1570. table.setStyles(this.css.calendarDaysContent);
  1571. tds.setStyles(this.css.calendarDaysContentTd);
  1572. break;
  1573. case "month" :
  1574. table.setStyles(this.css.calendarMonthsContent);
  1575. tds.setStyles(this.css.calendarMonthsContentTd);
  1576. break;
  1577. case "year" :
  1578. this.yearLength = tds.length;
  1579. table.setStyles(this.css.calendarYearsContent);
  1580. tds.setStyles(this.css.calendarYearsContentTd);
  1581. break;
  1582. case "time" :
  1583. if( this.options.style.indexOf("mobile") > -1 ){
  1584. var nodes = table.getElements(".calendarTimeContent_mobile");
  1585. if (nodes.length) nodes.setStyles(this.css.calendarTimeContent_mobile);
  1586. nodes = table.getElements(".calendarTimeFixWidthNode_mobile");
  1587. if (nodes.length) nodes.setStyles(this.css.calendarTimeFixWidthNode_mobile);
  1588. nodes = table.getElements(".calendarTimeWheels_mobile");
  1589. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheels_mobile);
  1590. nodes = table.getElements(".calendarTimeWheel_mobile");
  1591. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheel_mobile);
  1592. nodes = table.getElements(".calendarTimeSelectContainer_mobile");
  1593. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectContainer_mobile);
  1594. nodes = table.getElements(".calendarTimeSelectLine_mobile");
  1595. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectLine_mobile);
  1596. nodes = table.getElements(".calendarTimeShadowMask_mobile");
  1597. if (nodes.length) nodes.setStyles(this.css.calendarTimeShadowMask_mobile);
  1598. var node = table.getElement(".MWF_calendar_action_show");
  1599. if (node){
  1600. node.setStyles(this.css.calendarActionShow);
  1601. //var buttons = node.getElements("button");
  1602. //buttons.setStyles(this.css.calendarActionShowButton);
  1603. }
  1604. }else{
  1605. var nodes = table.getElements(".calendarTimeArea");
  1606. if (nodes.length) nodes.setStyles(this.css.calendarTimeArea);
  1607. nodes = table.getElements(".calendarTimeSlider");
  1608. if (nodes.length) nodes.setStyles(this.css.calendarTimeSlider);
  1609. nodes = table.getElements(".calendarTimeSliderKnob");
  1610. if (nodes.length) nodes.setStyles(this.css.calendarTimeSliderKnob);
  1611. nodes = table.getElements(".calendarTimeShow");
  1612. if (nodes.length) nodes.setStyles(this.css.calendarTimeShow);
  1613. nodes = table.getElements(".calendarTimeShowItem");
  1614. if (nodes.length) nodes.setStyles(this.css.calendarTimeShowItem);
  1615. var node = table.getElement(".MWF_calendar_action_show");
  1616. if (node){
  1617. node.setStyles(this.css.calendarActionShow);
  1618. var buttons = node.getElements("button");
  1619. buttons.setStyles(this.css.calendarActionShowButton);
  1620. }
  1621. }
  1622. break;
  1623. default :
  1624. //nothing;
  1625. }
  1626. tds.addEvent("mouseover", function(){
  1627. var d;
  1628. switch (calendar.currentView) {
  1629. case "day" :
  1630. d = this.retrieve("dateValue");
  1631. if (calendar.isEnableDate(d)) this.setStyle("border", "1px solid #999999");
  1632. break;
  1633. case "month" :
  1634. if( calendar.options.enableDate ){
  1635. d = calendar.addZero(this.retrieve("month").toInt() + 1, 2 );
  1636. var y = this.retrieve("year");
  1637. if (calendar.isEnableDate(y+"-"+d+"-01")){
  1638. this.setStyle("border", "1px solid #999999");
  1639. }else if(calendar.isEnableDate(y+"-"+d+"-"+new Date(y+"-"+d+"-01").get('lastdayofmonth'))){
  1640. this.setStyle("border", "1px solid #999999");
  1641. }
  1642. }else{
  1643. this.setStyle("border", "1px solid #999999");
  1644. }
  1645. break;
  1646. case "year" :
  1647. d = this.retrieve("year");
  1648. if (calendar.isEnableDate(d+"-01-01") || calendar.isEnableDate(d+"-12-12")) this.setStyle("border", "1px solid #999999");
  1649. break;
  1650. default:
  1651. this.setStyle("border", "1px solid #999999");
  1652. break;
  1653. }
  1654. });
  1655. tds.addEvent("mouseout", function(){
  1656. this.setStyle("border", "1px solid #FFF");
  1657. // var d;
  1658. // switch (calendar.currentView) {
  1659. // case "day" :
  1660. // d = this.retrieve("dateValue");
  1661. // if (calendar.isEnableDate(d)) this.setStyle("border", "1px solid #FFF");
  1662. // break;
  1663. // default:
  1664. // this.setStyle("border", "1px solid #FFF");
  1665. // break;
  1666. // }
  1667. });
  1668. }else{
  1669. switch (this.currentView) {
  1670. case "day" :
  1671. table.setStyles(this.css.calendarDaysContent);
  1672. tds.setStyles(this.css.calendarDaysContentTd);
  1673. break;
  1674. case "month" :
  1675. table.setStyles(this.css.calendarMonthsContent);
  1676. tds.setStyles(this.css.calendarMonthsContentTd);
  1677. break;
  1678. case "year" :
  1679. this.yearLength = tds.length;
  1680. table.setStyles(this.css.calendarYearsContent);
  1681. tds.setStyles(this.css.calendarYearsContentTd);
  1682. break;
  1683. case "time" :
  1684. if( this.options.style.indexOf("mobile") > -1 ){
  1685. var nodes = table.getElements(".calendarTimeContent_mobile");
  1686. if (nodes.length) nodes.setStyles(this.css.calendarTimeContent_mobile);
  1687. nodes = table.getElements(".calendarTimeFixWidthNode_mobile");
  1688. if (nodes.length) nodes.setStyles(this.css.calendarTimeFixWidthNode_mobile);
  1689. nodes = table.getElements(".calendarTimeWheels_mobile");
  1690. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheels_mobile);
  1691. nodes = table.getElements(".calendarTimeWheel_mobile");
  1692. if (nodes.length) nodes.setStyles(this.css.calendarTimeWheel_mobile);
  1693. nodes = table.getElements(".calendarTimeSelectContainer_mobile");
  1694. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectContainer_mobile);
  1695. nodes = table.getElements(".calendarTimeSelectLine_mobile");
  1696. if (nodes.length) nodes.setStyles(this.css.calendarTimeSelectLine_mobile);
  1697. nodes = table.getElements(".calendarTimeShadowMask_mobile");
  1698. if (nodes.length) nodes.setStyles(this.css.calendarTimeShadowMask_mobile);
  1699. var node = table.getElement(".MWF_calendar_action_show");
  1700. if (node){
  1701. node.setStyles(this.css.calendarActionShow);
  1702. //var buttons = node.getElements("button");
  1703. //buttons.setStyles(this.css.calendarActionShowButton);
  1704. }
  1705. }else{
  1706. var nodes = table.getElements(".calendarTimeArea");
  1707. if (nodes.length) nodes.setStyles(this.css.calendarTimeArea);
  1708. nodes = table.getElements(".calendarTimeSlider");
  1709. if (nodes.length) nodes.setStyles(this.css.calendarTimeSlider);
  1710. nodes = table.getElements(".calendarTimeSliderKnob");
  1711. if (nodes.length) nodes.setStyles(this.css.calendarTimeSliderKnob);
  1712. nodes = table.getElements(".calendarTimeShow");
  1713. if (nodes.length) nodes.setStyles(this.css.calendarTimeShow);
  1714. nodes = table.getElements(".calendarTimeShowItem");
  1715. if (nodes.length) nodes.setStyles(this.css.calendarTimeShowItem);
  1716. var node = table.getElement(".MWF_calendar_action_show");
  1717. if (node){
  1718. node.setStyles(this.css.calendarActionShow);
  1719. var buttons = node.getElements("button");
  1720. buttons.setStyles(this.css.calendarActionShowButton);
  1721. }
  1722. }
  1723. break;
  1724. default :
  1725. //nothing;
  1726. }
  1727. }
  1728. return table;
  1729. },
  1730. setRange: function(){
  1731. if( this.options.datetimeRange && this.options.datetimeRange.length ){
  1732. this.setDatetimeRange();
  1733. }else{
  1734. if(this.options.dateRange && this.options.dateRange.length){
  1735. this.setDateRange();
  1736. }
  1737. if(this.options.timeRange && this.options.timeRange.length){
  1738. this.setTimeRange();
  1739. }
  1740. }
  1741. },
  1742. setDatetimeRange: function(){
  1743. var arr = this.options.datetimeRange;
  1744. var _2dArray = typeOf(arr[0]) !== "array" ? [arr] : arr;
  1745. if( !_2dArray[0][0] && !_2dArray[0][1] )return;
  1746. this.datetimeRange = [];
  1747. this.dateRange = [];
  1748. this.dateOnlyRange = [];
  1749. _2dArray.each(function(a){
  1750. var ds, de, ds1, de1, de2;
  1751. if(a[0])ds = typeOf(a[0]) === "date" ? a[0] : Date.parse(a[0]);
  1752. if(a[1])de = typeOf(a[1]) === "date" ? a[1] : Date.parse(a[1]);
  1753. this.datetimeRange.push([ds, de]);
  1754. if(ds){
  1755. ds1 = ds.clone().clearTime();
  1756. }
  1757. if(de){
  1758. de1 = de.clone().set({hr:23, min:59, sec:59});
  1759. de2 = de.clone().clearTime();
  1760. }
  1761. this.dateRange.push([ds1, de1]);
  1762. this.dateOnlyRange.push([ds1, de2]);
  1763. }.bind(this));
  1764. this.options.enableDate = function (date) {
  1765. var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
  1766. d.clearTime();
  1767. for( var i=0; i<this.dateRange.length; i++ ){
  1768. var ar = this.dateRange[i];
  1769. if( !ar[0] && this.isLessEquals(d, ar[1]) )return true;
  1770. if( !ar[1] && this.isLessEquals(ar[0], d) )return true;
  1771. if( this.isLessEquals(ar[0], d) && this.isLessEquals(d, ar[1]) )return true;
  1772. }
  1773. return false;
  1774. }.bind(this);
  1775. this.options.enableHours = function (date) {
  1776. var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
  1777. d.clearTime();
  1778. var hours = [];
  1779. for( var i=0; i<this.dateOnlyRange.length; i++ ){
  1780. var ar = this.dateOnlyRange[i];
  1781. var equal1 = this.isEquals(ar[0], d), equal2 = this.isEquals(d, ar[1]);
  1782. if( equal1 || equal2){
  1783. var s = equal1 ? this.datetimeRange[i][0].get("hr") : 0;
  1784. var e = equal2 ? this.datetimeRange[i][1].get("hr") : 23;
  1785. hours.push( [s, e] );
  1786. }
  1787. }
  1788. return hours.length ? o2.Calendar.RangeArrayUtils.union(hours) : [0, 23];
  1789. }.bind(this);
  1790. this.options.enableMinutes = function (date, hour) {
  1791. var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
  1792. d.clearTime();
  1793. var minutes = [];
  1794. for( var i=0; i<this.dateOnlyRange.length; i++ ){
  1795. var ar = this.dateOnlyRange[i];
  1796. var ardt = this.datetimeRange[i];
  1797. var equal1 = (this.isEquals(ar[0], d) && hour === ardt[0].get("hr"));
  1798. var equal2 = (this.isEquals(d, ar[1]) && hour === ardt[1].get("hr"));
  1799. if( equal1 || equal2 ){
  1800. var s = equal1 ? ardt[0].get("min") : 0;
  1801. var e = equal2 ? ardt[1].get("min") : 59;
  1802. minutes.push( [s, e] );
  1803. }
  1804. }
  1805. return minutes.length ? o2.Calendar.RangeArrayUtils.union(minutes) : [0, 59];
  1806. }.bind(this);
  1807. this.options.enableSeconds = function (date, hour, minute) {
  1808. var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
  1809. d.clearTime();
  1810. var seconds = [];
  1811. for( var i=0; i<this.dateOnlyRange.length; i++ ){
  1812. var ar = this.dateOnlyRange[i];
  1813. var ardt = this.datetimeRange[i];
  1814. var equal1 = (this.isEquals(ar[0], d) && hour === ardt[0].get("hr") && minute === ardt[0].get("min"));
  1815. var equal2 = (this.isEquals(d, ar[1]) && hour === ardt[1].get("hr") && minute === ardt[1].get("min"));
  1816. if( equal1 || equal2 ){
  1817. var s = equal1 ? ardt[0].get("sec") : 0;
  1818. var e = equal2 ? ardt[1].get("sec") : 59;
  1819. seconds.push( [s, e] );
  1820. }
  1821. }
  1822. return seconds.length ? o2.Calendar.RangeArrayUtils.union(seconds) : [0, 59];
  1823. }.bind(this);
  1824. },
  1825. setDateRange: function(){
  1826. var arr = this.options.dateRange;
  1827. var _2dArray = typeOf(arr[0]) !== "array" ? [arr] : arr;
  1828. if( !_2dArray[0][0] && !_2dArray[0][1] )return;
  1829. this.dateRange = [];
  1830. _2dArray.each(function(a){
  1831. var ds, de, ds1, de1;
  1832. if(a[0])ds = typeOf(a[0]) === "date" ? a[0] : Date.parse(a[0]);
  1833. if(a[1])de = typeOf(a[1]) === "date" ? a[1] : Date.parse(a[1]);
  1834. if(ds)ds1 = ds.clearTime();
  1835. if(de)de1 = de.set({hr:23, min:59, sec:59});
  1836. this.dateRange.push([ds1, de1]);
  1837. }.bind(this));
  1838. this.options.enableDate = function (date) {
  1839. var d = typeOf(date) === "string" ? Date.parse(date) : date.clone();
  1840. d.clearTime();
  1841. for( var i=0; i<this.dateRange.length; i++ ){
  1842. var ar = this.dateRange[i];
  1843. if( !ar[0] && this.isLessEquals(d, ar[1]) )return true;
  1844. if( !ar[1] && this.isLessEquals(ar[0], d) )return true;
  1845. if( this.isLessEquals(ar[0], d) && this.isLessEquals(d , ar[1]) )return true;
  1846. }
  1847. return false;
  1848. }.bind(this);
  1849. },
  1850. setTimeRange: function(){
  1851. var arr = this.options.timeRange;
  1852. var _2dArray = typeOf(arr[0]) !== "array" ? [arr] : arr;
  1853. if( !_2dArray[0][0] && !_2dArray[0][1] )return;
  1854. this.datetimeRange2 = [];
  1855. _2dArray.each(function(a){
  1856. var ds, de, ds1, de1;
  1857. if(a[0])ds = Date.parse("2020-01-01 "+a[0]);
  1858. if(a[1])de = Date.parse("2020-01-01 "+a[1]);
  1859. this.datetimeRange2.push([ds, de]);
  1860. }.bind(this));
  1861. this.options.enableHours = function (date) {
  1862. // var d = typeOf(date) === "string" ? Date.parse(date) : date;
  1863. if(this.hourRange)return this.hourRange;
  1864. var hours = [];
  1865. for( var i=0; i<this.datetimeRange2.length; i++ ){
  1866. var ar = this.datetimeRange2[i];
  1867. var s = ar[0] ? ar[0].get("hr") : 0;
  1868. var e = ar[1] ? ar[1].get("hr") : 23;
  1869. hours.push( [s, e] );
  1870. }
  1871. this.hourRange = o2.Calendar.RangeArrayUtils.union(hours);
  1872. return this.hourRange;
  1873. }.bind(this);
  1874. this.options.enableMinutes = function (date, hour) {
  1875. // var d = typeOf(date) === "string" ? Date.parse(date) : date;
  1876. var minutes = [];
  1877. for( var i=0; i<this.datetimeRange2.length; i++ ){
  1878. var ar = this.datetimeRange2[i];
  1879. var equal1 = (ar[0] && hour === ar[0].get("hr"));
  1880. var equal2 = (ar[1] && hour === ar[1].get("hr"));
  1881. if( equal1 || equal2 ){
  1882. var s = equal1 ? ar[0].get("min") : 0;
  1883. var e = equal2 ? ar[1].get("min") : 59;
  1884. minutes.push( [s, e] );
  1885. }
  1886. }
  1887. return minutes.length ? o2.Calendar.RangeArrayUtils.union(minutes) : [0, 59];
  1888. }.bind(this);
  1889. this.options.enableSeconds = function (date, hour, minute) {
  1890. // var d = typeOf(date) === "string" ? Date.parse(date) : date;
  1891. var seconds = [];
  1892. for( var i=0; i<this.datetimeRange2.length; i++ ){
  1893. var ar = this.datetimeRange2[i];
  1894. var equal1 = (ar[0] && hour === ar[0].get("hr") && minute === ar[0].get("min"));
  1895. var equal2 = (ar[1] && hour === ar[1].get("hr") && minute === ar[1].get("min"));
  1896. if( equal1 || equal2 ){
  1897. var s = equal1 ? ar[0].get("sec") : 0;
  1898. var e = equal2 ? ar[1].get("sec") : 59;
  1899. seconds.push( [s, e] );
  1900. }
  1901. }
  1902. return seconds.length ? o2.Calendar.RangeArrayUtils.union(seconds) : [0, 59];
  1903. }.bind(this);
  1904. },
  1905. isGreatEquals: function( d1, d2 ){
  1906. return (d1 > d2) || ((d1 - d2) === 0);
  1907. },
  1908. isLessEquals: function( d1, d2 ){
  1909. return (d1 < d2) || ((d1 - d2) === 0);
  1910. },
  1911. isEquals: function(d1, d2){
  1912. return (d1 - d2) === 0;
  1913. },
  1914. isEnableDate: function(date){
  1915. var fun = this.options.enableDate;
  1916. if( fun && typeOf(fun) === "function" ){
  1917. var d = typeOf( date ) === "string" ? new Date(date) : date;
  1918. if( fun( d ) === false ){
  1919. return false;
  1920. }
  1921. }
  1922. return true;
  1923. },
  1924. getEnableHours: function(date){
  1925. var fun = this.options.enableHours;
  1926. if( fun && typeOf(fun) === "function" ){
  1927. var d = typeOf( date ) === "string" ? new Date(date) : date;
  1928. return fun( d );
  1929. }
  1930. return [0, 23];
  1931. },
  1932. getDisabledHours: function(date){
  1933. var ar = this.getEnableHours(date);
  1934. if( !ar || !ar.length || (ar[0] === 0 && ar[1] === 23) )return [];
  1935. if( typeOf(ar[0]) !== "array" )ar = [ar];
  1936. return o2.Calendar.RangeArrayUtils.complementary([0, 23], ar, null, 1);
  1937. },
  1938. // getEnableHourStartEnd: function(date){
  1939. // var ar = this.getEnableHours(date);
  1940. // return this._getEnableStartEnd( ar, 0, 23 );
  1941. // },
  1942. isEnableHour: function (thisDate, hour) {
  1943. var hs = this.getEnableHours( thisDate );
  1944. if( !hs || !hs.length || (hs[0] === 0 && hs[1] === 23) )return true;
  1945. if( typeOf(hs[0]) === "array" ){
  1946. for( var i=0; i< hs.length; i++ ){
  1947. var dhs = hs[i];
  1948. if( dhs[0] <= hour && hour <= dhs[1] )return true;
  1949. }
  1950. }else{
  1951. if( hs[0] <= hour && hour <= hs[1] )return true;
  1952. }
  1953. return false;
  1954. },
  1955. getEnableMinutes: function(date, h){
  1956. var fun = this.options.enableMinutes;
  1957. if( fun && typeOf(fun) === "function" ){
  1958. var d = typeOf( date ) === "string" ? new Date(date) : date;
  1959. return fun( d, h );
  1960. }
  1961. return [0, 59];
  1962. },
  1963. getDisabledMinutes: function(date, h){
  1964. var ar = this.getEnableMinutes(date, h);
  1965. if( !ar || !ar.length || (ar[0] === 0 && ar[1] === 59))return [];
  1966. if( typeOf(ar[0]) !== "array" )ar = [ar];
  1967. return o2.Calendar.RangeArrayUtils.complementary([0, 59], ar, null, 1);
  1968. },
  1969. isEnableMinute: function (thisDate, hour, minute) {
  1970. var ms = this.getEnableMinutes( thisDate, hour );
  1971. if( !ms || !ms.length || (ms[0] === 0 && ms[1] === 59))return true;
  1972. if( typeOf(ms[0]) === "array" ){
  1973. for( var i=0; i< ms.length; i++ ){
  1974. var dms = ms[i];
  1975. if( dms[0] <= minute && minute <= dms[1] )return true;
  1976. }
  1977. }else{
  1978. if( ms[0] <= minute && minute <= ms[1] )return true;
  1979. }
  1980. return false;
  1981. },
  1982. getEnableSeconds: function(date, h, m){
  1983. var fun = this.options.enableSeconds;
  1984. if( fun && typeOf(fun) === "function" ){
  1985. var d = typeOf( date ) === "string" ? new Date(date) : date;
  1986. return fun( d, h, m );
  1987. }
  1988. return [0, 59];
  1989. },
  1990. getDisabledSeconds: function(date, h, m){
  1991. var ar = this.getEnableSeconds(date, h, m);
  1992. if( !ar || !ar.length || (ar[0] === 0 && ar[1] === 59))return [];
  1993. if( typeOf(ar[0]) !== "array" )ar = [ar];
  1994. return o2.Calendar.RangeArrayUtils.complementary([0, 59], ar, null, 1);
  1995. },
  1996. isEnableSecond: function (thisDate, hour, minute, second) {
  1997. var ss = this.getEnableSeconds( thisDate, hour, minute );
  1998. if( !ss || !ss.length || (ss[0] === 0 && ss[1] === 59))return true;
  1999. if( typeOf(ss[0]) === "array" ){
  2000. for( var i=0; i< ss.length; i++ ){
  2001. var dss = ss[i];
  2002. if( dss[0] <= second && second <= dss[1] )return true;
  2003. }
  2004. }else{
  2005. if( ss[0] <= second && second <= ss[1] )return true;
  2006. }
  2007. return false;
  2008. }
  2009. // _getEnableStartEnd: function( ar, start, end ){
  2010. // if( !ar || !ar.length || (ar[0] === start && ar[1] === 23) )return [start, 23];
  2011. // var s, e;
  2012. // if( typeOf( ar[0] === "array" ) ){
  2013. // ar.each(function(a, i){
  2014. // s = i === 0 ? (a[0] || start ) : Math.min( s , a[0] || start );
  2015. // e = i === 0 ? (a[1] || end ) : Math.max( e, a[1] || end );
  2016. // })
  2017. // }else{
  2018. // s = ar[0] || start;
  2019. // e = ar[1] || end;
  2020. // }
  2021. // return [s, e];
  2022. // }
  2023. });
  2024. o2.Calendar.MobileSelect = new Class({
  2025. Implements: [Options, Events],
  2026. options: {
  2027. "lineHeight" : 40, //每个item的高度
  2028. "items": [],
  2029. "ratio" : 1, //滑动距离倍率
  2030. "currentItem" : 0
  2031. },
  2032. initialize: function (wheelNode, options) {
  2033. this.setOptions( options );
  2034. this.wheelNode = wheelNode;
  2035. this.sliderNode = wheelNode.getFirst();
  2036. this.options.itemIndex = this.options.items.indexOf(this.options.currentItem);
  2037. if( this.options.itemIndex < 0 )this.options.itemIndex = 0;
  2038. },
  2039. load : function(){
  2040. var _this = this;
  2041. this.curDistance = 0;
  2042. this.sliderNode.style.transform = "translate3d(0px, 80px, 0px)";
  2043. this.wheelNode.addEventListener('touchstart', function (event) {
  2044. _this.touch(event);
  2045. }, false);
  2046. this.wheelNode.addEventListener('touchend', function (event) {
  2047. _this.touch(event);
  2048. }, false);
  2049. this.wheelNode.addEventListener('touchmove', function (event) {
  2050. _this.touch(event);
  2051. }, false);
  2052. this.locatePostion( this.options.itemIndex );
  2053. },
  2054. touch: function (ev) {
  2055. var sliderNode = this.sliderNode;
  2056. ev = ev || window.event;
  2057. switch (ev.type) {
  2058. case "touchstart":
  2059. this.startTime = new Date();
  2060. this.startY = event.touches[0].clientY;
  2061. this.oldMoveY = this.startY;
  2062. break;
  2063. case "touchend":
  2064. this.moveEndY = event.changedTouches[0].clientY;
  2065. this.overTime = new Date();
  2066. var speed = (this.moveEndY - this.startY) / ( this.overTime - this.startTime );
  2067. var ratio = 1;
  2068. if( Math.abs(speed) > 0.7 ){
  2069. ratio = 5;
  2070. }else if( Math.abs(speed) < 0.2 ){
  2071. ratio = 0.7
  2072. }
  2073. this.offsetSum = ( this.moveEndY - this.startY ) * this.options.ratio * ratio;
  2074. this.updateCurDistance();
  2075. this.curDistance = this.fixPosition(this.curDistance);
  2076. this.movePosition( this.curDistance );
  2077. this.oversizeBorder = - ( this.options.items.length - 3) * this.options.lineHeight;
  2078. if (this.curDistance + this.offsetSum > 2 * this.options.lineHeight) {
  2079. this.curDistance = 2 * this.options.lineHeight;
  2080. setTimeout(function () {
  2081. this.movePosition( this.curDistance );
  2082. }.bind(this), 100);
  2083. } else if (this.curDistance + this.offsetSum < this.oversizeBorder) {
  2084. this.curDistance = this.oversizeBorder;
  2085. setTimeout(function () {
  2086. this.movePosition( this.curDistance );
  2087. }.bind(this), 100);
  2088. }
  2089. var idx = this.getCurIndex();
  2090. this.fireEvent( "change", [this.options.items[idx]]);
  2091. break;
  2092. case "touchmove":
  2093. ev.preventDefault();
  2094. this.moveY = event.touches[0].clientY;
  2095. this.overTime = new Date();
  2096. var speed = (this.moveY - this.oldMoveY) / ( this.overTime - this.oldOverTime );
  2097. var ratio = 1;
  2098. if( Math.abs(speed) > 0.7 ){
  2099. ratio = 5;
  2100. }else if( Math.abs(speed) < 0.2 ){
  2101. ratio = 0.7
  2102. }
  2103. this.offset = ( this.moveY - this.oldMoveY ) * this.options.ratio * ratio;
  2104. this.updateCurDistance();
  2105. this.curDistance = this.curDistance + this.offset;
  2106. this.movePosition( this.curDistance );
  2107. this.oldMoveY = this.moveY;
  2108. this.oldOverTime = this.overTime;
  2109. break;
  2110. }
  2111. },
  2112. resetItems: function( items, currentItem ){
  2113. this.options.items = items;
  2114. this.options.currentItem = currentItem;
  2115. this.options.itemIndex = this.options.items.indexOf(this.options.currentItem);
  2116. if( this.options.itemIndex < 0 )this.options.itemIndex = 0;
  2117. this.oversizeBorder = - ( this.options.items.length - 3) * this.options.lineHeight;
  2118. this.locatePostion( this.options.itemIndex );
  2119. },
  2120. calcDistance: function (index) {
  2121. return 2 * this.options.lineHeight - index * this.options.lineHeight;
  2122. },
  2123. setCurDistance: function ( index ) {
  2124. this.curDistance = this.calcDistance( index );
  2125. this.movePosition( this.curDistance );
  2126. },
  2127. fixPosition: function (distance) {
  2128. return -(this.getIndex(distance) - 2) * this.options.lineHeight;
  2129. },
  2130. getCurIndex : function(){
  2131. return this.getIndex( this.curDistance );
  2132. },
  2133. getIndex: function (distance) {
  2134. return Math.round((2 * this.options.lineHeight - distance) / this.options.lineHeight);
  2135. },
  2136. movePosition: function ( distance) {
  2137. this.sliderNode.style.webkitTransform = 'translate3d(0,' + distance + 'px, 0)';
  2138. this.sliderNode.style.transform = 'translate3d(0,' + distance + 'px, 0)';
  2139. },
  2140. locatePostion: function ( index ) {
  2141. this.curDistance = this.calcDistance(index);
  2142. this.movePosition( this.curDistance );
  2143. },
  2144. updateCurDistance: function () {
  2145. this.curDistance = parseInt(this.sliderNode.style.transform.split(',')[1]);
  2146. },
  2147. getDistance: function () {
  2148. return parseInt(this.sliderNode.style.transform.split(',')[1]);
  2149. }
  2150. });
  2151. o2.Calendar.RangeArrayUtils = {
  2152. //补集 range [ start, end ] rangeList [ [start1, end1], [ start2, end2 ] ... ]
  2153. complementary : function( range, rangeList, type, offset ){
  2154. if( !range )return range;
  2155. var r = this.getRangeObject( range );
  2156. if( !rangeList || rangeList.length == 0 )return this.parse( [r] , type);
  2157. var unitedList = this.union( rangeList );
  2158. var newRange = {};
  2159. if( unitedList[0][0] > r.start ){
  2160. newRange.start = r.start;
  2161. }else if( r.end > unitedList[0][1] ){
  2162. newRange.start = unitedList[0][1];
  2163. unitedList.shift();
  2164. }else{
  2165. return [];
  2166. }
  2167. var newList = [];
  2168. while( unitedList.length > 0 ){
  2169. if( unitedList[0][0] >= r.end ){
  2170. newRange.end = r.end;
  2171. newList.push( Object.clone(newRange) );
  2172. return this.parse( newList , type);
  2173. }else if( r.end <= unitedList[0][1] ){
  2174. newRange.end = unitedList[0][0];
  2175. newList.push( Object.clone(newRange) );
  2176. return this.parse( newList, type );
  2177. }else{
  2178. newRange.end = unitedList[0][0];
  2179. newList.push( Object.clone(newRange) );
  2180. newRange.start = unitedList[0][1];
  2181. unitedList.shift();
  2182. }
  2183. }
  2184. newRange.end = r.end;
  2185. newList.push( Object.clone(newRange ));
  2186. var array = this.parse( newList, type );
  2187. if( offset ){
  2188. return array.map(function (a) {
  2189. if( a[0] !== r.start )a[0] = a[0] + offset;
  2190. if( a[1] !== r.end )a[1] = a[1] - offset;
  2191. return a;
  2192. })
  2193. }else{
  2194. return array;
  2195. }
  2196. },
  2197. //取区域并集rangeList [ [start1, end1], [ start2, end2 ] ... ]
  2198. union : function( ranges, type ){
  2199. if( !ranges || ranges.length == 0)return ranges; //this.parse(this.getRangeObject( ranges ) ) ;
  2200. var rangeList = Array.clone( ranges );
  2201. for( var i=0; i<rangeList.length; i++ ){
  2202. rangeList[i] = this.getRangeObject( rangeList[i] );
  2203. }
  2204. rangeList.sort( function( a, b ){
  2205. return a.start - b.start;
  2206. });
  2207. var newRangeList = [];
  2208. var newRange = rangeList.shift();
  2209. while( rangeList.length > 0 ){
  2210. var nextRange = rangeList.shift();
  2211. if( this.isIntersection( newRange, nextRange ) ){
  2212. newRange.end = Math.max( newRange.end, nextRange.end );
  2213. }else{
  2214. newRangeList.push( Object.clone( newRange ) );
  2215. newRange = nextRange;
  2216. }
  2217. }
  2218. if( !nextRange ){
  2219. newRangeList.push( Object.clone( newRange ) );
  2220. }else if( this.isIntersection( newRange, nextRange ) ){
  2221. newRange.end = Math.max( newRange.end, nextRange.end );
  2222. newRangeList.push( Object.clone( newRange ) );
  2223. }else{
  2224. newRangeList.push( Object.clone( nextRange ) );
  2225. }
  2226. return this.parse( newRangeList, type );
  2227. },
  2228. //取区域交集rangeList [ [start1, end1], [ start2, end2 ] ... ],需要测试
  2229. intersection: function( ranges, type ){
  2230. if( !ranges || ranges.length == 0 )return ranges; //this.parse(this.getRangeObject( ranges ) ) ;
  2231. if( ranges.length === 1 )return ranges[1];
  2232. var rangeList = Array.clone( ranges );
  2233. for( var i=0; i<rangeList.length; i++ ){
  2234. rangeList[i] = this.getRangeObject( rangeList[i] );
  2235. }
  2236. rangeList.sort( function( a, b ){
  2237. return a.start - b.start;
  2238. });
  2239. var newRange = rangeList.shift();
  2240. while( rangeList.length > 0 ){
  2241. var nextRange = rangeList.shift();
  2242. if( this.isIntersection( newRange, nextRange ) ){
  2243. newRange.start = nextRange.start;
  2244. newRange.end = Math.min( newRange.end, nextRange.end );
  2245. }else{
  2246. return [];
  2247. }
  2248. }
  2249. if( type && type === "date" ){
  2250. return [ Date.parse(newRange.start), Date.parse(newRange.end) ];
  2251. }else{
  2252. return [newRange.start, newRange.end];
  2253. }
  2254. },
  2255. //区域是否相交
  2256. isIntersection : function( range1, range2 ){
  2257. var r1 = typeOf( range1 ) === "object" ? range1 : this.getRangeObject( range1 );
  2258. var r2 = typeOf( range2 ) === "object" ? range2 : this.getRangeObject( range2 );
  2259. if( r1.start > r2.end )return false;
  2260. if( r2.start > r1.end )return false;
  2261. return true;
  2262. },
  2263. parse: function( objectList, type ){
  2264. var list = [];
  2265. for( var i=0; i<objectList.length; i++ ){
  2266. var range = objectList[i];
  2267. if( type && type == "date" ){
  2268. list.push( [ Date.parse(range.start), Date.parse(range.end) ] );
  2269. }else{
  2270. list.push( [range.start, range.end] );
  2271. }
  2272. }
  2273. return list;
  2274. },
  2275. getRangeObject: function( range ){
  2276. return {
  2277. start : Math.min( range[0], range[1] ),
  2278. end : Math.max( range[0], range[1] )
  2279. }
  2280. }
  2281. };