diff --git a/public/js/opendxp/document/link.js b/public/js/opendxp/document/link.js index 92ee5a3..76e1bc3 100644 --- a/public/js/opendxp/document/link.js +++ b/public/js/opendxp/document/link.js @@ -11,7 +11,7 @@ * @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License version 3 (GPLv3) */ -opendxp.registerNS("opendxp.document.link"); +opendxp.registerNS('opendxp.document.link'); /** * @private */ @@ -21,13 +21,13 @@ opendxp.document.link = Class.create(opendxp.document.document, { this.options = options; this.id = intval(id); - this.setType("link"); + this.setType('link'); this.addLoadingPanel(); const preOpenDocumentLink = new CustomEvent(opendxp.events.preOpenDocument, { detail: { document: this, - type: "link" + type: 'link' }, cancelable: true }); @@ -43,28 +43,28 @@ opendxp.document.link = Class.create(opendxp.document.document, { init: function () { - var user = opendxp.globalmanager.get("user"); + var user = opendxp.globalmanager.get('user'); - if (this.isAllowed("properties")) { - this.properties = new opendxp.document.properties(this, "document", true); + if (this.isAllowed('properties')) { + this.properties = new opendxp.document.properties(this, 'document', true); } - if (this.isAllowed("settings")) { - this.scheduler = new opendxp.element.scheduler(this, "document", { + if (this.isAllowed('settings')) { + this.scheduler = new opendxp.element.scheduler(this, 'document', { supportsVersions: false }); } - if (user.isAllowed("notes_events")) { - this.notes = new opendxp.element.notes(this, "document"); + if (user.isAllowed('notes_events')) { + this.notes = new opendxp.element.notes(this, 'document'); } if (opendxp.settings.dependency) { - this.dependencies = new opendxp.element.dependencies(this, "document"); + this.dependencies = new opendxp.element.dependencies(this, 'document'); } - this.tagAssignment = new opendxp.element.tag.assignment(this, "document"); - this.workflows = new opendxp.element.workflows(this, "document"); + this.tagAssignment = new opendxp.element.tag.assignment(this, 'document'); + this.workflows = new opendxp.element.workflows(this, 'document'); }, getSaveData: function (only) { @@ -72,13 +72,13 @@ opendxp.document.link = Class.create(opendxp.document.document, { parameters.id = this.id; // get only scheduled tasks - if (only === "scheduler") { + if (only === 'scheduler') { try { parameters.scheduler = Ext.encode(this.scheduler.getValues()); return parameters; } catch (e) { - console.log("scheduler not available"); + console.log('scheduler not available'); return; } } @@ -87,7 +87,7 @@ opendxp.document.link = Class.create(opendxp.document.document, { values.published = this.data.published; parameters.data = Ext.encode(values); - if (this.isAllowed("properties")) { + if (this.isAllowed('properties')) { // properties try { parameters.properties = Ext.encode(this.properties.getValues()); @@ -97,7 +97,7 @@ opendxp.document.link = Class.create(opendxp.document.document, { } } - if (this.isAllowed("settings")) { + if (this.isAllowed('settings')) { // scheduler try { parameters.scheduler = Ext.encode(this.scheduler.getValues()); @@ -112,9 +112,10 @@ opendxp.document.link = Class.create(opendxp.document.document, { addTab: function () { - var tabTitle = this.data.key; - this.tabPanel = Ext.getCmp("opendxp_panel_tabs"); - var tabId = "document_" + this.id; + var tabTitle = this.data.key, + tabId = 'document_' + this.id; + + this.tabPanel = Ext.getCmp('opendxp_panel_tabs'); const tabbarContainer = new Ext.Container({ flex: 2 @@ -126,15 +127,15 @@ opendxp.document.link = Class.create(opendxp.document.document, { if (opendxp.helpers.checkIfNewHeadbarLayoutIsEnabled()) { this.tab = new Ext.Panel({ id: tabId, - cls: "opendxp_panel_toolbar_horizontal_border_layout", + cls: 'opendxp_panel_toolbar_horizontal_border_layout', title: htmlspecialchars(tabTitle), closable:true, - hideMode: "offsets", - layout: "border", + hideMode: 'offsets', + layout: 'border', items: [ { xtype: 'panel', - width: "100%", + width: '100%', region: 'north', layout: 'hbox', items: [ @@ -157,7 +158,7 @@ opendxp.document.link = Class.create(opendxp.document.document, { id: tabId, title: htmlspecialchars(tabTitle), closable: true, - layout: "border", + layout: 'border', items: [ toolbar, tabPanel @@ -167,35 +168,35 @@ opendxp.document.link = Class.create(opendxp.document.document, { }); } - this.tab.on("beforedestroy", function () { + this.tab.on('beforedestroy', function () { Ext.Ajax.request({ url: Routing.generate('opendxp_admin_element_unlockelement'), method: 'PUT', params: { id: this.data.id, - type: "document" + type: 'document' } }); }.bind(this)); // remove this instance when the panel is closed - this.tab.on("destroy", function () { - opendxp.globalmanager.remove("document_" + this.id); - opendxp.helpers.forgetOpenTab("document_" + this.id + "_link"); + this.tab.on('destroy', function () { + opendxp.globalmanager.remove('document_' + this.id); + opendxp.helpers.forgetOpenTab('document_' + this.id + '_link'); }.bind(this)); - this.tab.on("activate", function () { + this.tab.on('activate', function () { this.tab.updateLayout(); opendxp.layout.refresh(); }.bind(this)); - this.tab.on("afterrender", function (tabId) { + this.tab.on('afterrender', function (tabId) { this.tabPanel.setActiveItem(tabId); const postOpenDocumentLink = new CustomEvent(opendxp.events.postOpenDocument, { detail: { document: this, - type: "link" + type: 'link' } }); @@ -217,20 +218,20 @@ opendxp.document.link = Class.create(opendxp.document.document, { this.toolbarButtons.publish = new Ext.SplitButton({ text: t('save_and_publish'), - iconCls: "opendxp_icon_save_white", - cls: "opendxp_save_button", - scale: "medium", + iconCls: 'opendxp_icon_save_white', + cls: 'opendxp_save_button', + scale: 'medium', handler: this.publish.bind(this), menu: [ { text: t('save_pubish_close'), - iconCls: "opendxp_icon_save", + iconCls: 'opendxp_icon_save', handler: this.publishClose.bind(this) }, { text: t('save_only_scheduled_tasks'), - iconCls: "opendxp_icon_save", - handler: this.save.bind(this, "scheduler", "scheduler") + iconCls: 'opendxp_icon_save', + handler: this.save.bind(this, 'scheduler', 'scheduler') } ] }); @@ -243,40 +244,40 @@ opendxp.document.link = Class.create(opendxp.document.document, { this.toolbarButtons.unpublish = new Ext.Button({ text: t('unpublish'), - iconCls: "opendxp_material_icon_unpublish opendxp_material_icon", - scale: "medium", + iconCls: 'opendxp_material_icon_unpublish opendxp_material_icon', + scale: 'medium', handler: this.unpublish.bind(this) }); if (opendxp.helpers.checkIfNewHeadbarLayoutIsEnabled()) { this.toolbarButtons.unpublish = Ext.create('Ext.menu.Item', { text: t('unpublish'), - iconCls: "opendxp_material_icon_unpublish opendxp_material_icon", - scale: "medium", + iconCls: 'opendxp_material_icon_unpublish opendxp_material_icon', + scale: 'medium', handler: this.unpublish.bind(this) }) } this.toolbarButtons.remove = new Ext.Button({ tooltip: t('delete'), - iconCls: "opendxp_material_icon_delete opendxp_material_icon", - scale: "medium", + iconCls: 'opendxp_material_icon_delete opendxp_material_icon', + scale: 'medium', handler: this.remove.bind(this) }); this.toolbarButtons.rename = new Ext.Button({ tooltip: t('rename'), - iconCls: "opendxp_material_icon_rename opendxp_material_icon", - scale: "medium", + iconCls: 'opendxp_material_icon_rename opendxp_material_icon', + scale: 'medium', handler: this.rename.bind(this) }); var buttons = []; - if (this.isAllowed("publish")) { + if (this.isAllowed('publish')) { buttons.push(this.toolbarButtons.publish); } - if (this.isAllowed("unpublish") && !this.data.locked) { + if (this.isAllowed('unpublish') && !this.data.locked) { if (opendxp.helpers.checkIfNewHeadbarLayoutIsEnabled()) { this.toolbarSubmenu.menu.add( this.toolbarButtons.unpublish @@ -286,30 +287,30 @@ opendxp.document.link = Class.create(opendxp.document.document, { } } - buttons.push("-"); + buttons.push('-'); if (opendxp.helpers.checkIfNewHeadbarLayoutIsEnabled()) { buttons.push(this.toolbarSubmenu); } - if (this.isAllowed("delete") && !this.data.locked) { + if (this.isAllowed('delete') && !this.data.locked) { if (opendxp.helpers.checkIfNewHeadbarLayoutIsEnabled()) { this.toolbarSubmenu.menu.add({ text: t('delete'), - iconCls: "opendxp_material_icon_delete opendxp_material_icon", - scale: "medium", + iconCls: 'opendxp_material_icon_delete opendxp_material_icon', + scale: 'medium', handler: this.remove.bind(this) }); } else { buttons.push(this.toolbarButtons.remove); } } - if (this.isAllowed("rename") && !this.data.locked) { + if (this.isAllowed('rename') && !this.data.locked) { if (opendxp.helpers.checkIfNewHeadbarLayoutIsEnabled()) { this.toolbarSubmenu.menu.add({ text: t('rename'), - iconCls: "opendxp_material_icon_rename opendxp_material_icon", - scale: "medium", + iconCls: 'opendxp_material_icon_rename opendxp_material_icon', + scale: 'medium', handler: this.rename.bind(this) }); } else { @@ -319,16 +320,16 @@ opendxp.document.link = Class.create(opendxp.document.document, { buttons.push({ tooltip: t('reload'), - iconCls: "opendxp_material_icon_reload opendxp_material_icon", - scale: "medium", + iconCls: 'opendxp_material_icon_reload opendxp_material_icon', + scale: 'medium', handler: this.reload.bind(this) }); - if (opendxp.elementservice.showLocateInTreeButton("document")) { + if (opendxp.elementservice.showLocateInTreeButton('document')) { buttons.push({ tooltip: t('show_in_tree'), - iconCls: "opendxp_material_icon_locate opendxp_material_icon", - scale: "medium", + iconCls: 'opendxp_material_icon_locate opendxp_material_icon', + scale: 'medium', handler: this.selectInTree.bind(this) }); } @@ -340,25 +341,25 @@ opendxp.document.link = Class.create(opendxp.document.document, { } if (!opendxp.helpers.checkIfNewHeadbarLayoutIsEnabled()) { - buttons.push("-"); + buttons.push('-'); buttons.push({ xtype: 'tbtext', - text: t("id") + " " + this.data.id, - scale: "medium" + text: t('id') + ' ' + this.data.id, + scale: 'medium' }); } this.toolbar = new Ext.Toolbar({ - id: "document_toolbar_" + this.id, - region: "north", + id: 'document_toolbar_' + this.id, + region: 'north', border: false, ...(() => opendxp.helpers.checkIfNewHeadbarLayoutIsEnabled() ? { flex: 3 } : { })(), - cls: "opendxp_main_toolbar", + cls: 'opendxp_main_toolbar', items: buttons, overflowHandler: 'scroller' }); - this.toolbar.on("afterrender", function () { + this.toolbar.on('afterrender', function () { window.setTimeout(function () { // it's not possible to delete the root-node if (this.id == 1) { @@ -377,32 +378,32 @@ opendxp.document.link = Class.create(opendxp.document.document, { getTabPanel: function () { - var items = []; - var user = opendxp.globalmanager.get("user"); + var items = [], + user = opendxp.globalmanager.get('user'); items.push(this.getLayoutForm()); - if (this.isAllowed("properties")) { + if (this.isAllowed('properties')) { items.push(this.properties.getLayout()); } - if (typeof this.dependencies !== "undefined") { + if (typeof this.dependencies !== 'undefined') { items.push(this.dependencies.getLayout()); } - if (this.isAllowed("settings")) { + if (this.isAllowed('settings')) { items.push(this.scheduler.getLayout()); } - if (user.isAllowed("notes_events")) { + if (user.isAllowed('notes_events')) { items.push(this.notes.getLayout()); } - if (user.isAllowed("tags_assignment")) { + if (user.isAllowed('tags_assignment')) { items.push(this.tagAssignment.getLayout()); } - if (user.isAllowed("workflow_details") && this.data.workflowManagement && this.data.workflowManagement.hasWorkflowManagement === true) { + if (user.isAllowed('workflow_details') && this.data.workflowManagement && this.data.workflowManagement.hasWorkflowManagement === true) { items.push(this.workflows.getLayout()); } @@ -430,7 +431,7 @@ opendxp.document.link = Class.create(opendxp.document.document, { }); - var path = ""; + var path = ''; if (this.data.rawHref) { path = this.data.rawHref; } @@ -438,80 +439,96 @@ opendxp.document.link = Class.create(opendxp.document.document, { let isChangeAllowed = this.data.userPermissions.publish; var pathField = new Ext.form.TextField({ - name: "path", - fieldLabel: t("path"), + name: 'path', + fieldLabel: t('path'), value: path, - fieldCls: "input_drop_target", + fieldCls: 'input_drop_target', width: 500, disabled: !isChangeAllowed, }); - pathField.on("render", function (el) { + pathField.on('render', function (el) { let currentId = this.data.id; let dd = new Ext.dd.DropZone(el.getEl().dom.parentNode.parentNode, { - ddGroup: "element", + ddGroup: 'element', getTargetFromEvent: function (e) { return this.getEl(); }, onNodeOver: function (target, dd, e, data) { - if (data.records[0].data.id == currentId){ + + const record = data.records[0]; + + if (data.records.length !== 1) { return false; } - if (data.records.length === 1 && ( - data.records[0].data.elementType === "document" || - data.records[0].data.elementType === "asset" || - data.records[0].data.elementType === "object") - && data.records[0].data.type !== "folder") { + if (record.data.elementType === 'document' && record.data.id === currentId) { + return false; + } + + if ( + record.data.type !== 'folder' && + ['document', 'asset', 'object'].includes(record.data.elementType) + ) { return Ext.dd.DropZone.prototype.dropAllowed; } + + return Ext.dd.DropZone.prototype.dropNotAllowed; }, onNodeDrop: function (target, dd, e, data) { - if(!opendxp.helpers.dragAndDropValidateSingleItem(data) || !isChangeAllowed || data.records[0].data.id == currentId) { + const record = data.records[0]; + + if (record.data.elementType === 'document' && record.data.id === currentId) { return false; } - data = data.records[0].data; - if (data.type !== "folder" && ( - data.elementType === "document" || - data.elementType === "asset" || - data.elementType === "object") - ) { - internalTypeField.setValue(data.elementType); + if (!opendxp.helpers.dragAndDropValidateSingleItem(data) || !isChangeAllowed) { + return false; + } + + if ( + record.data.type !== 'folder' && + ['document', 'asset', 'object'].includes(record.data.elementType) + ) { + internalTypeField.setValue(record.data.elementType); linkTypeField.setValue('internal'); - pathField.setValue(data.path); + pathField.setValue(record.data.path); + return true; } + + return false; + }.bind(this) }); - el.getEl().on("contextmenu", function(e) { + el.getEl().on('contextmenu', function(e) { var menu = new Ext.menu.Menu(); menu.add(new Ext.menu.Item({ text: t('empty'), - iconCls: "opendxp_icon_delete", + iconCls: 'opendxp_icon_delete', hidden: !isChangeAllowed, handler: function (item) { item.parentMenu.destroy(); - pathField.setValue(""); - internalTypeField.setValue(""); - linkTypeField.setValue(""); + pathField.setValue(''); + internalTypeField.setValue(''); + linkTypeField.setValue(''); }.bind(this) })); menu.add(new Ext.menu.Item({ text: t('open'), - iconCls: "opendxp_icon_open", + iconCls: 'opendxp_icon_open', handler: function (item) { item.parentMenu.destroy(); if(linkTypeField.getValue() === 'internal') { opendxp.helpers.openElement(pathField.getValue(), internalTypeField.getValue()); } else { - window.open(pathField.getValue(), "_blank"); + window.open(pathField.getValue(), '_blank'); } }.bind(this) })); @@ -519,7 +536,7 @@ opendxp.document.link = Class.create(opendxp.document.document, { if(opendxp.helpers.hasSearchImplementation()) { menu.add(new Ext.menu.Item({ text: t('search'), - iconCls: "opendxp_icon_search", + iconCls: 'opendxp_icon_search', hidden: !isChangeAllowed, handler: function (item) { item.parentMenu.destroy(); @@ -543,44 +560,47 @@ opendxp.document.link = Class.create(opendxp.document.document, { var items = [ pathField, { - xtype: "button", - iconCls: "opendxp_icon_open", - style: "margin-left: 5px", + xtype: 'button', + iconCls: 'opendxp_icon_open', + style: 'margin-left: 5px', handler: function() { if (pathField.getValue()) { if(linkTypeField.getValue() === 'internal') { opendxp.helpers.openElement(pathField.getValue(), internalTypeField.getValue()); } else { - window.open(pathField.getValue(), "_blank"); + window.open(pathField.getValue(), '_blank'); } } }.bind(this) }, { - xtype: "button", - iconCls: "opendxp_icon_delete", - style: "margin-left: 5px", + xtype: 'button', + iconCls: 'opendxp_icon_delete', + style: 'margin-left: 5px', hidden: !isChangeAllowed, handler: function () { - pathField.setValue(""); - internalTypeField.setValue(""); - linkTypeField.setValue(""); + pathField.setValue(''); + internalTypeField.setValue(''); + linkTypeField.setValue(''); }.bind(this) } ]; if(opendxp.helpers.hasSearchImplementation()) { items.push({ - xtype: "button", - iconCls: "opendxp_icon_search", - style: "margin-left: 5px", + xtype: 'button', + iconCls: 'opendxp_icon_search', + style: 'margin-left: 5px', hidden: !isChangeAllowed, handler: function () { opendxp.helpers.itemselector(false, function (data) { - if (this.data.id == data.id){ - Ext.Msg.alert(t('error'),t('link_recursion_error')); + + if (data.type === 'document' && this.data.id === data.id) { + Ext.Msg.alert(t('error'), t('link_recursion_error')); + return false; } + pathField.setValue(data.fullpath); linkTypeField.setValue('internal'); internalTypeField.setValue(data.type); @@ -591,12 +611,12 @@ opendxp.document.link = Class.create(opendxp.document.document, { this.panel = new Ext.form.FormPanel({ title: t('settings'), - iconCls: "opendxp_material_icon_settings opendxp_material_icon", + iconCls: 'opendxp_material_icon_settings opendxp_material_icon', autoHeight: true, labelWidth: 200, defaultType: 'textfield', bodyStyle: 'padding:10px;', - region: "center", + region: 'center', items: [ internalTypeField, linkTypeField, @@ -617,9 +637,9 @@ opendxp.document.link = Class.create(opendxp.document.document, { }, rename: function () { - if (this.isAllowed("rename") && !this.data.locked) { + if (this.isAllowed('rename') && !this.data.locked) { var options = { - elementType: "document", + elementType: 'document', elementSubType: this.getType(), id: this.id, default: this.data.key