editHyperlinkPane.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**
  2. * Copyright (C) 2013 KO GmbH <copyright@kogmbh.com>
  3. *
  4. * @licstart
  5. * This file is part of WebODF.
  6. *
  7. * WebODF is free software: you can redistribute it and/or modify it
  8. * under the terms of the GNU Affero General Public License (GNU AGPL)
  9. * as published by the Free Software Foundation, either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * WebODF is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with WebODF. If not, see <http://www.gnu.org/licenses/>.
  19. * @licend
  20. *
  21. * @source: http://www.webodf.org/
  22. * @source: https://github.com/kogmbh/WebODF/
  23. */
  24. /*global runtime,core,define,require,document,dijit */
  25. define("webodf/editor/widgets/dialogWidgets/editHyperlinkPane", [
  26. "dojo",
  27. "dijit/layout/ContentPane",
  28. "webodf/editor/widgets/dialogWidgets/idMangler"],
  29. function (dojo, ContentPane, IdMangler) {
  30. "use strict";
  31. runtime.loadClass("core.CSSUnits");
  32. var EditHyperlinkPane = function () {
  33. var self = this,
  34. editorBase = dojo.config && dojo.config.paths && dojo.config.paths['webodf/editor'],
  35. idMangler = new IdMangler(),
  36. contentPane,
  37. form,
  38. displayTextField,
  39. linkField,
  40. initialValue;
  41. runtime.assert(editorBase, "webodf/editor path not defined in dojoConfig");
  42. function onSave() {
  43. if (self.onSave) {
  44. self.onSave();
  45. }
  46. return false;
  47. }
  48. function onCancel() {
  49. form.set('value', initialValue);
  50. if (self.onCancel) {
  51. self.onCancel();
  52. }
  53. }
  54. contentPane = new ContentPane({
  55. title: runtime.tr("editLink"),
  56. href: editorBase+"/widgets/dialogWidgets/editHyperlinkPane.html",
  57. preload: true,
  58. ioMethod: idMangler.ioMethod,
  59. onLoad : function () {
  60. form = idMangler.byId('editHyperlinkPaneForm');
  61. form.onSubmit = onSave;
  62. idMangler.byId('cancelHyperlinkChangeButton').onClick = onCancel;
  63. displayTextField = idMangler.byId('linkDisplayText');
  64. linkField = idMangler.byId('linkUrl');
  65. linkField.on("change", function(value) {
  66. displayTextField.set('placeHolder', value);
  67. });
  68. runtime.translateContent(form.domNode);
  69. if (initialValue) {
  70. form.set('value', initialValue);
  71. displayTextField.set('disabled', initialValue.isReadOnlyText);
  72. initialValue = undefined;
  73. }
  74. displayTextField.set('placeHolder', linkField.value);
  75. }
  76. });
  77. this.widget = function () {
  78. return contentPane;
  79. };
  80. this.value = function () {
  81. return form && form.get('value');
  82. };
  83. this.set = function (value) {
  84. initialValue = value;
  85. if (form) {
  86. form.set('value', value);
  87. displayTextField.set('disabled', value.isReadOnlyText);
  88. }
  89. };
  90. };
  91. return EditHyperlinkPane;
  92. });