Skip to content

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kharg authored Feb 15, 2025
1 parent b1bac6b commit 16456d7
Show file tree
Hide file tree
Showing 17 changed files with 360 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
define('link-button:views/admin/field-manager/fields/confirmation-dialog', ['views/fields/bool'], (Dep) => {
return class extends Dep {

setup() {
super.setup();
this.listenTo(this.model, 'change:mode', this.toggleConfirmationDialog);
}

afterRender() {
super.afterRender();
this.toggleConfirmationDialog();
}

toggleConfirmationDialog() {
if (this.model.get('mode') === 'runEspoWorkflow') {
this.getParentView().showField('confirmationDialog');
this.getParentView().showField('hideOriginalWorkflowAction');
} else {
this.getParentView().hideField('confirmationDialog');
this.getParentView().hideField('hideOriginalWorkflowAction');
}
}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define('link-button:views/admin/field-manager/fields/confirmation-text', ['views/fields/text'], (Dep) => {
return class extends Dep {

setup() {
super.setup();
this.listenTo(this.model, 'change:confirmationDialog change:mode', this.toggleConfirmationText);
}

afterRender() {
super.afterRender();
this.toggleConfirmationText();
}

toggleConfirmationText() {
if (this.model.get('confirmationDialog') === true && this.model.get('mode') === 'runEspoWorkflow') {
this.getParentView().showField('confirmationText');
} else {
this.getParentView().hideField('confirmationText');
}
}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
define('link-button:views/admin/field-manager/fields/mode', ['views/fields/enum'], (Dep) => {
return class extends Dep {

setup() {
super.setup();
this.updateModeOptions();
}

afterRender() {
super.afterRender();
}

updateModeOptions() {
const isAdvancedPackInstalled = this.getHelper().getAppParam('isAdvancedPackInstalled');
const modeOptions = this.model.getFieldParam('mode', 'options') || [];

if (isAdvancedPackInstalled) {
modeOptions.push('runEspoWorkflow');
}

}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
define('link-button:views/admin/field-manager/fields/popup', ['views/fields/int'], (Dep) => {
return class extends Dep {

setup() {
super.setup();
this.listenTo(this.model, 'change:mode', this.togglePopupSize);
}

afterRender() {
super.afterRender();
this.togglePopupSize();
}

togglePopupSize() {
if (this.model.get('mode') === 'openPopup') {
this.getParentView().showField('popupHeight');
this.getParentView().showField('popupWidth');
} else {
this.getParentView().hideField('popupHeight');
this.getParentView().hideField('popupWidth');
}
}
};
});
156 changes: 105 additions & 51 deletions files/client/custom/modules/link-button/src/views/fields/link-button.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,59 @@
define('link-button:views/fields/link-button', 'views/fields/url', function (Dep) {
define('link-button:views/fields/link-button', ['views/fields/url'], (Dep) => {
return class extends Dep {

return Dep.extend({
type = 'link-button'
editTemplate = 'link-button:fields/edit'
listTemplate = 'link-button:fields/list'
detailTemplate = 'link-button:fields/detail'

type: 'link-button',
setup() {
super.setup();

editTemplate: 'link-button:fields/edit',

listTemplate: 'link-button:fields/list',

detailTemplate: 'link-button:fields/detail',

events: {
'click button[data-action="open-modal"]': function() {
this.events['click button[data-action="open-modal"]'] = () => {
this.actionOpenModal();
},
'click button[data-action="espo-modal"]': function() {
};

this.events['click button[data-action="espo-modal"]'] = () => {
this.actionEspoModal();
},
'click button[data-action="open-popup"]': function() {
};

this.events['click button[data-action="open-popup"]'] = () => {
this.actionOpenPopup();
},
'click button[data-action="quick-create"]': function() {
};

this.events['click button[data-action="quick-create"]'] = () => {
this.actionQuickCreate();
},
'click button[data-action="run-workflow"]': function() {
this.actionEspoWorkFlow();
},
},
};

this.events['click button[data-action="run-workflow"]'] = () => {
this.actionCheckWorkFlow();
};

}

afterRender: function() {
Dep.prototype.afterRender.call(this);
if (this.model.getFieldParam(this.name, 'hideLabel') === true) {
afterRender() {
super.afterRender();
const superParent = this.getParentView().getParentView()._parentView;
const url = this.model.get(this.name);
const hideLabel = this.model.getFieldParam(this.name, 'hideLabel');
const isDetailMode = this.isDetailMode();
const hideOriginalWorkflowAction = this.model.getFieldParam(this.name, 'hideOriginalWorkflowAction');
const mode = this.model.getFieldParam(this.name, 'mode');

if (hideLabel === true) {
this.getLabelElement().hide();
}
},

if (url && isDetailMode && hideOriginalWorkflowAction === true && mode === 'runEspoWorkflow') {
const workflowId = url.split('#')[1]?.split('/').pop();
superParent.hideHeaderActionItem(`runWorkflow_${workflowId}`);
}

data: function() {
return _.extend({
}

data() {
return {
...super.data(),
iconLeft: this.model.getFieldParam(this.name, 'iconLeft'),
iconRight: this.model.getFieldParam(this.name, 'iconRight'),
mode: this.model.getFieldParam(this.name, 'mode'),
Expand All @@ -45,10 +62,10 @@ define('link-button:views/fields/link-button', 'views/fields/url', function (Dep
title: this.model.getFieldParam(this.name, 'title') || null,
buttonSize: this.model.getFieldParam(this.name, 'buttonSize'),
style: this.model.getFieldParam(this.name, 'style'),
}, Dep.prototype.data.call(this));
},
};
}

actionOpenModal: function() {
actionOpenModal() {
this.notify('Loading...');
this.createView('dialog', 'link-button:views/modals/button-url', {
buttonLabel: this.model.getFieldParam(this.name, 'buttonLabel') || null,
Expand All @@ -62,9 +79,9 @@ define('link-button:views/fields/link-button', 'views/fields/url', function (Dep
this.clearView('dialog');
});
}, this);
},
}

actionEspoModal: function() {
actionEspoModal() {
let model = this.model;
let url = this.model.get(this.name);
let hashPart = url.split('#')[1];
Expand Down Expand Up @@ -98,9 +115,9 @@ define('link-button:views/fields/link-button', 'views/fields/url', function (Dep
this.clearView('quickView');
});
}, this);
},
}

actionQuickCreate: function() {
actionQuickCreate() {
let model = this.model;
let url = this.model.get(this.name);
let hashPart = url.split('#')[1];
Expand Down Expand Up @@ -152,9 +169,33 @@ define('link-button:views/fields/link-button', 'views/fields/url', function (Dep
//model.collection.fetch();
});
}, this);
},
}

actionCheckWorkFlow() {
let message = this.translate('confirmation', 'messages');
let confirmationText = this.model.getFieldParam(this.name, 'confirmationText');
let confirmation = this.model.getFieldParam(this.name, 'confirmationDialog');
if (confirmationText) {
message = this.getHelper().transformMarkdownText(confirmationText).toString();
}

if (!confirmation) {
this.actionEspoWorkFlow();

actionEspoWorkFlow: function() {
return;
}

Espo.Ui.confirm(message, {
confirmText: this.translate('Yes', 'labels'),
cancelText: this.translate('No', 'labels'),
backdrop: true,
isHtml: true,
})
.then(() => this.actionEspoWorkFlow());
}


actionEspoWorkFlow() {
let model = this.model;
let url = model.get(this.name);
let hashPart = url.split('#')[1];
Expand All @@ -170,19 +211,32 @@ define('link-button:views/fields/link-button', 'views/fields/url', function (Dep
if (entityType !== 'Workflow') {
return Espo.Ui.error(('Error: not a workflow'));
}
//TODO Api action to check if the workflow is manual
Espo.Ajax.postRequest('WorkflowManual/action/run', {
targetId: model.id,
id: workflowId,
}).then(() => {
model.fetch().then(() => {
Espo.Ui.success(('Done'));

Espo.Ajax.getRequest('LinkButton/WorkflowCheck/' + workflowId)
.then(response => {
if (response.isManual === false) {
return Espo.Ui.error(('Error: not a manual or active workflow'));
}

Espo.Ajax.postRequest('WorkflowManual/action/run', {
targetId: model.id,
id: workflowId,
}).then(() => {
model.fetch().then(() => {
Espo.Ui.success(('Done'));
});
});
})
.catch(error => {
console.error(error);
Espo.Ui.error(('Error checking workflow type'));
});
},

actionOpenPopup: function() {
window.open(this.model.get(this.name), '_blank', 'scrollbars=yes,height=800,width=600');
},
});
});
}

actionOpenPopup() {
const popupHeight = this.model.getFieldParam(this.name, 'popupHeight') || 800;
const popupWidth = this.model.getFieldParam(this.name, 'popupWidth') || 600;
window.open(this.model.get(this.name), '_blank', `scrollbars=yes,height=${popupHeight},width=${popupWidth}`);
}
};
});
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
define('link-button:views/modals/button-url', 'views/modal', function (Dep) {
define('link-button:views/modals/button-url', ['views/modal'], (Dep) => {
return class extends Dep {

return Dep.extend({

template: 'link-button:modals/button-url',
fitHeight: true,
isCollapsable: true,
template = 'link-button:modals/button-url'
fitHeight = true
isCollapsable = true

data: function () {
data() {
return {
...super.data(),
url: this.options.url
};
},
}

setup: function () {
setup() {
super.setup();
this.headerText = document.title || this.options.buttonLabel || 'Modal';
},

});
}
};
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
define('link-button:views/modals/espo-modal', 'views/modals/detail', function (Dep) {
define('link-button:views/modals/espo-modal', ['views/modals/detail'], (Dep) => {
return class extends Dep {

return Dep.extend({
isCollapsable = true

isCollapsable: true,

});
};
});
Loading

0 comments on commit 16456d7

Please sign in to comment.