Merge pull request #34 from ONLYOFFICE/feature/restore-version

Feature/restore version
This commit is contained in:
Julia Radzhabova 2016-09-21 13:35:44 +03:00 committed by GitHub
commit 5739d6cd73
8 changed files with 95 additions and 12 deletions

View file

@ -216,6 +216,7 @@
extend(_config, DocsAPI.DocEditor.defaultConfig);
_config.editorConfig.canUseHistory = _config.events && !!_config.events.onRequestHistory;
_config.editorConfig.canHistoryClose = _config.events && !!_config.events.onRequestHistoryClose;
_config.editorConfig.canHistoryRestore = _config.events && !!_config.events.onRequestRestore;
_config.editorConfig.canSendEmailAddresses = _config.events && !!_config.events.onRequestEmailAddresses;
_config.editorConfig.canRequestEditRights = _config.events && !!_config.events.onRequestEditRights;

View file

@ -162,6 +162,16 @@ Common.Gateway = new(function() {
});
},
requestRestore: function(version, url) {
_postMessage({
event: 'onRequestRestore',
data: {
version: version,
url: url
}
});
},
requestEmailAddresses: function() {
_postMessage({ event: 'onRequestEmailAddresses' });
},

View file

@ -72,6 +72,7 @@ define([
setApi: function(api) {
this.api = api;
this.api.asc_registerCallback('asc_onDownloadUrl', _.bind(this.onDownloadUrl, this));
return this;
},
@ -87,7 +88,34 @@ define([
historyView.btnBackToDocument.on('click', _.bind(this.onClickBackToDocument, this));
},
onSelectRevision: function(picker, item, record) {
onDownloadUrl: function(url) {
if (this.isFromSelectRevision !== undefined)
Common.Gateway.requestRestore(this.isFromSelectRevision, url);
this.isFromSelectRevision = undefined;
},
onSelectRevision: function(picker, item, record, e) {
if (e) {
var btn = $(e.target);
if (btn && btn.hasClass('revision-restore')) {
var tip = item.btnTip;
if (tip) {
tip.dontShow = true;
tip.tip().remove();
}
if (record.get('isRevision'))
Common.Gateway.requestRestore(record.get('revision'));
else {
this.isFromSelectRevision = record.get('revision');
this.api.asc_DownloadAs(Asc.c_oAscFileType.DOCX, true);
}
return;
}
}
if (!picker && record)
this.panelHistory.viewHistoryList.scrollToRecord(record);
var url = record.get('url'),
rev = record.get('revision'),
urlGetTime = new Date();

View file

@ -65,7 +65,9 @@ define([
docId: '',
docIdPrev: '',
arrColors: [], // array of user colors for all changes of current version
markedAsVersion: false
markedAsVersion: false,
canRestore: false,
isRevision: true
}
}
});

View file

@ -81,6 +81,9 @@ define([
'<% if (markedAsVersion) { %>',
'<div class="user-version">ver.<%=version%></div>',
'<% } %>',
'<% if (canRestore && selected) { %>',
'<div class="revision-restore img-commonctrl"></div>',
'<% } %>',
'<div class="user-name">',
'<div class="color" style="display: inline-block; background-color:' + '<%=usercolor%>;' + '" >',
'</div><%= Common.Utils.String.htmlEncode(username) %>',
@ -93,12 +96,28 @@ define([
el: $('#history-btn-back'),
enableToggle: false
});
var me = this;
var changetooltip = function (dataview, view, record) {
if (record.get('selected')) {
var btns = $(view.el).find('.revision-restore').tooltip({title: me.textRestore, placement: 'cursor'});
if (btns)
view.btnTip = btns.data('bs.tooltip');
} else if (view.btnTip) {
view.btnTip.dontShow = true;
view.btnTip.tip().remove();
view.btnTip = null;
}
};
this.viewHistoryList.on('item:add', changetooltip);
this.viewHistoryList.on('item:change', changetooltip);
this.trigger('render:after', this);
return this;
},
textHistoryHeader: 'Back to Document'
textHistoryHeader: 'Back to Document',
textRestore: 'Restore'
}, Common.Views.History || {}))
});

View file

@ -102,5 +102,15 @@
margin: 0 5px 3px 0;
vertical-align: middle;
}
.revision-restore {
width: 16px;
height: 16px;
background-position: -22px -272px;
margin: 0 12px;
display: inline-block;
position: absolute;
right: 0;
}
}
}

View file

@ -324,6 +324,7 @@ define([
},
onDownloadAs: function() {
this._state.isFromGatewayDownloadAs = true;
var type = /^(?:(pdf|djvu|xps))$/.exec(this.document.fileType);
(type && typeof type[1] === 'string') ? this.api.asc_DownloadOrigin(true) : this.api.asc_DownloadAs(Asc.c_oAscFileType.DOCX, true);
},
@ -344,7 +345,13 @@ define([
onRefreshHistory: function(opts) {
this.loadMask && this.loadMask.hide();
if (opts.data.error || !opts.data.history) {
var config = {
var historyStore = this.getApplication().getCollection('Common.Collections.HistoryVersions');
if (historyStore && historyStore.size()>0) {
historyStore.each(function(item){
item.set('canRestore', false);
});
}
Common.UI.alert({
closable: false,
title: this.notcriticalErrorTitle,
msg: (opts.data.error) ? opts.data.error : this.txtErrorLoadHistory,
@ -353,8 +360,7 @@ define([
callback: _.bind(function(btn){
this.onEditComplete();
}, this)
};
Common.UI.alert(config);
});
} else {
this.api.asc_coAuthoringDisconnect();
this.getApplication().getController('LeftMenu').getView('LeftMenu').showHistory();
@ -393,7 +399,8 @@ define([
created: version.created,
docId: version.key,
markedAsVersion: (group!==version.versionGroup),
selected: (opts.data.currentVersion == version.version)
selected: (opts.data.currentVersion == version.version),
canRestore: this.appOptions.canHistoryRestore
}));
if (opts.data.currentVersion == version.version) {
currentVersion = arrVersions[arrVersions.length-1];
@ -437,7 +444,9 @@ define([
created: change.created,
docId: version.key,
docIdPrev: docIdPrev,
selected: false
selected: false,
canRestore: this.appOptions.canHistoryRestore,
isRevision: false
}));
arrColors.push(user.get('colorval'));
}
@ -453,7 +462,7 @@ define([
}
arrColors = [];
}
historyStore[historyStore.size() > 0 ? 'add' : 'reset'](arrVersions);
historyStore.reset(arrVersions);
if (currentVersion===null && historyStore.size()>0) {
currentVersion = historyStore.at(0);
currentVersion.set('selected', true);
@ -948,8 +957,9 @@ define([
(!this.appOptions.isReviewOnly || this.appOptions.canLicense); // if isReviewOnly==true -> canLicense must be true
this.appOptions.isEdit = this.appOptions.canLicense && this.appOptions.canEdit && this.editorConfig.mode !== 'view';
this.appOptions.canReview = this.appOptions.canLicense && this.appOptions.isEdit && (this.permissions.review===true);
this.appOptions.canUseHistory = this.appOptions.canLicense && !this.appOptions.isLightVersion && this.editorConfig.canUseHistory && (this.permissions.edit !== false) && this.appOptions.canCoAuthoring && !this.appOptions.isDesktopApp;
this.appOptions.canUseHistory = this.appOptions.canLicense && !this.appOptions.isLightVersion && this.editorConfig.canUseHistory && this.appOptions.canCoAuthoring && !this.appOptions.isDesktopApp;
this.appOptions.canHistoryClose = this.editorConfig.canHistoryClose;
this.appOptions.canHistoryRestore= this.editorConfig.canHistoryRestore && !!this.permissions.changeHistory;
this.appOptions.canUseMailMerge= this.appOptions.canLicense && this.appOptions.canEdit && !this.appOptions.isDesktopApp;
this.appOptions.canSendEmailAddresses = this.appOptions.canLicense && this.editorConfig.canSendEmailAddresses && this.appOptions.canEdit && this.appOptions.canCoAuthoring;
this.appOptions.canComments = this.appOptions.canLicense && !((typeof (this.editorConfig.customization) == 'object') && this.editorConfig.customization.comments===false);
@ -1416,7 +1426,9 @@ define([
},
onDownloadUrl: function(url) {
Common.Gateway.downloadAs(url);
if (this._state.isFromGatewayDownloadAs)
Common.Gateway.downloadAs(url);
this._state.isFromGatewayDownloadAs = false;
},
onUpdateVersion: function(callback) {

View file

@ -143,6 +143,7 @@
"Common.Views.Header.textBack": "Go to Documents",
"Common.Views.Header.txtHeaderDeveloper": "DEVELOPER MODE",
"Common.Views.History.textHistoryHeader": "Back to Document",
"Common.Views.History.textRestore": "Restore",
"Common.Views.ImageFromUrlDialog.cancelButtonText": "Cancel",
"Common.Views.ImageFromUrlDialog.okButtonText": "OK",
"Common.Views.ImageFromUrlDialog.textUrl": "Paste an image URL:",