/* Copyright (c) Business Objects 2006. All rights reserved. */ if (typeof bobj == 'undefined') { bobj = {}; } if (typeof bobj.crv == 'undefined') { bobj.crv = {}; } if (typeof bobj.crv.Calendar == 'undefined') { bobj.crv.Calendar = {}; } /* ================================================================================ Calendar Widget ================================================================================ */ /** * Get a shared calendar instance */ bobj.crv.Calendar.getInstance = function() { if (!bobj.crv.Calendar.__instance) { bobj.crv.Calendar.__instance = bobj.crv.newCalendar(); } return bobj.crv.Calendar.__instance; }; bobj.crv.Calendar.Signals = { OK_CLICK: 'okClick', CANCEL_CLICK: 'cancelClick', ON_HIDE: 'onHide' }; bobj.crv.newCalendar = function(kwArgs) { var UPDATE = MochiKit.Base.update; kwArgs = UPDATE({ id: bobj.uniqueId() + "_calendar", showTime: false, date: new Date(), // List of formats to match in order of preference. Once a format is // matched, the time field will be displayed in that format. timeFormats: ["HH:mm:ss", "H:mm:ss", "H:m:s", "HH:mm", "H:mm", "H:m", "h:mm:ss a", "h:m:s a", "h:mm:ssa", "h:m:sa", "h:mm a", "h:m a", "h:mma", "h:ma"] }, kwArgs); var o = newMenuWidget( ); o.widgetType = 'Calendar'; // Update instance with constructor arguments bobj.fillIn(o, kwArgs); // Update instance with member functions o._menuJustInTimeInit = o.justInTimeInit; UPDATE(o, bobj.crv.Calendar); o._curTimeFormat = o.timeFormats[0]; o._cells = []; o._firstDay = 0; o._numDays = 0; return o; }; bobj.crv.Calendar._createHeaderButtons = function() { var w = 8; var h = 4; var dx = 46; var dyUp = 0; var dyDown = 12; var bind = MochiKit.Base.bind; this._prevMonthBtn = newIconWidget(this.id+"_pm",_skin+'../lov.gif',bind(this._onPrevMonthClick, this),"",L_DHTMLLIB_calendarPrevMonthLab,w,h,dx,dyDown, true); this._prevYearBtn = newIconWidget(this.id+"_py",_skin+'../lov.gif',bind(this._onPrevYearClick, this),"",L_DHTMLLIB_calendarPrevYearLab,w,h,dx,dyDown, true); this._nextMonthBtn = newIconWidget(this.id+"_nm",_skin+'../lov.gif',bind(this._onNextMonthClick, this),"",L_DHTMLLIB_calendarNextMonthLab,w,h,dx,dyUp, true); this._nextYearBtn = newIconWidget(this.id+"_ny",_skin+'../lov.gif',bind(this._onNextYearClick, this),"",L_DHTMLLIB_calendarNextYearLab,w,h,dx,dyUp, true); this._prevMonthBtn.allowDblClick = true; this._prevYearBtn.allowDblClick = true; this._nextMonthBtn.allowDblClick = true; this._nextYearBtn.allowDblClick = true; }; bobj.crv.Calendar._createTimeTextField = function() { var bind = MochiKit.Base.bind; this._timeField = newTextFieldWidget( this.id + '_time', bind(this._onTimeChange, this), //changeCB null, //maxChar null, //keyUpCB null, //enterCB true, //noMargin null, //tooltip null, //width null, //focusCB null); //blurCB }; bobj.crv.Calendar._createOKCancelButtons = function() { var bind = MochiKit.Base.bind; this._okBtn = newButtonWidget(this.id + "_ok", L_bobj_crv_OK, bind(this._onOKClick, this)); this._cancelBtn = newButtonWidget(this.id + "_cancel", L_bobj_crv_Cancel, bind(this._onCancelClick, this)); }; /** * Widget will auto-initialize the first time its show method is called. * Client code shoud not call this method. */ bobj.crv.Calendar.justInTimeInit = function() { this._menuJustInTimeInit(); this._prevMonthBtn.init(); this._prevYearBtn.init(); this._nextMonthBtn.init(); this._nextYearBtn.init(); this._okBtn.init(); this._cancelBtn.init(); this._timeField.init(); this._timeField.layer.style.width = '100%'; this._timeField.setValue(bobj.external.date.formatDate(this.date, this._curTimeFormat)); this._timeRow = getLayer(this.id + '_timeRow'); this._timeSep = getLayer(this.id + '_timeSep'); this._month = getLayer(this.id + "_month"); this._year = getLayer(this.id + "_year"); var numCells = 6 * 7; // six rows in the calendar with 7 days each for (var i = 0; i < numCells; i++) { this._cells[i] = getLayer(this.id + '_c' + i); } this._update(); }; /** * Widget will be written into the document the first time its show method is called. * Client code shoud not call this method. */ bobj.crv.Calendar.getHTML = function() { var h = bobj.html; var TABLE = h.TABLE; var TBODY = h.TBODY; var TR = h.TR; var TD = h.TD; var DIV = h.DIV; var SPAN = h.SPAN; var A = h.A; this._createHeaderButtons(); this._createTimeTextField(); this._createOKCancelButtons(); var onkeydown = _dhtmlLib + ".MenuWidget_keyDown('" + this.id + "', event); return true"; var onmousedown = _dhtmlLib + ".eventCancelBubble(event)"; var onmouseup = _dhtmlLib + ".eventCancelBubble(event)"; var onkeypress = _dhtmlLib + ".eventCancelBubble(event)"; var dayHeaderAtt = {'class':"calendarTextPart"}; // viewer workflow - use bobj.crv.config // CAF (CR2013) workflow - use bobj.prompt var isRTL = (bobj.crv.config && bobj.crv.config.isRTL) || (bobj.prompt && bobj.prompt.isRTL); var tableDir = isRTL ? "rtl" : "ltr"; var buttonsAlign = isRTL ? "left" : "right"; var html = TABLE({dir: tableDir, id: this.id, border:"0", cellpadding:"0", cellspacing:"0", onkeydown: onkeydown, onmousedown: onmousedown, onmouseup: onmouseup, onkeypress: onkeypress, 'class':"menuFrame", style:{cursor:"default", visibility:"hidden",'z-index': 10000}}, TBODY(null, TR(null, TD(null, this._getMonthYearHTML())), TR(null, TD({align:"center"}, TABLE({border:"0", cellspacing:"0", cellpadding:"0", style:{margin:"2px", 'margin-top': "6px"}}, TR({align:"center"}, TD(dayHeaderAtt, L_bobj_crv_SundayShort), TD(dayHeaderAtt, L_bobj_crv_MondayShort), TD(dayHeaderAtt, L_bobj_crv_TuesdayShort), TD(dayHeaderAtt, L_bobj_crv_WednesdayShort), TD(dayHeaderAtt, L_bobj_crv_ThursdayShort), TD(dayHeaderAtt, L_bobj_crv_FridayShort), TD(dayHeaderAtt, L_bobj_crv_SaturdayShort)), TR(null, TD({colspan:"7", style:{padding:"2px"}}, this._getSeparatorHTML())), this._getDaysHTML(), TR(null, TD({colspan:"7", style:{padding:"2px"}}, this._getSeparatorHTML())), TR({id:this.id + '_timeRow', style:{display:this.showTime ? '' : 'none'}}, TD({colspan:"7", style:{'padding-top':"3px", 'padding-bottom':"3px", 'padding-right':"10px", 'padding-left':"10px"}}, this._timeField.getHTML())), TR({id:this.id + '_timeSep',style:{display:this.showTime ? '' : 'none'}}, TD({colspan:"7", style:{padding:"2px"}}, this._getSeparatorHTML())), TR(null, TD({colspan:"7", align:buttonsAlign, style:{'padding-bottom':"3px", 'padding-top':"3px"}}, TABLE(null, TBODY(null, TR(null, TD(null, this._okBtn.getHTML()), TD(null, this._cancelBtn.getHTML()))))))))))); return this._getLinkHTML('startLink_' + this.id, true) + html + this._getLinkHTML('endLink_' + this.id, false); }; bobj.crv.Calendar._getMonthYearHTML = function() { var h = bobj.html; var TABLE = h.TABLE; var TBODY = h.TBODY; var TR = h.TR; var TD = h.TD; var DIV = h.DIV; var SPAN = h.SPAN; return TABLE({'class':"dialogzone", width:"100%", cellpadding:"0", cellspacing:"0"}, TBODY(null, TR(null, TD({style:{'padding-top':"1px"}}, this._nextMonthBtn.getHTML()), TD({rowspan:"2", width:"100%", align:"center", 'class':"dialogzone"}, SPAN({id:this.id + "_month", tabIndex:"0"}, L_DHTMLLIB_month[this.date.getMonth()]), " ", SPAN({id:this.id + "_year", tabIndex:"0"}, this.date.getFullYear())), TD({style:{'pading-top':"1px"}}, this._nextYearBtn.getHTML())), TR({valign:"top"}, TD({style:{'padding-bottom':"1px"}}, this._prevMonthBtn.getHTML()), TD({style:{'padding-bottom':"1px"}}, this._prevYearBtn.getHTML())))); }; bobj.crv.Calendar._getSeparatorHTML = function() { var sep=newSeparatorWidget(bobj.uniqueId(),null,0,0,0,0); return sep.getHTML(); }; bobj.crv.Calendar._getLinkHTML = function(id, isFocusLastChild) { return bobj.html.A({ id: id, href: "javascript:void(0)", onfocus: "MenuWidget_keepFocus('"+this.id+"'," + isFocusLastChild + ")", /*focus next month*/ style:{ visibility:"hidden", position:"absolute", top : "-1000px", left : '-1000px' }}); }; bobj.crv.Calendar._getDaysHTML = function() { var TD = bobj.html.TD; var DIV = bobj.html.DIV; var html = ''; for (var i = 0; i < 6; ++i) { html += '