editHyperlinkPane.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. function (dojo, ContentPane) {
  29. "use strict";
  30. runtime.loadClass("core.CSSUnits");
  31. var EditHyperlinkPane = function () {
  32. var self = this,
  33. editorBase = dojo.config && dojo.config.paths && dojo.config.paths['webodf/editor'],
  34. contentPane,
  35. form,
  36. displayTextField,
  37. linkField,
  38. initialValue;
  39. runtime.assert(editorBase, "webodf/editor path not defined in dojoConfig");
  40. function onSave() {
  41. if (self.onSave) {
  42. self.onSave();
  43. }
  44. return false;
  45. }
  46. function onCancel() {
  47. form.set('value', initialValue);
  48. if (self.onCancel) {
  49. self.onCancel();
  50. }
  51. }
  52. contentPane = new ContentPane({
  53. title: runtime.tr("editLink"),
  54. href: editorBase+"/widgets/dialogWidgets/editHyperlinkPane.html",
  55. preload: true,
  56. onLoad : function () {
  57. form = dijit.byId('editHyperlinkPaneForm');
  58. form.onSubmit = onSave;
  59. dijit.byId('cancelHyperlinkChangeButton').onClick = onCancel;
  60. displayTextField = dijit.byId('linkDisplayText');
  61. linkField = dijit.byId('linkUrl');
  62. linkField.on("change", function(value) {
  63. displayTextField.set('placeHolder', value);
  64. });
  65. runtime.translateContent(form.domNode);
  66. if (initialValue) {
  67. form.set('value', initialValue);
  68. displayTextField.set('disabled', initialValue.isReadOnlyText);
  69. initialValue = undefined;
  70. }
  71. displayTextField.set('placeHolder', linkField.value);
  72. }
  73. });
  74. this.widget = function () {
  75. return contentPane;
  76. };
  77. this.value = function () {
  78. return form && form.get('value');
  79. };
  80. this.set = function (value) {
  81. initialValue = value;
  82. if (form) {
  83. form.set('value', value);
  84. displayTextField.set('disabled', value.isReadOnlyText);
  85. }
  86. };
  87. };
  88. return EditHyperlinkPane;
  89. });