Merge pull request #625 from ONLYOFFICE/feature/add-favorite

Add/remove file to favorites
This commit is contained in:
Julia Radzhabova 2020-12-15 11:16:00 +03:00 committed by GitHub
commit 04d02d051b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 110 additions and 4 deletions

View file

@ -36,7 +36,8 @@
isLink: false
},
...
]
],
favorite: '<file is favorite>' // true/false/undefined (undefined - don't show fav. button)
},
permissions: {
edit: <can edit>, // default = true
@ -638,6 +639,13 @@
});
};
var _setFavorite = function(data) {
_sendCommand({
command: 'setFavorite',
data: data
});
};
var _processMouse = function(evt) {
var r = iframe.getBoundingClientRect();
var data = {
@ -683,7 +691,8 @@
setSharingSettings : _setSharingSettings,
insertImage : _insertImage,
setMailMergeRecipients: _setMailMergeRecipients,
setRevisedFile : _setRevisedFile
setRevisedFile : _setRevisedFile,
setFavorite : _setFavorite
}
};

View file

@ -122,6 +122,10 @@ if (Common === undefined) {
'setRevisedFile': function(data) {
$me.trigger('setrevisedfile', data);
},
'setFavorite': function(data) {
$me.trigger('setfavorite', data);
}
};

View file

@ -659,7 +659,7 @@ define([
changeIcon: function(opts) {
var me = this;
if ( opts && (opts.curr || opts.next)) {
if ( opts && (opts.curr || opts.next) && me.$icon) {
!!opts.curr && (me.$icon.removeClass(opts.curr));
!!opts.next && !me.$icon.hasClass(opts.next) && (me.$icon.addClass(opts.next));

View file

@ -98,6 +98,7 @@ define([
'</div>' +
'<div class="hedset">' +
'<div class="btn-slot" id="slot-btn-back"></div>' +
'<div class="btn-slot" id="slot-btn-favorite"></div>' +
'<div class="btn-slot" id="slot-btn-options"></div>' +
'</div>' +
'</section>' +
@ -232,6 +233,13 @@ define([
Common.NotificationCenter.trigger('goback');
});
me.btnFavorite.on('click', function (e) {
me.options.favorite = !me.options.favorite;
me.btnFavorite.changeIcon(me.options.favorite ? {next: 'btn-in-favorite'} : {curr: 'btn-in-favorite'});
me.btnFavorite.updateHint(!me.options.favorite ? me.textAddFavorite : me.textRemoveFavorite);
Common.NotificationCenter.trigger('markfavorite', me.options.favorite);
});
if ( me.logo )
me.logo.children(0).on('click', function (e) {
var _url = !!me.branding && !!me.branding.logo && (me.branding.logo.url!==undefined) ?
@ -402,6 +410,12 @@ define([
me.mnuZoom = {options: {value: 100}};
me.btnFavorite = new Common.UI.Button({
id: 'btn-favorite',
cls: 'btn-header',
iconCls: 'toolbar__icon icon--inverse btn-favorite'
});
Common.NotificationCenter.on({
'app:ready': function(mode) {Common.Utils.asyncCall(onAppReady, me, mode);},
'app:face': function(mode) {Common.Utils.asyncCall(onAppShowed, me, mode);}
@ -463,6 +477,14 @@ define([
$html.find('#slot-btn-back').hide();
}
if ( this.options.favorite !== undefined ) {
me.btnFavorite.render($html.find('#slot-btn-favorite'));
me.btnFavorite.changeIcon(!!me.options.favorite ? {next: 'btn-in-favorite'} : {curr: 'btn-in-favorite'});
me.btnFavorite.updateHint(!me.options.favorite ? me.textAddFavorite : me.textRemoveFavorite);
} else {
$html.find('#slot-btn-favorite').hide();
}
if ( !config.isEdit ) {
if ( (config.canDownload || config.canDownloadOrigin) && !config.isOffline )
this.btnDownload = createTitleButton('toolbar__icon icon--inverse btn-download', $html.findById('#slot-hbtn-download'));
@ -582,6 +604,19 @@ define([
return this.options.canBack;
},
setFavorite: function (value) {
this.options.favorite = value;
this.btnFavorite[value!==undefined ? 'show' : 'hide']();
this.btnFavorite.changeIcon(!!value ? {next: 'btn-in-favorite'} : {curr: 'btn-in-favorite'});
this.btnFavorite.updateHint(!value ? this.textAddFavorite : this.textRemoveFavorite);
return this;
},
getFavorite: function () {
return this.options.favorite;
},
setCanRename: function (rename) {
rename = false;
@ -691,7 +726,9 @@ define([
textHideLines: 'Hide Rulers',
textZoom: 'Zoom',
textAdvSettings: 'Advanced Settings',
tipViewSettings: 'View Settings'
tipViewSettings: 'View Settings',
textRemoveFavorite: 'Remove from Favorites',
textAddFavorite: 'Mark as favorite'
}
}(), Common.Views.Header || {}))
});

View file

@ -202,6 +202,7 @@ define([
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('goback', _.bind(this.goBack, this));
Common.NotificationCenter.on('markfavorite', _.bind(this.markFavorite, this));
Common.NotificationCenter.on('download:advanced', _.bind(this.onAdvancedOptions, this));
Common.NotificationCenter.on('showmessage', _.bind(this.onExternalMessage, this));
Common.NotificationCenter.on('showerror', _.bind(this.onError, this));
@ -440,6 +441,8 @@ define([
if (type && typeof type[1] === 'string') {
this.permissions.edit = this.permissions.review = false;
}
this.appOptions.canFavorite = data.doc.info && (data.doc.info.favorite!==undefined);
}
this.api.asc_registerCallback('asc_onGetEditorPermissions', _.bind(this.onEditorPermissions, this));
@ -451,6 +454,7 @@ define([
if (data.doc) {
appHeader.setDocumentCaption(data.doc.title);
}
this.appOptions.canFavorite && appHeader.setFavorite(data.doc.info.favorite);
},
onProcessSaveResult: function(data) {
@ -700,6 +704,18 @@ define([
}
},
markFavorite: function(favorite) {
if ( !Common.Controllers.Desktop.process('markfavorite') ) {
Common.Gateway.metaChange({
favorite: favorite
});
}
},
onSetFavorite: function(favorite) {
this.appOptions.canFavorite && appHeader.setFavorite(!!favorite);
},
onEditComplete: function(cmp) {
// this.getMainMenu().closeFullScaleMenu();
var application = this.getApplication(),
@ -1111,6 +1127,7 @@ define([
Common.Gateway.on('processmouse', _.bind(me.onProcessMouse, me));
Common.Gateway.on('refreshhistory', _.bind(me.onRefreshHistory, me));
Common.Gateway.on('downloadas', _.bind(me.onDownloadAs, me));
Common.Gateway.on('setfavorite', _.bind(me.onSetFavorite, me));
Common.Gateway.sendInfo({mode:me.appOptions.isEdit?'edit':'view'});

View file

@ -261,6 +261,8 @@
"Common.Views.Header.tipViewUsers": "View users and manage document access rights",
"Common.Views.Header.txtAccessRights": "Change access rights",
"Common.Views.Header.txtRename": "Rename",
"Common.Views.Header.textRemoveFavorite": "Remove from Favorites",
"Common.Views.Header.textAddFavorite": "Mark as favorite",
"Common.Views.History.textCloseHistory": "Close History",
"Common.Views.History.textHide": "Collapse",
"Common.Views.History.textHideAll": "Hide detailed changes",

View file

@ -185,6 +185,7 @@ define([
Common.NotificationCenter.on('goback', _.bind(this.goBack, this));
Common.NotificationCenter.on('showmessage', _.bind(this.onExternalMessage, this));
Common.NotificationCenter.on('showerror', _.bind(this.onError, this));
Common.NotificationCenter.on('markfavorite', _.bind(this.markFavorite, this));
this.isShowOpenDialog = false;
@ -391,6 +392,8 @@ define([
docInfo.asc_putIsEnabledMacroses(!!enable);
enable = !this.editorConfig.customization || (this.editorConfig.customization.plugins!==false);
docInfo.asc_putIsEnabledPlugins(!!enable);
this.appOptions.canFavorite = data.doc.info && (data.doc.info.favorite!==undefined);
}
this.api.asc_registerCallback('asc_onGetEditorPermissions', _.bind(this.onEditorPermissions, this));
@ -402,6 +405,7 @@ define([
if (data.doc) {
appHeader.setDocumentCaption(data.doc.title);
}
this.appOptions.canFavorite && appHeader.setFavorite(data.doc.info.favorite);
},
onProcessSaveResult: function(data) {
@ -487,6 +491,18 @@ define([
}
},
markFavorite: function(favorite) {
if ( !Common.Controllers.Desktop.process('markfavorite') ) {
Common.Gateway.metaChange({
favorite: favorite
});
}
},
onSetFavorite: function(favorite) {
this.appOptions.canFavorite && appHeader.setFavorite(!!favorite);
},
onEditComplete: function(cmp) {
var application = this.getApplication(),
toolbarView = application.getController('Toolbar').getView('Toolbar');
@ -835,6 +851,7 @@ define([
Common.Gateway.on('processrightschange', _.bind(me.onProcessRightsChange, me));
Common.Gateway.on('processmouse', _.bind(me.onProcessMouse, me));
Common.Gateway.on('downloadas', _.bind(me.onDownloadAs, me));
Common.Gateway.on('setfavorite', _.bind(me.onSetFavorite, me));
Common.Gateway.sendInfo({mode:me.appOptions.isEdit?'edit':'view'});

View file

@ -158,6 +158,8 @@
"Common.Views.Header.tipViewUsers": "View users and manage document access rights",
"Common.Views.Header.txtAccessRights": "Change access rights",
"Common.Views.Header.txtRename": "Rename",
"Common.Views.Header.textRemoveFavorite": "Remove from Favorites",
"Common.Views.Header.textAddFavorite": "Mark as favorite",
"Common.Views.ImageFromUrlDialog.textUrl": "Paste an image URL:",
"Common.Views.ImageFromUrlDialog.txtEmpty": "This field is required",
"Common.Views.ImageFromUrlDialog.txtNotUrl": "This field should be a URL in the \"http://www.example.com\" format",

View file

@ -193,6 +193,7 @@ define([
Common.NotificationCenter.on('download:cancel', _.bind(this.onDownloadCancel, this));
Common.NotificationCenter.on('download:advanced', _.bind(this.onAdvancedOptions, this));
Common.NotificationCenter.on('showmessage', _.bind(this.onExternalMessage, this));
Common.NotificationCenter.on('markfavorite', _.bind(this.markFavorite, this));
this.stackLongActions = new Common.IrregularStack({
strongCompare : this._compareActionStrong,
@ -445,6 +446,8 @@ define([
docInfo.asc_putIsEnabledPlugins(!!enable);
this.headerView && this.headerView.setDocumentCaption(data.doc.title);
this.appOptions.canFavorite = data.doc.info && (data.doc.info.favorite!==undefined);
this.appOptions.canFavorite && this.headerView && this.headerView.setFavorite(data.doc.info.favorite);
Common.Utils.InternalSettings.set("sse-doc-info-key", data.doc.key);
}
@ -541,6 +544,18 @@ define([
}
},
markFavorite: function(favorite) {
if ( !Common.Controllers.Desktop.process('markfavorite') ) {
Common.Gateway.metaChange({
favorite: favorite
});
}
},
onSetFavorite: function(favorite) {
this.appOptions.canFavorite && this.headerView && this.headerView.setFavorite(!!favorite);
},
onEditComplete: function(cmp, opts) {
if (opts && opts.restorefocus && this.api.isCEditorFocused) {
this.formulaInput.blur();
@ -887,6 +902,7 @@ define([
Common.Gateway.on('processrightschange', _.bind(me.onProcessRightsChange, me));
Common.Gateway.on('processmouse', _.bind(me.onProcessMouse, me));
Common.Gateway.on('downloadas', _.bind(me.onDownloadAs, me));
Common.Gateway.on('setfavorite', _.bind(me.onSetFavorite, me));
Common.Gateway.sendInfo({mode:me.appOptions.isEdit?'edit':'view'});
$(document).on('contextmenu', _.bind(me.onContextMenu, me));

View file

@ -154,6 +154,8 @@
"Common.Views.Header.tipViewUsers": "View users and manage document access rights",
"Common.Views.Header.txtAccessRights": "Change access rights",
"Common.Views.Header.txtRename": "Rename",
"Common.Views.Header.textRemoveFavorite": "Remove from Favorites",
"Common.Views.Header.textAddFavorite": "Mark as favorite",
"Common.Views.ImageFromUrlDialog.textUrl": "Paste an image URL:",
"Common.Views.ImageFromUrlDialog.txtEmpty": "This field is required",
"Common.Views.ImageFromUrlDialog.txtNotUrl": "This field should be a URL in the \"http://www.example.com\" format",