Detect disabled apps in drive context menu

pull/1/head
yflory 3 years ago
parent aa601db3ee
commit f3cdf33daa

@ -40,15 +40,15 @@ define([
return function () { return function () {
var icons = [ var icons = [
[ 'pad', Msg.type.pad],
[ 'code', Msg.type.code],
[ 'slide', Msg.type.slide],
[ 'sheet', Msg.type.sheet], [ 'sheet', Msg.type.sheet],
[ 'doc', Msg.type.doc], [ 'doc', Msg.type.doc],
[ 'presentation', Msg.type.presentation], [ 'presentation', Msg.type.presentation],
[ 'pad', Msg.type.pad],
[ 'code', Msg.type.code],
[ 'form', Msg.type.form], [ 'form', Msg.type.form],
[ 'kanban', Msg.type.kanban], [ 'kanban', Msg.type.kanban],
[ 'whiteboard', Msg.type.whiteboard], [ 'whiteboard', Msg.type.whiteboard],
[ 'slide', Msg.type.slide],
[ 'drive', Msg.type.drive] [ 'drive', Msg.type.drive]
].filter(function (x) { ].filter(function (x) {
return isAvailableType(x[0]); return isAvailableType(x[0]);

@ -11,7 +11,7 @@ define(function() {
* redirected to the drive. * redirected to the drive.
* You should never remove the drive from this list. * You should never remove the drive from this list.
*/ */
AppConfig.availablePadTypes = ['drive', 'teams', 'doc', 'sheet', 'presentation', 'pad', 'code', 'slide', 'poll', 'kanban', 'whiteboard', AppConfig.availablePadTypes = ['drive', 'teams', 'sheet', 'doc', 'presentation', 'pad', 'code', 'slide', 'poll', 'kanban', 'whiteboard',
'file', 'contacts', 'form', 'convert']; 'file', 'contacts', 'form', 'convert'];
/* The registered only types are apps restricted to registered users. /* The registered only types are apps restricted to registered users.
* You should never remove apps from this list unless you know what you're doing. The apps * You should never remove apps from this list unless you know what you're doing. The apps

@ -348,6 +348,13 @@ define([
var html = '<i class="'+cls+'"></i>' + Messages.type[app]; var html = '<i class="'+cls+'"></i>' + Messages.type[app];
return Messages._getKey('fc_openIn', [html]); return Messages._getKey('fc_openIn', [html]);
}; };
var isAppEnabled = function (app) {
if (!Array.isArray(AppConfig.availablePadTypes)) { return true; }
var registered = common.isLoggedIn() || !(AppConfig.registeredOnlyTypes || []).includes(app);
var restricted = common.checkRestrictedApp(app) < 0;
if (restricted === 0) { return 0; }
return AppConfig.availablePadTypes.includes(app) && registered && !restricted;
};
var menu = h('div.cp-contextmenu.dropdown.cp-unselectable', [ var menu = h('div.cp-contextmenu.dropdown.cp-unselectable', [
h('ul.dropdown-menu', { h('ul.dropdown-menu', {
'role': 'menu', 'role': 'menu',
@ -367,22 +374,22 @@ define([
'tabindex': '-1', 'tabindex': '-1',
'data-icon': faReadOnly, 'data-icon': faReadOnly,
}, h('span.cp-text', Messages.fc_open_ro))), }, h('span.cp-text', Messages.fc_open_ro))),
h('li', UI.setHTML(h('a.cp-app-drive-context-openincode.dropdown-item', { isAppEnabled('code') ? h('li', UI.setHTML(h('a.cp-app-drive-context-openincode.dropdown-item', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': 'fa-arrows', 'data-icon': 'fa-arrows',
}), getOpenIn('code'))), }), getOpenIn('code'))) : undefined,
h('li', UI.setHTML(h('a.cp-app-drive-context-openinsheet.dropdown-item', { isAppEnabled('sheet') ? h('li', UI.setHTML(h('a.cp-app-drive-context-openinsheet.dropdown-item', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': 'fa-arrows', 'data-icon': 'fa-arrows',
}), getOpenIn('sheet'))), }), getOpenIn('sheet'))) : undefined,
premiumD < 0 ? undefined : h('li', UI.setHTML(h('a.cp-app-drive-context-openindoc.dropdown-item' + (premiumD === 0 ? '.cp-app-disabled' : ''), { isAppEnabled('doc') ? h('li', UI.setHTML(h('a.cp-app-drive-context-openindoc.dropdown-item' + (premiumD === 0 ? '.cp-app-disabled' : ''), {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': 'fa-arrows', 'data-icon': 'fa-arrows',
}), getOpenIn('doc'))), }), getOpenIn('doc'))) : undefined,
premiumP < 0 ? undefined : h('li', UI.setHTML(h('a.cp-app-drive-context-openinpresentation.dropdown-item' + (premiumP === 0 ? '.cp-app-disabled' : ''), { isAppEnabled('presentation') ? h('li', UI.setHTML(h('a.cp-app-drive-context-openinpresentation.dropdown-item' + (premiumP === 0 ? '.cp-app-disabled' : ''), {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': 'fa-arrows', 'data-icon': 'fa-arrows',
}), getOpenIn('presentation'))), }), getOpenIn('presentation'))) : undefined,
h('li', h('a.cp-app-drive-context-savelocal.dropdown-item', { h('li', h('a.cp-app-drive-context-savelocal.dropdown-item', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': 'fa-cloud-upload', 'data-icon': 'fa-cloud-upload',
@ -429,57 +436,57 @@ define([
'data-icon': faUploadFolder, 'data-icon': faUploadFolder,
}, Messages.uploadFolderButton)), }, Messages.uploadFolderButton)),
$separator.clone()[0], $separator.clone()[0],
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { isAppEnabled('pad') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.pad, 'data-icon': AppConfig.applicationsIcon.pad,
'data-type': 'pad' 'data-type': 'pad'
}, Messages.button_newpad)), }, Messages.button_newpad)) : undefined,
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { isAppEnabled('code') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.code, 'data-icon': AppConfig.applicationsIcon.code,
'data-type': 'code' 'data-type': 'code'
}, Messages.button_newcode)), }, Messages.button_newcode)) : undefined,
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { isAppEnabled('sheet') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.slide, 'data-icon': AppConfig.applicationsIcon.sheet,
'data-type': 'slide' 'data-type': 'sheet'
}, Messages.button_newslide)), }, Messages.button_newsheet)) : undefined,
h('li.dropdown-submenu', [ h('li.dropdown-submenu', [
h('a.cp-app-drive-context-newdocmenu.dropdown-item', { h('a.cp-app-drive-context-newdocmenu.dropdown-item', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': "fa-plus", 'data-icon': "fa-plus",
}, Messages.fm_morePads), }, Messages.fm_morePads),
h("ul.dropdown-menu", [ h("ul.dropdown-menu", [
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { isAppEnabled('doc') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable' + (premiumD === 0 ? '.cp-app-disabled' : ''), {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.sheet,
'data-type': 'sheet'
}, Messages.button_newsheet)),
premiumD === -1 ? undefined : h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable' + (premiumD === 0 ? '.cp-app-disabled' : ''), {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.doc, 'data-icon': AppConfig.applicationsIcon.doc,
'data-type': 'doc' 'data-type': 'doc'
}, Messages.button_newdoc)), }, Messages.button_newdoc)) : undefined,
premiumP === -1 ? undefined : h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable' + (premiumP === 0 ? '.cp-app-disabled' : ''), { isAppEnabled('presentation') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable' + (premiumP === 0 ? '.cp-app-disabled' : ''), {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.presentation, 'data-icon': AppConfig.applicationsIcon.presentation,
'data-type': 'presentation' 'data-type': 'presentation'
}, Messages.button_newpresentation)), }, Messages.button_newpresentation)) : undefined,
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { isAppEnabled('whiteboard') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.whiteboard, 'data-icon': AppConfig.applicationsIcon.whiteboard,
'data-type': 'whiteboard' 'data-type': 'whiteboard'
}, Messages.button_newwhiteboard)), }, Messages.button_newwhiteboard)) : undefined,
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { isAppEnabled('kanban') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.kanban, 'data-icon': AppConfig.applicationsIcon.kanban,
'data-type': 'kanban' 'data-type': 'kanban'
}, Messages.button_newkanban)), }, Messages.button_newkanban)) : undefined,
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { isAppEnabled('form') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.form,
'data-type': 'form'
}, Messages.button_newform)) : undefined,
isAppEnabled('slide') ? h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.poll, 'data-icon': AppConfig.applicationsIcon.slide,
'data-type': 'poll' 'data-type': 'slide'
}, Messages.button_newpoll)), }, Messages.button_newslide)) : undefined,
h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', {
'tabindex': '-1', 'tabindex': '-1',
'data-icon': AppConfig.applicationsIcon.link, 'data-icon': AppConfig.applicationsIcon.link,

Loading…
Cancel
Save