promptengine_calendar2.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. if(typeof(bobj) == "undefined") bobj = {};
  2. if(typeof(bobj.prompt) == "undefined") bobj.prompt = {};
  3. bobj.prompt.Calendar = function(formName,dateFormat,locale,promptJsFilePrefix) {
  4. this.locale = locale;
  5. this.crystalreportviewerPath = promptJsFilePrefix + '/../';
  6. this.loadFiles();
  7. this.formName = formName;
  8. this.dateFormat = dateFormat;
  9. this.dateTimeFormat = dateFormat + " " + "H:mm:ss";
  10. this.isDateTime = false;
  11. }
  12. bobj.prompt.Calendar.prototype = {
  13. /*
  14. * shows calendar for the specified input
  15. * @param e [event]
  16. * @param inputName [DOM element] The node that will receive the calendar value
  17. */
  18. show : function(e,inputName) {
  19. this.calendar = bobj.crv.Calendar.getInstance();
  20. this.input = document.getElementById (inputName);
  21. var srcElem = e.target ? e.target : e.srcElement;
  22. var pos = this._getPosition(srcElem);
  23. this._setValue(this.input.value);
  24. this._setSignals(true); // sets OK, and cancel event handlers
  25. this.calendar.setShowTime(this.isDateTime);
  26. this.calendar.show(true,pos.x,pos.y);
  27. },
  28. setIsDateTime : function(isDateTime) {
  29. this.isDateTime = isDateTime;
  30. },
  31. _getPosition : function(element) {
  32. return MochiKit.Style.getElementPosition(element);
  33. },
  34. _setValue : function(value) {
  35. var date = this._getDateValue(value);
  36. if(!date) {
  37. date = new Date();
  38. }
  39. this.calendar.setDate(date);
  40. },
  41. _onOkayClick : function(dateValue) {
  42. this._setFieldValue(dateValue);
  43. },
  44. _setFieldValue : function(dateValue) {
  45. if(this.input) {
  46. this.input.value = this._getStringValue(dateValue);
  47. }
  48. },
  49. _onHide : function() {
  50. this._removeSignals();
  51. },
  52. _getStringValue : function(dateValue) {
  53. var format = this.isDateTime ? this.dateTimeFormat : this.dateFormat;
  54. return bobj.external.date.formatDate(dateValue, format);
  55. },
  56. _getDateValue : function(stringValue) {
  57. var format = this.isDateTime ? this.dateTimeFormat : this.dateFormat;
  58. return bobj.external.date.getDateFromFormat(stringValue, format);
  59. },
  60. _setSignals: function(isConnected) {
  61. var op = isConnected ? MochiKit.Signal.connect : MochiKit.Signal.disconnect;
  62. op(this.calendar, this.calendar.Signals.OK_CLICK, this, '_onOkayClick');
  63. op(this.calendar, this.calendar.Signals.ON_HIDE, this, '_onHide');
  64. },
  65. _removeSignals: function() {
  66. this._setSignals(false);
  67. },
  68. loadJsResources : function() {
  69. var resources = [
  70. 'js/external/date.js',
  71. 'js/MochiKit/Base.js',
  72. 'js/MochiKit/DOM.js',
  73. 'js/MochiKit/Style.js',
  74. 'js/MochiKit/Signal.js',
  75. 'js/dhtmllib/dom.js',
  76. 'prompting/js/initDhtmlLib.js',
  77. 'js/dhtmllib/palette.js',
  78. 'js/dhtmllib/menu.js',
  79. 'js/crviewer/html.js',
  80. 'js/crviewer/common.js',
  81. 'js/crviewer/Calendar.js'
  82. ]
  83. for(var i = 0 ; i < resources.length; i++) {
  84. this.loadJsFile(resources[i]);
  85. }
  86. },
  87. loadJsFile : function(uri) {
  88. document.write("<script src=\"" + this.crystalreportviewerPath + uri + "\" language=\"javascript\"></script>");
  89. },
  90. loadLocaleStrings: function() {
  91. var localeFiles = [
  92. 'js/dhtmllib/language/en/labels.js',
  93. 'js/crviewer/strings_en.js'
  94. ]
  95. var splitChar = '_'; // default to java's locale split character
  96. if (this.locale.indexOf ('-') > 0)
  97. splitChar = '-'; // must be .Net's locale split
  98. var lang = this.locale.split(splitChar);
  99. if(lang.length >= 1) {
  100. localeFiles.push('js/dhtmllib/language/' + lang[0] + '/labels.js');
  101. localeFiles.push('js/crviewer/strings_' + lang[0] + '.js');
  102. }
  103. if(lang.length >= 2) {
  104. localeFiles.push('js/dhtmllib/language/' + lang[0] + '_' + lang[1] + '/labels.js');
  105. localeFiles.push('js/crviewer/strings_' + lang[0] + '_' + lang[1] + '.js');
  106. }
  107. for (var i = 0; i < localeFiles.length; i++) {
  108. this.loadJsFile(localeFiles[i]);
  109. }
  110. },
  111. loadFiles : function() {
  112. if(typeof(bobj.crv) == "undefined") {
  113. window["promptengine_skin"] = this.crystalreportviewerPath + "js/dhtmllib/images/skin_standard/";
  114. window["promptengine_style"] = this.crystalreportviewerPath + "js/crviewer/images/";
  115. window["promptengine_lang"] = this.locale;
  116. this.loadLocaleStrings();
  117. this.loadJsResources();
  118. }
  119. }
  120. };