[DE] Set name for guest user

This commit is contained in:
Julia Radzhabova 2020-12-11 13:08:13 +03:00
parent 583065a6af
commit 2be4649d63
5 changed files with 36 additions and 12 deletions

View file

@ -714,6 +714,7 @@ Common.Utils.fillUserInfo = function(info, lang, defname) {
!_user.id && (_user.id = ('uid-' + Date.now()));
_user.fullname = _.isEmpty(_user.name) ? defname : _user.name;
_user.group && (_user.fullname = (_user.group).toString() + Common.Utils.UserInfoParser.getSeparator() + _user.fullname);
_user.guest = _.isEmpty(_user.name);
return _user;
};

View file

@ -118,7 +118,7 @@ define([
'<div class="lr-separator" id="id-box-doc-name">' +
'<label id="title-doc-name" />' +
'</div>' +
'<label id="title-user-name" style="pointer-events: none;"></label>' +
'<label id="title-user-name"></label>' +
'</section>';
function onResetUsers(collection, opts) {
@ -273,6 +273,13 @@ define([
$panelUsers[(editingUsers > 1 || editingUsers > 0 && !appConfig.isEdit && !appConfig.isRestrictedEdit || !mode.isOffline && (mode.sharingSettingsUrl && mode.sharingSettingsUrl.length || mode.canRequestSharingSettings)) ? 'show' : 'hide']();
}
if (me.labelUserName && appConfig.user.guest) {
me.labelUserName.addClass('clickable');
me.labelUserName.on('click', function (e) {
Common.NotificationCenter.trigger('user:rename');
});
}
if ( me.btnPrint ) {
me.btnPrint.updateHint(me.tipPrint + Common.Utils.String.platformKey('Ctrl+P'));
me.btnPrint.on('click', function (e) {

View file

@ -76,8 +76,7 @@ define([
var me = this;
me.inputLabel = new Common.UI.InputField({
el : $('#id-dlg-username-caption'),
allowBlank : false,
blankError : me.options.error ? me.options.error : me.textLabelError,
allowBlank : true,
style : 'width: 100%;',
maxLength : 128,
validateOnBlur: false,
@ -87,9 +86,10 @@ define([
});
me.inputLabel.setValue(this.options.value || '' );
me.chAlwaysUse = new Common.UI.CheckBox({
me.chDontShow = new Common.UI.CheckBox({
el: $('#id-dlg-username-chk-use'),
labelText: this.textUse
labelText: this.textDontShow,
value: this.options.check
});
var $window = this.getChild();
@ -123,7 +123,7 @@ define([
}
}
this.options.handler.call(this, state, {input: this.inputLabel.getValue(), checkbox: this.chAlwaysUse.getValue()=='checked'});
this.options.handler.call(this, state, {input: this.inputLabel.getValue(), checkbox: this.chDontShow.getValue()=='checked'});
}
this.close();
@ -131,6 +131,6 @@ define([
textLabel: 'Label:',
textLabelError: 'Label must not be empty.',
textUse: 'Always use this name'
textDontShow: 'Don\'t ask me again'
}, Common.Views.UserNameDialog || {}));
});

View file

@ -401,6 +401,11 @@
height: 100%;
padding: 0 12px;
line-height: @height-title;
pointer-events: none;
&.clickable {
cursor: pointer;
pointer-events: auto;
}
}
.lr-separator {

View file

@ -340,6 +340,7 @@ define([
this.editorConfig = $.extend(this.editorConfig, data.config);
var value = Common.localStorage.getItem("guest-username");
Common.Utils.InternalSettings.set("guest-username", value);
this.editorConfig.user =
this.appOptions.user = Common.Utils.fillUserInfo(this.editorConfig.user, this.editorConfig.lang, value ? (value + ' (' + this.textGuest + ')' ) : this.textAnonymous);
this.appOptions.isDesktopApp = this.editorConfig.targetApp == 'desktop';
@ -375,6 +376,8 @@ define([
this.appOptions.canFeatureContentControl = !!this.api.asc_isSupportFeature("content-controls");
this.appOptions.mentionShare = !((typeof (this.appOptions.customization) == 'object') && (this.appOptions.customization.mentionShare==false));
this.appOptions.user.guest && Common.NotificationCenter.on('user:rename', _.bind(this.showRenameUserDialog, this));
appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header');
appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '');
@ -1120,7 +1123,7 @@ define([
$('#editor-container').css('overflow', '');
$('.doc-placeholder').remove();
!Common.localStorage.getItem("guest-username") && this.showRenameUserDialog();
this.appOptions.user.guest && (Common.Utils.InternalSettings.get("guest-username")===null) && this.showRenameUserDialog();
},
onLicenseChanged: function(params) {
@ -2363,18 +2366,21 @@ define([
},
showRenameUserDialog: function() {
if (this._renameDialog) return;
var me = this;
var value = Common.localStorage.getItem("guest-username");
(new Common.Views.UserNameDialog({
var value = Common.Utils.InternalSettings.get("guest-username");
this._renameDialog = new Common.Views.UserNameDialog({
label: this.textRenameLabel,
error: this.textRenameError,
value: value || '',
check: (value!==null),
validation: function(value) {
return value.length<128 ? true : me.textLongName;
},
handler: function(result, {input: input, checkbox: checkbox}) {
if (result == 'ok') {
var name = input + ' (' + me.textGuest + ')';
var name = input ? input + ' (' + me.textGuest + ')' : me.textAnonymous;
var _user = new Asc.asc_CUserInfo();
_user.put_FullName(name);
@ -2385,9 +2391,14 @@ define([
Common.Utils.UserInfoParser.setCurrentName(name);
appHeader.setUserName(Common.Utils.UserInfoParser.getParsedName(name));
checkbox ? Common.localStorage.setItem("guest-username", input) : Common.localStorage.removeItem("guest-username");
Common.Utils.InternalSettings.set("guest-username", input);
}
}
})).show();
});
this._renameDialog.on('close', function() {
me._renameDialog = undefined;
});
this._renameDialog.show(Common.Utils.innerWidth() - this._renameDialog.options.width - 15, 30);
},
leavePageText: 'You have unsaved changes in this document. Click \'Stay on this Page\' then \'Save\' to save them. Click \'Leave this Page\' to discard all the unsaved changes.',