[DE] Save track changes to file: set 4 variants of track changes mode

This commit is contained in:
Julia Radzhabova 2021-02-10 13:09:21 +03:00
parent cb21490921
commit 4b232db539
3 changed files with 190 additions and 33 deletions

View file

@ -132,6 +132,8 @@ define([
this.api.asc_registerCallback('asc_onAuthParticipantsChanged', _.bind(this.onAuthParticipantsChanged, this));
this.api.asc_registerCallback('asc_onParticipantsChanged', _.bind(this.onAuthParticipantsChanged, this));
}
if (this.appConfig.canReview && !this.appConfig.isReviewOnly)
this.api.asc_registerCallback('asc_onOnTrackRevisionsChange', _.bind(this.onApiTrackRevisionsChange, this));
this.api.asc_registerCallback('asc_onAcceptChangesBeforeCompare',_.bind(this.onAcceptChangesBeforeCompare, this));
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
@ -555,17 +557,29 @@ define([
Common.NotificationCenter.trigger('edit:complete', this.view);
},
onTurnPreview: function(state) {
onTurnPreview: function(state, global, fromApi) {
if ( this.appConfig.isReviewOnly ) {
this.view.turnChanges(true);
} else
if ( this.appConfig.canReview ) {
state = (state == 'on');
var sendMessage = !fromApi;
var saveToFile = !!global; // save track changes flag (state) to file
this.api.asc_SetTrackRevisions(!!state, saveToFile, sendMessage);
Common.Utils.InternalSettings.set(this.view.appPrefix + "track-changes", (state ? 0 : 1) + (global ? 2 : 0));
this.view.turnChanges(state, global);
}
},
this.api.asc_SetTrackRevisions(state);
Common.localStorage.setItem(this.view.appPrefix + "track-changes-" + (this.appConfig.fileKey || ''), state ? 1 : 0);
this.view.turnChanges(state);
onApiTrackRevisionsChange: function(state, global, userId) {
// change local or global state
if (userId && this.getUserName(userId)) {
if (state)
this.showTips(Common.Utils.String.format(global ? this.textOnGlobal : this.textOn, this.getUserName(userId)));
else
this.showTips(Common.Utils.String.format(global ? this.textOffGlobal : this.textOff, this.getUserName(userId)));
}
if (global && Common.Utils.InternalSettings.get(this.view.appPrefix + "track-changes")>1) {
Common.NotificationCenter.trigger('reviewchanges:turn', state, global, true);
}
},
@ -764,15 +778,18 @@ define([
(new Promise(function (resolve) {
resolve();
})).then(function () {
function _setReviewStatus(state) {
me.view.turnChanges(state);
function _setReviewStatus(state, global) {
me.view.turnChanges(state, global);
me.api.asc_SetTrackRevisions(state);
Common.Utils.InternalSettings.set(me.view.appPrefix + "track-changes", (state ? 0 : 1) + (global ? 2 : 0));
};
var trackChanges = typeof (me.appConfig.customization) == 'object' ? me.appConfig.customization.trackChanges : undefined;
var state = config.isReviewOnly || trackChanges===true || (trackChanges!==false) && Common.localStorage.getBool(me.view.appPrefix + "track-changes-" + (config.fileKey || ''));
var trackChanges = typeof (me.appConfig.customization) == 'object' ? me.appConfig.customization.trackChanges : undefined,
state = config.isReviewOnly || trackChanges===true || (trackChanges!==false) && me.api.asc_IsTrackRevisions(),
global = !config.isReviewOnly && (trackChanges===undefined);
me.api.asc_HaveRevisionsChanges() && me.view.markChanges(true);
_setReviewStatus(state);
_setReviewStatus(state, global);
if ( typeof (me.appConfig.customization) == 'object' && (me.appConfig.customization.showReviewChanges==true) ) {
me.dlgChanges = (new Common.Views.ReviewChangesDialog({
@ -806,6 +823,36 @@ define([
}
},
showTips: function(strings) {
var me = this;
if (!strings.length) return;
if (typeof(strings)!='object') strings = [strings];
function showNextTip() {
var str_tip = strings.shift();
if (str_tip) {
me.tooltip.setTitle(str_tip);
me.tooltip.show();
}
}
if (!this.tooltip) {
this.tooltip = new Common.UI.Tooltip({
owner: this.getApplication().getController('Toolbar').getView(),
hideonclick: true,
placement: 'bottom',
cls: 'main-info',
offset: 30,
hoverState: 'in'
});
this.tooltip.on('tooltip:hide', function(cmp){
(cmp==me.tooltip) && setTimeout(showNextTip, 300);
});
}
showNextTip();
},
applySettings: function(menu) {
this.view && this.view.turnSpelling( Common.localStorage.getBool(this.view.appPrefix + "settings-spellcheck", true) );
this.view && this.view.turnCoAuthMode( Common.localStorage.getBool(this.view.appPrefix + "settings-coauthmode", true) );
@ -966,7 +1013,11 @@ define([
textTitleComparison: 'Comparison Settings',
textShow: 'Show changes at',
textChar: 'Character level',
textWord: 'Word level'
textWord: 'Word level',
textOnGlobal: '{0} enabled Track Changes for everyone.',
textOffGlobal: '{0} disabled Track Changes for everyone.',
textOn: '{0} is now using Track Changes.',
textOff: '{0} is no longer using Track Changes.'
}, Common.Controllers.ReviewChanges || {}));
});

View file

@ -93,13 +93,6 @@ define([
'</div>' +
'</section>';
function _click_turnpreview(btn, e) {
if (this.appConfig.canReview) {
Common.NotificationCenter.trigger('reviewchanges:turn', btn.pressed ? 'on' : 'off');
Common.NotificationCenter.trigger('edit:complete');
}
};
function setEvents() {
var me = this;
@ -131,7 +124,36 @@ define([
}
this.btnsTurnReview.forEach(function (button) {
button.on('click', _click_turnpreview.bind(me));
button.on('click', function (btn, e) {
Common.NotificationCenter.trigger('reviewchanges:turn', btn.pressed);
Common.NotificationCenter.trigger('edit:complete');
});
!me.appConfig.isReviewOnly && button.menu.on('item:toggle', function (menu, item, state, e) {
if (!!state) {
if (item.value==2) // ON track changes for everyone
Common.UI.warning({
title: me.textWarnTrackChangesTitle,
msg: me.textWarnTrackChanges,
maxwidth: 600,
buttons: [{
value: 'enable',
caption: me.textEnable
}, 'cancel'],
primary: 'enable',
callback: function(btn){
if (btn == 'enable') {
Common.NotificationCenter.trigger('reviewchanges:turn', item.value==0 || item.value==2, item.value>1);
} else {
var old = Common.Utils.InternalSettings.get(me.appPrefix + "track-changes");
me.turnChanges(old==0 || old==2, old>1);
}
Common.NotificationCenter.trigger('edit:complete');
}
});
else
Common.NotificationCenter.trigger('reviewchanges:turn', item.value==0 || item.value==2, item.value>1);
}
});
});
}
if (this.appConfig.canViewReview) {
@ -225,6 +247,7 @@ define([
cls: 'btn-toolbar x-huge icon-top',
iconCls: 'toolbar__icon btn-ic-review',
caption: this.txtTurnon,
split: !this.appConfig.isReviewOnly,
enableToggle: true
});
this.btnsTurnReview = [this.btnTurnOn];
@ -356,6 +379,39 @@ define([
'<% } %></a>');
if ( config.canReview ) {
var idx = Common.Utils.InternalSettings.get(me.appPrefix + "track-changes");
!config.isReviewOnly && me.btnTurnOn.setMenu(
new Common.UI.Menu({items: [
{
caption: me.txtOn,
value: 0,
checkable: true,
checked: idx==0,
toggleGroup: 'menuTurnReviewTlb'
},
{
caption: me.txtOff,
value: 1,
checkable: true,
checked: idx==1,
toggleGroup: 'menuTurnReviewTlb'
},
{
caption: me.txtOnGlobal,
value: 2,
checkable: true,
checked: idx==2,
toggleGroup: 'menuTurnReviewTlb'
},
{
caption: me.txtOffGlobal,
value: 3,
checkable: true,
checked: idx==3,
toggleGroup: 'menuTurnReviewTlb'
}
]})
);
me.btnTurnOn.updateHint(me.tipReview);
if (!me.appConfig.canUseReviewPermissions) {
@ -551,7 +607,37 @@ define([
iconCls : 'toolbar__icon btn-ic-review',
hintAnchor : 'top',
hint : this.tipReview,
enableToggle: true
split : !this.appConfig.isReviewOnly,
enableToggle: true,
menu: this.appConfig.isReviewOnly ? false : new Common.UI.Menu({
menuAlign: 'bl-tl',
style: 'margin-top:-5px;',
items: [
{
caption: this.txtOn,
value: 0,
checkable: true,
toggleGroup: 'menuTurnReviewStb'
},
{
caption: this.txtOff,
value: 1,
checkable: true,
toggleGroup: 'menuTurnReviewStb'
},
{
caption: this.txtOnGlobal,
value: 2,
checkable: true,
toggleGroup: 'menuTurnReviewStb'
},
{
caption: this.txtOffGlobal,
value: 3,
checkable: true,
toggleGroup: 'menuTurnReviewStb'
}
]})
});
this.btnsTurnReview.push(button);
@ -587,11 +673,17 @@ define([
return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username));
},
turnChanges: function(state) {
turnChanges: function(state, global) {
this.btnsTurnReview.forEach(function(button) {
if ( button && button.pressed != state ) {
button.toggle(state, true);
}
if (button.menu) {
button.menu.items[0].setChecked(state && !global, true);
button.menu.items[1].setChecked(!state && !global, true);
button.menu.items[2].setChecked(state && !!global, true);
button.menu.items[3].setChecked(!state && !!global, true);
}
}, this);
},
@ -711,7 +803,14 @@ define([
txtCommentRemCurrent: 'Remove Current Comments',
txtCommentRemMyCurrent: 'Remove My Current Comments',
txtCommentRemMy: 'Remove My Comments',
txtCommentRemAll: 'Remove All Comments'
txtCommentRemAll: 'Remove All Comments',
txtOnGlobal: 'ON for me and everyone',
txtOffGlobal: 'OFF for me and everyone',
txtOn: 'ON for me',
txtOff: 'OFF for me',
textWarnTrackChangesTitle: 'Enable Track Changes for everyone?',
textWarnTrackChanges: 'Track Changes will be switched ON for all users with full access. The next time anyone opens the doc, Track Changes will remain enabled.',
textEnable: 'Enable'
}
}()), Common.Views.ReviewChanges || {}));

View file

@ -135,7 +135,7 @@ define([
if ( showTrackChangesTip ) {
me.btnTurnReview.updateHint('');
if (me.changesTooltip === undefined)
me.changesTooltip = me.createChangesTip(me.textTrackChanges, 'de-track-changes-tip', false);
me.changesTooltip = me.createChangesTip(me.textTrackChanges, 'de-track-changes-tip');
me.changesTooltip.show();
} else {
@ -143,16 +143,17 @@ define([
}
}
var trackChanges = typeof (config.customization) == 'object' ? config.customization.trackChanges : undefined;
if ( config.isReviewOnly || trackChanges===true || (trackChanges!==false) && Common.localStorage.getBool("de-track-changes-" + (config.fileKey || ''))) {
var trackRevisions = me.api.asc_IsTrackRevisions(),
trackChanges = typeof (config.customization) == 'object' ? config.customization.trackChanges : undefined;
if ( config.isReviewOnly || trackChanges===true || (trackChanges!==false) && trackRevisions) {
_process_changestip();
} else if ( me.api.asc_IsTrackRevisions() ) {
} else if ( trackRevisions ) {
var showNewChangesTip = !Common.localStorage.getBool("de-new-changes");
if ( me.api.asc_HaveRevisionsChanges() && showNewChangesTip ) {
me.btnTurnReview.updateHint('');
if (me.newChangesTooltip === undefined)
me.newChangesTooltip = me.createChangesTip(me.textHasChanges, 'de-new-changes', true);
me.newChangesTooltip = me.createChangesTip(me.textHasChanges, 'de-new-changes');
me.newChangesTooltip.show();
} else
@ -162,10 +163,14 @@ define([
});
},
onTurnPreview: function(state) {
if (state == 'off' && this.changesTooltip && this.changesTooltip.isVisible()) {
onTurnPreview: function(state, global, fromApi) {
if (!state && this.changesTooltip && this.changesTooltip.isVisible()) {
this.changesTooltip.hide();
this.btnTurnReview.updateHint(this.tipReview);
} else if (fromApi && state && global ) {
if (this.globalChangesTooltip === undefined)
this.globalChangesTooltip = this.createChangesTip(this.textSetTrackChanges);
!this.globalChangesTooltip.isVisible() && this.globalChangesTooltip.show();
}
},
@ -252,12 +257,13 @@ define([
this.setStatusCaption('');
},
createChangesTip: function (text, storage, newchanges) {
createChangesTip: function (text, storage) {
var me = this;
var tip = new Common.UI.SynchronizeTip({
target : me.btnTurnReview.$el,
text : text,
placement: 'top'
placement: 'top',
showLink: !!storage
});
tip.on({
'dontshowclick': function() {
@ -278,6 +284,7 @@ define([
zoomText : 'Zoom {0}%',
textHasChanges : 'New changes have been tracked',
textTrackChanges: 'The document is opened with the Track Changes mode enabled',
tipReview : 'Review'
tipReview : 'Review',
textSetTrackChanges: 'You are in Track Changes mode'
}, DE.Controllers.Statusbar || {}));
});