You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.2 KiB

  1. /*
  2. * Copyright (c) 2015
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. (function() {
  11. if (!OC.Share) {
  12. OC.Share = {};
  13. }
  14. var TEMPLATE =
  15. '<div id="link" class="linkShare">' +
  16. ' <span class="icon-loading-small hidden"></span>' +
  17. ' <input type="checkbox" name="linkCheckbox" id="linkCheckbox" value="1" /><label for="linkCheckbox">{{linkShareLabel}}</label>' +
  18. ' <br />' +
  19. ' <label for="linkText" class="hidden-visually">{{urlLabel}}</label>' +
  20. ' <input id="linkText" type="text" readonly="readonly" />' +
  21. ' <input type="checkbox" name="showPassword" id="showPassword" value="1" class="hidden" /><label for="showPassword" class="hidden-visually">{{enablePasswordLabel}}</label>' +
  22. ' <div id="linkPass">' +
  23. ' <label for="linkPassText" class="hidden-visually">{{passwordLabel}}</label>' +
  24. ' <input id="linkPassText" type="password" placeholder="passwordPlaceholder" />' +
  25. ' <span class="icon-loading-small hidden"></span>' +
  26. ' </div>' +
  27. ' {{#if publicUpload}}' +
  28. ' <div id="allowPublicUploadWrapper" class="hidden">' +
  29. ' <span class="icon-loading-small hidden"></span>' +
  30. ' <input type="checkbox" value="1" name="allowPublicUpload" id="sharingDialogAllowPublicUpload" {{{publicUploadChecked}}} />' +
  31. ' <label for="sharingDialogAllowPublicUpload">{{publicUploadLabel}}</label>' +
  32. ' </div>' +
  33. ' {{/if}}' +
  34. ' {{#if mailPublicNotificationEnabled}}' +
  35. ' <form id="emailPrivateLink">' +
  36. ' <input id="email" class="hidden" value="" placeholder="{{mailPrivatePlaceholder}}" type="text" />' +
  37. ' <input id="emailButton" class="hidden" type="submit" value="{{mailButtonText}}" />' +
  38. ' </form>' +
  39. ' {{/if}}' +
  40. '</div>'
  41. ;
  42. /**
  43. * @class OCA.Share.ShareDialogLinkShareView
  44. * @member {OC.Share.ShareItemModel} model
  45. * @member {jQuery} $el
  46. * @memberof OCA.Sharing
  47. * @classdesc
  48. *
  49. * Represents the GUI of the share dialogue
  50. *
  51. */
  52. var ShareDialogLinkShareView = OC.Backbone.View.extend({
  53. /** @type {string} **/
  54. id: 'shareDialogLinkShare',
  55. /** @type {OC.Share.ShareConfigModel} **/
  56. configModel: undefined,
  57. /** @type {Function} **/
  58. _template: undefined,
  59. /** @type {boolean} **/
  60. showLink: true,
  61. initialize: function(options) {
  62. var view = this;
  63. this.model.on('change:permissions', function() {
  64. view.render();
  65. });
  66. this.model.on('change:itemType', function() {
  67. view.render();
  68. });
  69. this.model.on('change:allowPublicUploadStatus', function() {
  70. view.render();
  71. });
  72. if(!_.isUndefined(options.configModel)) {
  73. this.configModel = options.configModel;
  74. } else {
  75. console.warn('missing OC.Share.ShareConfigModel');
  76. }
  77. },
  78. render: function() {
  79. if( !this.model.hasSharePermission()
  80. || !this.showLink
  81. || !this.configModel.isShareWithLinkAllowed())
  82. {
  83. this.$el.empty();
  84. return this;
  85. }
  86. var publicUpload =
  87. this.model.isFolder()
  88. && this.model.hasCreatePermission()
  89. && this.configModel.isPublicUploadEnabled();
  90. var publicUploadChecked = '';
  91. if(this.model.isPublicUploadAllowed()) {
  92. publicUploadChecked = 'checked="checked"';
  93. }
  94. var linkShareTemplate = this.template();
  95. this.$el.empty();
  96. this.$el.append(linkShareTemplate({
  97. linkShareLabel: t('core', 'Share link'),
  98. urlLabel: t('core', 'Link'),
  99. enablePasswordLabel: t('core', 'Password protect'),
  100. passwordLabel: t('core', 'Password'),
  101. passwordPlaceholder: t('core', 'Choose a password for the public link'),
  102. publicUpload: publicUpload,
  103. publicUploadChecked: publicUploadChecked,
  104. publicUploadLabel: t('core', 'Allow editing'),
  105. mailPublicNotificationEnabled: this.configModel.isMailPublicNotificationEnabled(),
  106. mailPrivatePlaceholder: t('core', 'Email link to person'),
  107. mailButtonText: t('core', 'Send')
  108. }));
  109. return this;
  110. },
  111. /**
  112. * @returns {Function} from Handlebars
  113. * @private
  114. */
  115. template: function () {
  116. if (!this._template) {
  117. this._template = Handlebars.compile(TEMPLATE);
  118. }
  119. return this._template;
  120. }
  121. });
  122. OC.Share.ShareDialogLinkShareView = ShareDialogLinkShareView;
  123. })();