EditableDialog.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. define(['../../../lib/@waca/core-client/js/core-client/ui/dialogs/BaseDialog', 'jquery', 'underscore', '../../nls/StringResources'], function (BaseDialog, $, _, stringResources) {
  8. var Dialog = null;
  9. Dialog = BaseDialog.extend({
  10. init: function init(options) {
  11. this._props = {
  12. 'type': options.sType,
  13. 'title': options.sTitle,
  14. 'value': options.sValue,
  15. 'actionHandler': options.actionHandler
  16. };
  17. // Add a close (predefined in BaseDialog), Copy and (optionally) a custom Save button
  18. this._close = {
  19. 'text': stringResources.get('close'),
  20. 'handler': this.cancel,
  21. 'type': options.updateable ? 'secondary' : 'primary'
  22. };
  23. this._buttons = [this._close];
  24. if (options.updateable) {
  25. this._buttons.push({
  26. 'text': stringResources.get('dlg_update'),
  27. 'handler': this.save,
  28. 'type': 'primary'
  29. });
  30. }
  31. this._buttons.push({
  32. 'text': stringResources.get('copyButton'),
  33. 'handler': this.copy,
  34. 'type': options.updateable ? 'secondary' : 'primary'
  35. });
  36. Dialog.inherited('init', this, arguments);
  37. },
  38. save: function save() {
  39. if (this._props.actionHandler && this._props.actionHandler(this.$textarea.val())) {
  40. this.hide();
  41. }
  42. },
  43. copy: function copy() {
  44. document.execCommand('copy');
  45. },
  46. focusOnButton: function focusOnButton() {
  47. var secondBtn = this._container().find('footer').children('.dialogButton')[1];
  48. if (secondBtn) {
  49. secondBtn.focus();
  50. }
  51. },
  52. show: function show() {
  53. Dialog.inherited('show', this, arguments);
  54. this.$textarea[0].select();
  55. },
  56. renderContent: function renderContent(n) {
  57. this.$textarea = $('<textarea>', {
  58. 'class': 'dashboardMessageBox ' + this._props.type,
  59. 'html': _.escape(this._props.value)
  60. });
  61. n.append(this.$textarea);
  62. return n;
  63. },
  64. renderTitle: function renderTitle(n) {
  65. n.text(this._props.title);
  66. return n;
  67. }
  68. });
  69. return Dialog;
  70. });
  71. //# sourceMappingURL=EditableDialog.js.map