';
@@ -897,7 +918,7 @@ OC.Share={
}
return expireDateString;
}
-};
+});
$(document).ready(function() {
diff --git a/core/js/sharedialogview.js b/core/js/sharedialogview.js
new file mode 100644
index 00000000000..cbab9694afe
--- /dev/null
+++ b/core/js/sharedialogview.js
@@ -0,0 +1,253 @@
+/*
+ * Copyright (c) 2015
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+(function() {
+ if(!OC.Share) {
+ OC.Share = {};
+ }
+
+ var TEMPLATE_BASE =
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ ' ' +
+ ' ' +
+ ' ' +
+ '
'
+ ;
+
+ /**
+ * @class OCA.Share.ShareDialogView
+ * @classdesc
+ *
+ * Represents the GUI of the share dialogue
+ *
+ */
+ var ShareDialogView = function(id) {
+ this.initialize(id);
+ };
+
+ /**
+ * @memberof OCA.Sharing
+ */
+ ShareDialogView.prototype = {
+ /** @member {OC.Share.ShareItemModel} **/
+ _itemModel: null,
+
+ /** @var {string} **/
+ _id: null,
+
+ /** @var {Object} **/
+ _templates: {},
+
+ /** @var {string} **/
+ _containerClasses: '',
+
+ /** @var {boolean} **/
+ _showLink: true,
+
+ /** @var {unknown} **/
+ _possiblePermissions: null,
+
+ initialize: function (id) {
+ this._id = id;
+ },
+
+ render: function() {
+ var baseTemplate = this._getTemplate('base', TEMPLATE_BASE);
+
+ var $dialog = $(baseTemplate({
+ containerID: this._id,
+ containerClasses: this._renderContainerClasses(),
+ shareLabel: t('core', 'Share'),
+ resharerInfo: this._renderResharerInfo(),
+ sharePlaceholder: this._renderSharePlaceholderPart(),
+ remoteShareInfo: this._renderRemoteShareInfoPart(),
+ linkShare: this._renderLinkSharePart()
+ }));
+
+ return $dialog;
+ },
+
+ setItemModel: function(model) {
+ if(model instanceof OC.Share.ShareItemModel) {
+ this._itemModel = model;
+ } else {
+ console.warn('model is not an instance of OC.Share.ShareItemModel');
+ }
+ },
+
+ /**
+ * sets the classes the main container should get additionally
+ * TODO:: figure out whether this is really necessary
+ *
+ * @param {string} classes whitespace seperated
+ */
+ setContainerClasses: function(classes) {
+ this._containerClasses = classes;
+ },
+
+ /**
+ * sets whether share by link should be displayed or not. Default is
+ * true.
+ *
+ * @param {bool} showLink
+ */
+ setShowLink: function(showLink) {
+ this._showLink = (typeof showLink === 'boolean') ? showLink : true;
+ },
+
+ setPossiblePermissions: function(permissions) {
+ //TODO: maybe move to model? Whatever this is.
+ this._possiblePermissions = permissions;
+ },
+
+ _renderResharerInfo: function() {
+ var resharerInfo = '';
+ if ( this._itemModel.hasReshare()
+ && this._itemModel.getReshareOwner() !== OC.currentUser)
+ {
+ var reshareTemplate = this._getReshareTemplate();
+ var sharedByText = '';
+ if (this._itemModel.getReshareType() === OC.Share.SHARE_TYPE_GROUP) {
+ sharedByText = t(
+ 'core',
+ 'Shared with you and the group {group} by {owner}',
+ {
+ group: this._itemModel.getReshareWith(),
+ owner: this._itemModel.getReshareOwnerDisplayname()
+ }
+ );
+ } else {
+ sharedByText = t(
+ 'core',
+ 'Shared with you by {owner}',
+ { owner: this._itemModel.getReshareOwnerDisplayname() }
+ );
+ }
+
+
+ resharerInfo = reshareTemplate({
+ avatarEnabled: oc_config.enable_avatars === true,
+ sharedByText: sharedByText
+ });
+ }
+ },
+
+ _renderContainerClasses: function() {
+ var classes = '';
+ if(this._containerClasses) {
+ classes = 'class="' + this._containerClasses + '"';
+ }
+ return classes;
+ },
+
+ _renderRemoteShareInfoPart: function() {
+ var remoteShareInfo = '';
+ if(oc_appconfig.core.remoteShareAllowed) {
+ var infoTemplate = this._getRemoteShareInfoTemplate();
+ remoteShareInfo = infoTemplate({
+ docLink: oc_appconfig.core.federatedCloudShareDoc,
+ tooltip: t('core', 'Share with people on other ownClouds using the syntax username@example.com/owncloud')
+ });
+ }
+ return remoteShareInfo;
+ },
+
+ _renderLinkSharePart: function() {
+ var linkShare = '';
+ if(this._showLink && $('#allowShareWithLink').val() === 'yes') {
+ var linkShareTemplate = this._getLinkShareTemplate();
+ linkShare = linkShareTemplate({
+ linkShareLabel: t('core', 'Share link'),
+ urlLabel: t('core', 'Link'),
+ enablePasswordLabel: t('core', 'Password protect'),
+ passwordLabel: t('core', 'Password'),
+ passwordPlaceholder: t('core', 'Choose a password for the public link')
+ });
+ }
+ return linkShare;
+ },
+
+ _renderSharePlaceholderPart: function () {
+ var sharePlaceholder = t('core', 'Share with users or groups …');
+ if (oc_appconfig.core.remoteShareAllowed) {
+ sharePlaceholder = t('core', 'Share with users, groups or remote users …');
+ }
+ return sharePlaceholder;
+ },
+
+ _getTemplate: function (key, template) {
+ if (!this._templates[key]) {
+ this._templates[key] = Handlebars.compile(template);
+ }
+ return this._templates[key];
+ },
+
+ /**
+ * returns the info template for remote sharing
+ *
+ * @returns {Handlebars}
+ * @private
+ */
+ _getRemoteShareInfoTemplate: function() {
+ return this._getTemplate('remoteShareInfo', TEMPLATE_REMOTE_SHARE_INFO);
+ },
+
+ /**
+ * returns the info template for link sharing
+ *
+ * @returns {Handlebars}
+ * @private
+ */
+ _getLinkShareTemplate: function() {
+ return this._getTemplate('linkShare', TEMPLATE_LINK_SHARE);
+ },
+
+ _getReshareTemplate: function() {
+ return this._getTemplate('reshare', TEMPLATE_RESHARER_INFO);
+ },
+ };
+
+ OC.Share.ShareDialogView = ShareDialogView;
+
+})();
diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js
new file mode 100644
index 00000000000..1db49536db5
--- /dev/null
+++ b/core/js/shareitemmodel.js
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2015
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+(function() {
+ if(!OC.Share) {
+ OC.Share = {};
+ OC.Share.Types = {};
+ }
+
+ /**
+ * @typedef {object} OC.Share.Types.Reshare
+ * @property {string} uid_owner
+ * @property {number} share_type
+ * @property {string} share_with
+ * @property {string} displayname_owner
+ * @property {number} permissions
+ */
+
+ /**
+ * @typedef {object} OC.Share.Types.ShareInfo
+ * @property {number} share_type
+ * @property {number} permissions
+ * @property {number} file_source optional
+ * @property {number} item_source
+ * @property {string} token
+ * @property {string} share_with
+ * @property {string} share_with_displayname
+ * @property {string} share_mail_send
+ * @property {bool} collection //TODO: verify
+ * @property {Date} expiration optional?
+ * @property {number} stime optional?
+ */
+
+ /**
+ * @typedef {object} OC.Share.Types.ShareItemInfo
+ * @property {OC.Share.Types.Reshare} reshare
+ * @property {OC.Share.Types.ShareInfo[]} shares
+ */
+
+ /**
+ * @class OCA.Share.ShareItemModel
+ * @classdesc
+ *
+ * Represents the GUI of the share dialogue
+ *
+ */
+ var ShareItemModel = function(itemType, itemSource) {
+ this.initialize(itemType, itemSource);
+ };
+
+ /**
+ * @memberof OCA.Sharing
+ */
+ ShareItemModel.prototype = {
+ /** @var {string} **/
+ _itemType: null,
+ /** @var {mixed} **/ //TODO: what type?
+ _itemSource: null,
+
+ /** @var {OC.Share.Types.Reshare} **/
+ _reshare: null,
+
+ /** @var {OC.Share.Types.ShareInfo[]} **/
+ _shares: null,
+
+ initialize: function(itemType, itemSource) {
+ this._itemType = itemType;
+ this._itemSource = itemSource;
+ this._retrieveData();
+ },
+
+ hasReshare: function() {
+ return _.isObject(this._reshare) && !_.isUndefined(this._reshare.uid_owner);
+ },
+
+ getReshareOwner: function() {
+ return this._reshare.uid_owner;
+ },
+
+ getReshareOwnerDisplayname: function() {
+ return this._reshare.displayname_owner;
+ },
+
+ getReshareWith: function() {
+ return this._reshare.share_with;
+ },
+
+ getReshareType: function() {
+ return this._reshare.share_type;
+ },
+
+ _retrieveData: function() {
+ /** var {OC.Share.Types.ShareItemInfo} **/
+ var data = OC.Share.loadItem(this._itemType, this._itemSource);
+ if(data === false) {
+ console.warn('no data was returned');
+ return;
+ }
+ this._reshare = data.reshare;
+ this._shares = data.shares;
+
+ }
+ };
+
+ OC.Share.ShareItemModel = ShareItemModel;
+})();
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index 6ad36d60fe8..65968f581f5 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -83,6 +83,8 @@ class Share extends Constants {
'supportedFileExtensions' => $supportedFileExtensions
);
if(count(self::$backendTypes) === 1) {
+ \OC_Util::addScript('core', 'shareitemmodel');
+ \OC_Util::addScript('core', 'sharedialogview');
\OC_Util::addScript('core', 'share');
\OC_Util::addStyle('core', 'share');
}