CalculationDialog.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2013
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. dojo.provide("bux.dialogs.CalculationDialog");
  13. dojo.require("bux.dialogs.BaseCustomContentDialog");
  14. dojo.require("bux.layout.TableContainer");
  15. dojo.require("dijit.form.NumberTextBox");
  16. dojo.require("dijit.form.Button");
  17. dojo.declare("viewer.dialogs.CalculationDialog", bux.dialogs.BaseCustomContentDialog, {
  18. sTitle: null,
  19. sLabel: null, /*String the lablel of the calculation dialog*/
  20. sDescription: null,
  21. sContentLocale: null,
  22. okHandler: null, /*Function?*/
  23. cancelHandler:null, /*Function?*/
  24. startup: function() {
  25. this.updateTitle(this.sTitle);
  26. this.inherited(arguments);
  27. var tableContainer = new bux.layout.TableContainer({
  28. // TODO remove this class
  29. classname: "bux-InformationDialog"
  30. },this.contentContainer);
  31. var cell = null, row = null;
  32. if (this.sDescription) {
  33. row = new bux.layout.TableContainerRow({
  34. parentContainer: tableContainer
  35. });
  36. cell = new bux.layout.TableContainerCell({
  37. classname: "bux-dialog-info",
  38. parentContainer: row
  39. });
  40. cell.addContent(document.createTextNode(this.sDescription));
  41. dijit.setWaiState(this._buxBaseDialog.domNode, "describedBy", cell.id);
  42. }
  43. row = new bux.layout.TableContainerRow({
  44. parentContainer: tableContainer
  45. });
  46. cell = new bux.layout.TableContainerCell({
  47. classname: "bux-dialog-label",
  48. parentContainer: row
  49. });
  50. this._calculationField = new dijit.form.NumberTextBox({
  51. required:true,
  52. onBlur:function() {
  53. if(!this._cancelled && !this.isValid() ) {
  54. this.focus();
  55. }
  56. },
  57. _setOKBtnDisabled : function(oButtons, bDisabled) {
  58. //note: localized label compare (product locale)
  59. if(oButtons && oButtons[0] && oButtons[0].label === RV_RES.IDS_JS_OK) {
  60. oButtons[0].set("disabled", bDisabled);
  61. }
  62. },
  63. isValid: function(){
  64. //the constraints will apply locale information when doing validation
  65. var bIsValid = this.validator(this.get("displayedValue"), this.get("constraints"));
  66. this._setOKBtnDisabled(this.oDlgBtns, !bIsValid);
  67. return bIsValid;
  68. }
  69. });
  70. if (this.sContentLocale != null) {
  71. dojo.requireLocalization("dojo.cldr", "number", this.sContentLocale);
  72. this._calculationField.constraints = {
  73. locale: this.sContentLocale
  74. };
  75. }
  76. var _label = document.createElement("label");
  77. _label.appendChild(document.createTextNode(this.sLabel));
  78. _label.setAttribute("for", this._calculationField.id);
  79. cell.addContent(_label);
  80. row = new bux.layout.TableContainerRow({
  81. parentContainer: tableContainer
  82. });
  83. cell = new bux.layout.TableContainerCell({
  84. classname: "bux-dialog-field",
  85. parentContainer: row
  86. });
  87. cell.addContent(this._calculationField.domNode);
  88. this._calculationField.oDlgBtns = this._buxBaseDialog._aButtonObjects;
  89. },
  90. onOK : function()
  91. {
  92. if (this._calculationField.state != "Error")
  93. {
  94. this.inherited(arguments);
  95. this.okHandler(this._calculationField.get("value"));
  96. this.hide();
  97. }
  98. },
  99. onCancel : function() {
  100. //this flag is used to make sure that the tooltip for the numberTextBox is not set to the wrong node when
  101. //cancelled is called
  102. this._calculationField._cancelled = true;
  103. this.inherited( arguments );
  104. }
  105. });