console_form_handler.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Copyright (C) 2010-2016 Combodo SARL
  2. //
  3. // This file is part of iTop.
  4. //
  5. // iTop is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // iTop is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  17. //iTop Form handler
  18. ;
  19. $(function()
  20. {
  21. // the widget definition, where 'itop' is the namespace,
  22. // 'consoleform_handler' the widget name
  23. $.widget( 'itop.console_form_handler', $.itop.form_handler,
  24. {
  25. // default options
  26. options:
  27. {
  28. wizard_helper_var_name: '', // Name of the global variable pointing to the wizard helper
  29. custom_field_attcode: ''
  30. },
  31. // the constructor
  32. _create: function()
  33. {
  34. var me = this;
  35. this.element
  36. .addClass('console_form_handler');
  37. this.options.oWizardHelper = window[this.options.wizard_helper_var_name];
  38. this._super();
  39. },
  40. // events bound via _bind are removed automatically
  41. // revert other modifications here
  42. _destroy: function()
  43. {
  44. this.element
  45. .removeClass('console_form_handler');
  46. this._super();
  47. },
  48. _onUpdateFields: function(event, data)
  49. {
  50. var me = this;
  51. var sFormPath = data.form_path;
  52. var sUpdateUrl = GetAbsoluteUrlAppRoot()+'pages/ajax.render.php';
  53. $(this.element.find('[data-form-path="' + sFormPath + '"]')).block({message:''});
  54. $.post(
  55. sUpdateUrl,
  56. {
  57. operation: 'custom_fields_update',
  58. attcode: this.options.custom_field_attcode,
  59. //current_values: this.getCurrentValues(),
  60. requested_fields: data.requested_fields,
  61. form_path: sFormPath,
  62. json_obj: this.options.oWizardHelper.UpdateWizardToJSON()
  63. },
  64. function(data){
  65. me._onUpdateSuccess(data, sFormPath);
  66. }
  67. )
  68. .fail(function(data){ me._onUpdateFailure(data, sFormPath); })
  69. .always(function(data){
  70. me.alignColumns();
  71. $(me.element.find('[data-form-path="' + sFormPath + '"]')).unblock();
  72. me._onUpdateAlways(data, sFormPath);
  73. });
  74. },
  75. // On initialization or update
  76. alignColumns: function()
  77. {
  78. var iMaxWidth = 0;
  79. var oLabels = $(this.element.find('td.form-field-label'));
  80. // Reset the width to the automatic (original) value
  81. oLabels.width('');
  82. oLabels.each(function() {
  83. iMaxWidth = Math.max(iMaxWidth, $(this).width());
  84. });
  85. oLabels.width(iMaxWidth);
  86. },
  87. // Intended for overloading in derived classes
  88. _onSubmitClick: function()
  89. {
  90. },
  91. // Intended for overloading in derived classes
  92. _onCancelClick: function()
  93. {
  94. },
  95. // Intended for overloading in derived classes
  96. _onUpdateFailure: function(data)
  97. {
  98. },
  99. // Intended for overloading in derived classes
  100. _disableFormBeforeLoading: function()
  101. {
  102. },
  103. // Intended for overloading in derived classes
  104. _enableFormAfterLoading: function()
  105. {
  106. },
  107. });
  108. });