Add social sharing

* Add socialshare manager
* Add social share field under link share

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-03-02 14:12:13 +01:00
parent 8e9b119c5f
commit a85327fe87
No known key found for this signature in database
GPG Key ID: F941078878347C0C
4 changed files with 196 additions and 1 deletions

View File

@ -0,0 +1,132 @@
/**
* @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
(function() {
if (!OC.Share) {
OC.Share = {};
}
var TEMPLATE =
'<button class="icon {{iconClass}} pop-up hasTooltip"' +
' title="{{shareToolTip}}"' +
' data-url="{{url}}"></button>'
;
/**
* @class OCA.Share.ShareDialogLinkSocialView
* @member {OC.Share.ShareItemModel} model
* @member {jQuery} $el
* @memberof OCA.Sharing
* @classdesc
*
* Represents the GUI of the share dialogue
*
*/
var ShareDialogLinkSocialView = OC.Backbone.View.extend({
/** @type {string} **/
id: 'shareDialogLinkSocialView',
/** @type {OC.Share.ShareConfigModel} **/
configModel: undefined,
/** @type {Function} **/
_template: undefined,
/** @type {boolean} **/
showLink: true,
events: {
'click .pop-up': 'onPopUpClick'
},
initialize: function(options) {
var view = this;
this.model.on('change:linkShare', function() {
view.render();
});
if(!_.isUndefined(options.configModel)) {
this.configModel = options.configModel;
} else {
throw 'missing OC.Share.ShareConfigModel';
}
},
onPopUpClick: function(event) {
var url = $(event.target).data('url');
$(event.target).tooltip('hide');
if (url) {
var width = 600;
var height = 400;
var left = (screen.width/2)-(width/2);
var top = (screen.height/2)-(height/2);
window.open(url, 'name', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left);
}
},
render: function() {
var isLinkShare = this.model.get('linkShare').isLinkShare;
if (isLinkShare && OC.Share.Social.Collection.size() > 0) {
var linkShareTemplate = this.template();
var link = this.model.get('linkShare').link;
var html = '';
OC.Share.Social.Collection.each(function(model) {
var url = model.get('url');
url = url.replace('{{reference}}', link);
html += linkShareTemplate({
url: url,
shareToolTip: t('core', 'Share to {name}', {name: model.get('name')}),
iconClass: model.get('iconClass')
});
});
this.$el.html(html);
this.$el.show();
} else {
this.$el.hide();
}
this.delegateEvents();
return this;
},
/**
* @returns {Function} from Handlebars
* @private
*/
template: function () {
if (!this._template) {
this._template = Handlebars.compile(TEMPLATE);
}
return this._template;
}
});
OC.Share.ShareDialogLinkSocialView = ShareDialogLinkSocialView;
})();

View File

@ -28,6 +28,7 @@
'<div class="shareeListView subView"></div>' +
'<div class="linkShareView subView"></div>' +
'<div class="expirationView subView"></div>' +
'<div class="socialView subView"></div>' +
'<div class="loading hidden" style="height: 50px"></div>';
var TEMPLATE_REMOTE_SHARE_INFO =
@ -69,6 +70,9 @@
/** @type {object} **/
shareeListView: undefined,
/** @type OC.Share.ShareDialogLinkSocialView **/
socalView: undefined,
events: {
'input .shareWithField': 'onShareWithFieldChanged'
},
@ -105,7 +109,8 @@
resharerInfoView: 'ShareDialogResharerInfoView',
linkShareView: 'ShareDialogLinkShareView',
expirationView: 'ShareDialogExpirationView',
shareeListView: 'ShareDialogShareeListView'
shareeListView: 'ShareDialogShareeListView',
socialView: 'ShareDialogLinkSocialView'
};
for(var name in subViews) {
@ -421,6 +426,9 @@
this.shareeListView.$el = this.$el.find('.shareeListView');
this.shareeListView.render();
this.socialView.$el = this.$('.socialView');
this.socialView.render();
this.$el.find('.hasTooltip').tooltip();
return this;

View File

@ -0,0 +1,53 @@
/**
* @copyright 2017, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
(function() {
if (!OC.Share) {
OC.Share = {};
}
OC.Share.Social = {};
var SocialModel = OC.Backbone.Model.extend({
defaults: {
/** used for sorting social buttons */
key: null,
/** url to open, {{reference}} will be replaced with the link */
url: null,
/** Name to show in the tooltip */
name: null,
/** Icon class to display */
iconClass: null
}
});
OC.Share.Social.Model = SocialModel;
var SocialCollection = OC.Backbone.Collection.extend({
model: OC.Share.Social.Model,
comparator: 'key'
});
OC.Share.Social.Collection = new SocialCollection;
})();

View File

@ -94,8 +94,10 @@ class Share extends Constants {
if(count(self::$backendTypes) === 1) {
\OC_Util::addScript('core', 'shareconfigmodel');
\OC_Util::addScript('core', 'shareitemmodel');
\OC_Util::addScript('core', 'sharesocialmanager');
\OC_Util::addScript('core', 'sharedialogresharerinfoview');
\OC_Util::addScript('core', 'sharedialoglinkshareview');
\OC_Util::addScript('core', 'sharedialoglinksocialview');
\OC_Util::addScript('core', 'sharedialogexpirationview');
\OC_Util::addScript('core', 'sharedialogshareelistview');
\OC_Util::addScript('core', 'sharedialogview');