📄 db.js
字号:
/* db.js{{IS_NOTE Purpose: datebox Description: History: Mon Oct 17 15:24:01 2005, Created by tomyeh}}IS_NOTECopyright (C) 2005 Potix Corporation. All Rights Reserved.{{IS_RIGHT This program is distributed under GPL Version 2.0 in the hope that it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/zk.load("zul.zul"); //msgzulzk.load("zul.widget");//Calendar//zkCal = {};zk.Cal = Class.create();zk.Cal.prototype = { initialize: function (cmp, popup) { this.id = cmp.id; this.popup = popup; this.input = $e(cmp.id + "!real"); this._newCal(); this.init(); }, cleanup: function () { if (this.fnSubmit) zk.unlisten(this.form, "submit", this.fnSubmit); this.element = this.fnSubmit = null; }, _newCal: function() { this.element = $e(this.id); if (!this.element) return; var compact = getZKAttr(this.element, "compact") == "true"; var html = this.popup ? '<table border="0" cellspacing="0" cellpadding="0" tabindex="-1">': ''; html += '<tr><td><table class="calyear" width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="5"></td><td align="right"><img src="' +zk.getUpdateURI('/web/zul/img/cal/arrowL.gif') +'" style="cursor:pointer" onclick="zkCal.onyearofs(event,-1)" id="' +this.id+'!ly"/></td>'; if (compact) html += '<td align="right"><img src="'+zk.getUpdateURI('/web/zul/img/cal/arrow2L.gif') +'" style="cursor:pointer" onclick="zkCal.onmonofs(event,-1)" id="' +this.id+'!lm"/></td>'; html += '<td width="5"></td><td id="'+this.id+'!title"></td><td width="5"></td>'; if (compact) html += '<td align="left"><img src="'+zk.getUpdateURI('/web/zul/img/cal/arrow2R.gif') +'" style="cursor:pointer" onclick="zkCal.onmonofs(event,1)" id="' +this.id+'!rm"/></td>'; html += '<td align="left"><img src="'+zk.getUpdateURI('/web/zul/img/cal/arrowR.gif') +'" style="cursor:pointer" onclick="zkCal.onyearofs(event,1)" id="' +this.id+'!ry"/></td><td width="5"></td></tr></table></td></tr>'; if (!compact) { html += '<tr><td><table class="calmon" width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'; for (var j = 0 ; j < 12; ++j) { html += '<td id="'+this.id+'!m'+j +'" onclick="zkCal.onmonclk(event)" onmouseover="zkCal.onover(event)" onmouseout="zkCal.onout(event)">' + zk.S2MON[j] + '</td>'; if (j == 5) html += '</tr><tr>'; } html += '</tr></table></td></tr>'; } if (this.popup) html += '<tr><td height="3px"></td></tr>'; html += '<tr><td><table class="calday" width="100%" border="0" cellspacing="0" cellpadding="0"><tr class="caldow">'; var sun = (7 - zk.DOW_1ST) % 7, sat = (6 + sun) % 7; for (var j = 0 ; j < 7; ++j) { html += '<td'; if (j == sun || j == sat) html += ' style="color:red"'; html += '>' + zk.S2DOW[j] + '</td>'; } html += '</tr>'; for (var j = 0; j < 6; ++j) { //at most 7 rows html += '<tr class="calday" id="'+this.id+'!w'+j +'" onclick="zkCal.ondayclk(event)" onmouseover="zkCal.onover(event)" onmouseout="zkCal.onout(event)">'; for (var k = 0; k < 7; ++k) html += '<td></td>'; html += '</tr>' } html += '</table></td></tr>'; if (this.popup) html += '</table>'; zk.setInnerHTML(this.popup || this.element, html); this.form = zk.formOf(this.element); if (this.form && !this.fnSubmit) { var meta = this; this.fnSubmit = function () { meta.onsubmit(); }; zk.listen(this.form, "submit", this.fnSubmit); } }, init: function () { this.element = $e(this.id); if (!this.element) return; var val = this.input ? this.input.value: getZKAttr(this.element, "value"); if (val) val = zk.parseDate(val, this.getFormat()); this.date = val ? val: this.today(); this._output(); }, getFormat: function () { var fmt = getZKAttr(this.element, "fmt"); return fmt ? fmt: "yyyy/MM/dd"; }, today: function () { var d = new Date(); return new Date(d.getFullYear(), d.getMonth(), d.getDate()); }, _output: function () { //year var val = this.date, m = val.getMonth(), d = val.getDate(); var y = val.getFullYear(); var el = $e(this.id + "!title"); zk.setInnerHTML(el, zk.SMON[m] + ', ' + y); //month for (var j = 0; j < 12; ++j) { el = $e(this.id + "!m" + j); if (el) { //omitted if compact el.className = m == j ? "seld": ""; el.setAttribute("zk_mon", j); } } var last = new Date(y, m + 1, 0).getDate(), //last date of this month prev = new Date(y, m, 0).getDate(); //last date of previous month var v = new Date(y, m, 1).getDay()- zk.DOW_1ST; if (v < 0) v += 7; for (var j = 0, cur = -v + 1; j < 6; ++j) { el = $e(this.id + "!w" +j); for (var k = 0; k < 7; ++k, ++cur) { v = cur <= 0 ? prev + cur: cur <= last ? cur: cur - last; if (k == 0 && cur > last) el.style.display = "none"; else { if (k == 0) el.style.display = ""; var cell = el.cells[k]; cell.style.textDecoration = ""; cell.setAttribute("zk_day", v); cell.setAttribute("zk_monofs", cur <= 0 ? -1: cur <= last ? 0: 1); this._outcell(cell, cur == d); } } } }, _outcell: function (cell, sel) { if (sel) this.curcell = cell; cell.className = sel ? "seld": ""; var d = cell.getAttribute("zk_day"); zk.setInnerHTML(cell, !sel || this.popup ? d: '<a href="javascript:;" onkeyup="zkCal.onup(event)" on' +(zk.ie ? "keydown": "keypress") +'="zkCal.onkey(event)" onblur="zkCal.onblur(event)">'+d+'</a>'); //IE: use keydown. otherwise, it causes the window to scroll }, _ondayclk: function (cell) { var y = this.date.getFullYear(), m = this.date.getMonth(); var d = zk.getIntAttr(cell, "zk_day"); if (cell.className != "seld") { //!selected var monofs = zk.getIntAttr(cell, "zk_monofs"); this.date = new Date(y, m + monofs, d); if (!this.popup) { if (monofs != 0) this._output(); else { this._outcell(this.curcell, false); this._outcell(cell, true); } } } this._onupdate(true); }, _onmonclk: function (cell) { if (cell.className != "seld") { //!selected var y = this.date.getFullYear(), d = this.date.getDate(); this.date = new Date(y, zk.getIntAttr(cell, "zk_mon"), d); this._output(); this._onupdate(false); } }, _onyearofs: function (ofs) { var y = this.date.getFullYear(), m = this.date.getMonth(), d = this.date.getDate(); this.date = new Date(y + ofs, m, d); this._output(); this._onupdate(false); }, _onmonofs: function (ofs) { var y = this.date.getFullYear(), m = this.date.getMonth(), d = this.date.getDate(); this.date = new Date(y, m + ofs, d); this._output(); this._onupdate(false); }, setDate: function (val) { if (val != this.date) { var old = this.date; if (old.getFullYear() != val.getFullYear() || old.getMonth() != val.getMonth()) { this.date = val; this._output(); } else { this.date = val; this._outcell(this.curcell, false); var d = val.getDate(); for (var j = 0; j < 6; ++j) { el = $e(this.id + "!w" +j); for (var k = 0; k < 7; ++k) { var cell = el.cells[k]; if (zk.getIntAttr(cell, "zk_monofs") == 0 && zk.getIntAttr(cell, "zk_day") == d) { this._outcell(cell, true); break; } } } } } }, /** Calls selback or onchange depending on this.popup. */ _onupdate: function (close) { this._output(); if (this.popup) { this.selback(close); if (this.input) { //Request 1551019: better responsive this.onchange(); zk.asyncFocus(this.input.id); } } else { this.onchange(); zk.asyncFocusDown(this.id, zk.ie ? 50: 0); } }, onchange: function () { if (this.popup) { zkTxbox.updateChange(this.input, false); } else { var y = this.date.getFullYear(), m = this.date.getMonth(), d = this.date.getDate(); setZKAttr(this.element, "value", this.getDateString()); zkau.send({uuid: this.id, cmd: "onChange", data: [y+'/'+(m+1)+'/'+d]}, zkau.asapTimeout(this.element, "onChange")); this._changed = false; } }, selback: function (close) { if (this.input) { this.input.value = this.getDateString(); zk.asyncFocus(this.input.id); zk.asyncSelect(this.input.id); } if (close) zkau.closeFloats(this.element); }, getDateString: function () { return zk.formatDate(this.date, this.getFormat()); }, shift: function (days) { var val = this.date; this.setDate(new Date( val.getFullYear(), val.getMonth(), val.getDate() + days)); }, onsubmit: function () { var nm = getZKAttr(this.element, "name"); if (!nm || !this.form) return; var val = getZKAttr(this.element, "value"), el = this.form.elements[nm]; if (el) el.value = val; else zk.newHidden(nm, val, this.form); }};zkCal.init = function (cmp) { var meta = zkau.getMeta(cmp); if (meta) meta.init(); else zkau.setMeta(cmp, new zk.Cal(cmp, null));};zkCal.setAttr = function (cmp, nm, val) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -