[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_onAuthParticipantsChanged', _.bind(this.onAuthParticipantsChanged, this));
this.api.asc_registerCallback('asc_onParticipantsChanged', _.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_onAcceptChangesBeforeCompare',_.bind(this.onAcceptChangesBeforeCompare, this));
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
@ -555,17 +557,29 @@ define([
Common.NotificationCenter.trigger('edit:complete', this.view); Common.NotificationCenter.trigger('edit:complete', this.view);
}, },
onTurnPreview: function(state) { onTurnPreview: function(state, global, fromApi) {
if ( this.appConfig.isReviewOnly ) { if ( this.appConfig.isReviewOnly ) {
this.view.turnChanges(true); this.view.turnChanges(true);
} else } else
if ( this.appConfig.canReview ) { 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); onApiTrackRevisionsChange: function(state, global, userId) {
Common.localStorage.setItem(this.view.appPrefix + "track-changes-" + (this.appConfig.fileKey || ''), state ? 1 : 0); // change local or global state
if (userId && this.getUserName(userId)) {
this.view.turnChanges(state); 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) { (new Promise(function (resolve) {
resolve(); resolve();
})).then(function () { })).then(function () {
function _setReviewStatus(state) { function _setReviewStatus(state, global) {
me.view.turnChanges(state); me.view.turnChanges(state, global);
me.api.asc_SetTrackRevisions(state); 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 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 || '')); state = config.isReviewOnly || trackChanges===true || (trackChanges!==false) && me.api.asc_IsTrackRevisions(),
global = !config.isReviewOnly && (trackChanges===undefined);
me.api.asc_HaveRevisionsChanges() && me.view.markChanges(true); me.api.asc_HaveRevisionsChanges() && me.view.markChanges(true);
_setReviewStatus(state); _setReviewStatus(state, global);
if ( typeof (me.appConfig.customization) == 'object' && (me.appConfig.customization.showReviewChanges==true) ) { if ( typeof (me.appConfig.customization) == 'object' && (me.appConfig.customization.showReviewChanges==true) ) {
me.dlgChanges = (new Common.Views.ReviewChangesDialog({ 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) { applySettings: function(menu) {
this.view && this.view.turnSpelling( Common.localStorage.getBool(this.view.appPrefix + "settings-spellcheck", true) ); 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) ); this.view && this.view.turnCoAuthMode( Common.localStorage.getBool(this.view.appPrefix + "settings-coauthmode", true) );
@ -966,7 +1013,11 @@ define([
textTitleComparison: 'Comparison Settings', textTitleComparison: 'Comparison Settings',
textShow: 'Show changes at', textShow: 'Show changes at',
textChar: 'Character level', 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 || {})); }, Common.Controllers.ReviewChanges || {}));
}); });

View file

@ -93,13 +93,6 @@ define([
'</div>' + '</div>' +
'</section>'; '</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() { function setEvents() {
var me = this; var me = this;
@ -131,7 +124,36 @@ define([
} }
this.btnsTurnReview.forEach(function (button) { 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) { if (this.appConfig.canViewReview) {
@ -225,6 +247,7 @@ define([
cls: 'btn-toolbar x-huge icon-top', cls: 'btn-toolbar x-huge icon-top',
iconCls: 'toolbar__icon btn-ic-review', iconCls: 'toolbar__icon btn-ic-review',
caption: this.txtTurnon, caption: this.txtTurnon,
split: !this.appConfig.isReviewOnly,
enableToggle: true enableToggle: true
}); });
this.btnsTurnReview = [this.btnTurnOn]; this.btnsTurnReview = [this.btnTurnOn];
@ -356,6 +379,39 @@ define([
'<% } %></a>'); '<% } %></a>');
if ( config.canReview ) { 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); me.btnTurnOn.updateHint(me.tipReview);
if (!me.appConfig.canUseReviewPermissions) { if (!me.appConfig.canUseReviewPermissions) {
@ -551,7 +607,37 @@ define([
iconCls : 'toolbar__icon btn-ic-review', iconCls : 'toolbar__icon btn-ic-review',
hintAnchor : 'top', hintAnchor : 'top',
hint : this.tipReview, 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); this.btnsTurnReview.push(button);
@ -587,11 +673,17 @@ define([
return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username)); return Common.Utils.String.htmlEncode(Common.Utils.UserInfoParser.getParsedName(username));
}, },
turnChanges: function(state) { turnChanges: function(state, global) {
this.btnsTurnReview.forEach(function(button) { this.btnsTurnReview.forEach(function(button) {
if ( button && button.pressed != state ) { if ( button && button.pressed != state ) {
button.toggle(state, true); 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); }, this);
}, },
@ -711,7 +803,14 @@ define([
txtCommentRemCurrent: 'Remove Current Comments', txtCommentRemCurrent: 'Remove Current Comments',
txtCommentRemMyCurrent: 'Remove My Current Comments', txtCommentRemMyCurrent: 'Remove My Current Comments',
txtCommentRemMy: 'Remove My 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 || {})); }()), Common.Views.ReviewChanges || {}));

View file

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