RenameDialog.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2018
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. /**
  8. * Simple Dialog to Create a New Board
  9. */
  10. define(['../../../lib/@waca/core-client/js/core-client/ui/dialogs/BaseDialog', 'jquery', 'underscore', '../../nls/StringResources'], function (BaseDialog, $, _, stringResources) {
  11. var Dialog = null;
  12. Dialog = BaseDialog.extend({
  13. /**
  14. * Rename dialog init function.
  15. * @param item object to rename
  16. * @param okCallback function that performs the rename
  17. */
  18. init: function init(item, okCallback) {
  19. Dialog.inherited('init', this, arguments);
  20. this._okCallback = okCallback;
  21. if (item) {
  22. this._currentName = _.unescape(item.name);
  23. this._type = item.type ? item.type : 'Board';
  24. this._allowEmpty = item.allowEmpty ? true : false;
  25. } else {
  26. this._type = 'Board';
  27. this._allowEmpty = false;
  28. }
  29. this.$input = $('<input>', {
  30. id: 'boardName',
  31. name: 'boardName',
  32. value: this._currentName,
  33. type: 'text',
  34. maxlength: '100',
  35. OnFocus: function OnFocus() {
  36. this.select();
  37. },
  38. on: { 'focus': function focus() {
  39. // 'this' is the jquery instance object, we don't want to bind(this)
  40. this.setSelectionRange(0, 9999);
  41. } }
  42. });
  43. this.$input.on('input', this.toggleOk.bind(this));
  44. },
  45. renderContent: function renderContent(n) {
  46. this.$form = $('<form>', {
  47. id: 'renameBoardForm',
  48. action: 'board',
  49. method: 'post',
  50. 'class': 'boardActionDlgForm'
  51. });
  52. this.$form.append($('<label>', {
  53. 'for': 'boardName',
  54. form: this.$form[0].id,
  55. text: stringResources.get('dlg_NewNameLabel')
  56. }));
  57. this.$form.append(this.$input);
  58. n.append(this.$form);
  59. n.addClass('boardActionDlgContent');
  60. return n;
  61. },
  62. open: function open() {
  63. Dialog.inherited('open', this, arguments);
  64. this.$input.focus();
  65. },
  66. renderTitle: function renderTitle(n) {
  67. var resName = 'dlg_rename';
  68. resName += this._type;
  69. resName += 'Title';
  70. n.text(stringResources.get(resName));
  71. return n;
  72. },
  73. ok: function ok() {
  74. var boardName = this.$input.val();
  75. if (boardName.trim().length !== 0 || this._allowEmpty) {
  76. Dialog.inherited('ok', this, arguments);
  77. if (boardName !== this._currentName) {
  78. this._okCallback(boardName);
  79. }
  80. }
  81. },
  82. toggleOk: function toggleOk() /* evt */{
  83. var boardName = this.$input.val().trim();
  84. if (boardName.length === 0 && !this._allowEmpty) {
  85. Dialog.inherited('disableOk', this, arguments);
  86. } else {
  87. Dialog.inherited('enableOk', this, arguments);
  88. }
  89. },
  90. //@overrides
  91. onKey: function onKey(evt) {
  92. var keyCode = evt.keyCode;
  93. // Prevent default auto submit on the input control
  94. if (keyCode === 13 && evt.target.id === this.$input[0].id) {
  95. return false;
  96. }
  97. return Dialog.inherited('onKey', this, arguments);
  98. }
  99. });
  100. return Dialog;
  101. });
  102. //# sourceMappingURL=RenameDialog.js.map