Push changes to frontend
This commit is contained in:
134
web/api/ApproveAdminAdapter.js
Normal file
134
web/api/ApproveAdminAdapter.js
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
|
||||
/**
|
||||
* ApproveAdminAdapter
|
||||
*/
|
||||
import LogViewAdapter from './LogViewAdapter';
|
||||
|
||||
class ApproveAdminAdapter extends LogViewAdapter {
|
||||
constructor(endPoint, tab, filter, orderBy) {
|
||||
super(endPoint, tab, filter, orderBy);
|
||||
}
|
||||
|
||||
getStatusFieldPosition() {
|
||||
const dm = this.getDataMapping();
|
||||
return dm.length - 1;
|
||||
}
|
||||
|
||||
openStatus(id, status) {
|
||||
$(`#${this.itemNameLower}StatusModel`).modal('show');
|
||||
$(`#${this.itemNameLower}_status`).html(this.getStatusOptions(status));
|
||||
$(`#${this.itemNameLower}_status`).val(status);
|
||||
this.statusChangeId = id;
|
||||
}
|
||||
|
||||
closeDialog() {
|
||||
$(`#${this.itemNameLower}StatusModel`).modal('hide');
|
||||
}
|
||||
|
||||
changeStatus() {
|
||||
const status = $(`#${this.itemNameLower}_status`).val();
|
||||
const reason = $(`#${this.itemNameLower}_reason`).val();
|
||||
|
||||
if (status == undefined || status == null || status == '') {
|
||||
this.showMessage('Error', `Please select ${this.itemNameLower} status`);
|
||||
return;
|
||||
}
|
||||
|
||||
const object = { id: this.statusChangeId, status, reason };
|
||||
|
||||
const reqJson = JSON.stringify(object);
|
||||
|
||||
const callBackData = [];
|
||||
callBackData.callBackData = [];
|
||||
callBackData.callBackSuccess = 'changeStatusSuccessCallBack';
|
||||
callBackData.callBackFail = 'changeStatusFailCallBack';
|
||||
|
||||
this.customAction('changeStatus', `admin=${this.modulePathName}`, reqJson, callBackData);
|
||||
|
||||
this.closeDialog();
|
||||
this.statusChangeId = null;
|
||||
}
|
||||
|
||||
changeStatusSuccessCallBack(callBackData) {
|
||||
this.showMessage('Successful', `${this.itemName} Request status changed successfully`);
|
||||
this.get([]);
|
||||
}
|
||||
|
||||
changeStatusFailCallBack(callBackData) {
|
||||
this.showMessage('Error', `Error occurred while changing ${this.itemName} request status`);
|
||||
}
|
||||
|
||||
|
||||
getActionButtonsHtml(id, data) {
|
||||
const editButton = '<img class="tableActionButton" src="_BASE_images/edit.png" style="cursor:pointer;" rel="tooltip" title="Edit" onclick="modJs.edit(_id_);return false;"></img>';
|
||||
const deleteButton = '<img class="tableActionButton" src="_BASE_images/delete.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="Delete" onclick="modJs.deleteRow(_id_);return false;"></img>';
|
||||
const statusChangeButton = '<img class="tableActionButton" src="_BASE_images/run.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="Change Status" onclick="modJs.openStatus(_id_, \'_cstatus_\');return false;"></img>';
|
||||
const viewLogsButton = '<img class="tableActionButton" src="_BASE_images/log.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="View Logs" onclick="modJs.getLogs(_id_);return false;"></img>';
|
||||
|
||||
let html = '<div style="width:120px;">_edit__delete__status__logs_</div>';
|
||||
|
||||
const optiondata = this.getStatusOptionsData(data[this.getStatusFieldPosition()]);
|
||||
if (Object.keys(optiondata).length > 0) {
|
||||
html = html.replace('_status_', statusChangeButton);
|
||||
} else {
|
||||
html = html.replace('_status_', '');
|
||||
}
|
||||
|
||||
html = html.replace('_logs_', viewLogsButton);
|
||||
|
||||
if (this.showDelete) {
|
||||
html = html.replace('_delete_', deleteButton);
|
||||
} else {
|
||||
html = html.replace('_delete_', '');
|
||||
}
|
||||
|
||||
if (this.showEdit) {
|
||||
html = html.replace('_edit_', editButton);
|
||||
} else {
|
||||
html = html.replace('_edit_', '');
|
||||
}
|
||||
|
||||
html = html.replace(/_id_/g, id);
|
||||
html = html.replace(/_BASE_/g, this.baseUrl);
|
||||
html = html.replace(/_cstatus_/g, data[this.getStatusFieldPosition()]);
|
||||
return html;
|
||||
}
|
||||
|
||||
isSubProfileTable() {
|
||||
if (this.user.user_level == 'Admin') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
getStatusOptionsData(currentStatus) {
|
||||
const data = {};
|
||||
if (currentStatus == 'Approved') {
|
||||
|
||||
} else if (currentStatus == 'Pending') {
|
||||
data.Approved = 'Approved';
|
||||
data.Rejected = 'Rejected';
|
||||
} else if (currentStatus == 'Rejected') {
|
||||
|
||||
} else if (currentStatus == 'Cancelled') {
|
||||
|
||||
} else if (currentStatus == 'Processing') {
|
||||
|
||||
} else {
|
||||
data['Cancellation Requested'] = 'Cancellation Requested';
|
||||
data.Cancelled = 'Cancelled';
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
getStatusOptions(currentStatus) {
|
||||
return this.generateOptions(this.getStatusOptionsData(currentStatus));
|
||||
}
|
||||
}
|
||||
|
||||
export default ApproveAdminAdapter;
|
||||
50
web/api/ApproveApproverAdapter.js
Normal file
50
web/api/ApproveApproverAdapter.js
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
|
||||
/**
|
||||
* ApproveApproverAdapter
|
||||
*/
|
||||
|
||||
class ApproveApproverAdapter {
|
||||
getActionButtonsHtml(id, data) {
|
||||
const statusChangeButton = '<img class="tableActionButton" src="_BASE_images/run.png" style="cursor:pointer;" rel="tooltip" title="Change Status" onclick="modJs.openStatus(_id_, \'_cstatus_\');return false;"></img>';
|
||||
const viewLogsButton = '<img class="tableActionButton" src="_BASE_images/log.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="View Logs" onclick="modJs.getLogs(_id_);return false;"></img>';
|
||||
|
||||
let html = '<div style="width:80px;">_status__logs_</div>';
|
||||
|
||||
|
||||
html = html.replace('_logs_', viewLogsButton);
|
||||
|
||||
|
||||
if (data[this.getStatusFieldPosition()] == 'Processing') {
|
||||
html = html.replace('_status_', statusChangeButton);
|
||||
} else {
|
||||
html = html.replace('_status_', '');
|
||||
}
|
||||
|
||||
html = html.replace(/_id_/g, id);
|
||||
html = html.replace(/_BASE_/g, this.baseUrl);
|
||||
html = html.replace(/_cstatus_/g, data[this.getStatusFieldPosition()]);
|
||||
return html;
|
||||
}
|
||||
|
||||
getStatusOptionsData(currentStatus) {
|
||||
const data = {};
|
||||
if (currentStatus != 'Processing') {
|
||||
|
||||
} else {
|
||||
data.Approved = 'Approved';
|
||||
data.Rejected = 'Rejected';
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
getStatusOptions(currentStatus) {
|
||||
return this.generateOptions(this.getStatusOptionsData(currentStatus));
|
||||
}
|
||||
}
|
||||
|
||||
export default ApproveApproverAdapter;
|
||||
68
web/api/ApproveModuleAdapter.js
Normal file
68
web/api/ApproveModuleAdapter.js
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
|
||||
import LogViewAdapter from './LogViewAdapter';
|
||||
|
||||
class ApproveModuleAdapter extends LogViewAdapter {
|
||||
cancelRequest(id) {
|
||||
const object = {};
|
||||
object.id = id;
|
||||
|
||||
const reqJson = JSON.stringify(object);
|
||||
|
||||
const callBackData = [];
|
||||
callBackData.callBackData = [];
|
||||
callBackData.callBackSuccess = 'cancelSuccessCallBack';
|
||||
callBackData.callBackFail = 'cancelFailCallBack';
|
||||
|
||||
this.customAction('cancel', `modules=${this.modulePathName}`, reqJson, callBackData);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
cancelSuccessCallBack(callBackData) {
|
||||
this.showMessage('Successful', `${this.itemName} cancellation request sent`);
|
||||
this.get([]);
|
||||
}
|
||||
|
||||
cancelFailCallBack(callBackData) {
|
||||
this.showMessage(`Error Occurred while cancelling ${this.itemName}`, callBackData);
|
||||
}
|
||||
|
||||
getActionButtonsHtml(id, data) {
|
||||
const editButton = '<img class="tableActionButton" src="_BASE_images/edit.png" style="cursor:pointer;" rel="tooltip" title="Edit" onclick="modJs.edit(_id_);return false;"></img>';
|
||||
const deleteButton = '<img class="tableActionButton" src="_BASE_images/delete.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="Delete" onclick="modJs.deleteRow(_id_);return false;"></img>';
|
||||
const requestCancellationButton = `<img class="tableActionButton" src="_BASE_images/delete.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="Cancel ${this.itemName}" onclick="modJs.cancelRequest(_id_);return false;"></img>`;
|
||||
const viewLogsButton = '<img class="tableActionButton" src="_BASE_images/log.png" style="margin-left:15px;cursor:pointer;" rel="tooltip" title="View Logs" onclick="modJs.getLogs(_id_);return false;"></img>';
|
||||
|
||||
|
||||
let html = '<div style="width:120px;">_edit__logs__delete_</div>';
|
||||
|
||||
html = html.replace('_logs_', viewLogsButton);
|
||||
|
||||
if (this.showDelete) {
|
||||
if (data[7] === 'Approved') {
|
||||
html = html.replace('_delete_', requestCancellationButton);
|
||||
} else if (data[7] === 'Pending' || this.user.user_level === 'Admin') {
|
||||
html = html.replace('_delete_', deleteButton);
|
||||
} else {
|
||||
html = html.replace('_delete_', '');
|
||||
}
|
||||
} else {
|
||||
html = html.replace('_delete_', '');
|
||||
}
|
||||
|
||||
if (this.showEdit) {
|
||||
html = html.replace('_edit_', editButton);
|
||||
} else {
|
||||
html = html.replace('_edit_', '');
|
||||
}
|
||||
|
||||
html = html.replace(/_id_/g, id);
|
||||
html = html.replace(/_BASE_/g, this.baseUrl);
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
||||
export default ApproveModuleAdapter;
|
||||
27
web/api/BaseGraphAdapter.js
Normal file
27
web/api/BaseGraphAdapter.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
|
||||
import AdapterBase from './AdapterBase';
|
||||
|
||||
class BaseGraphAdapter extends AdapterBase {
|
||||
getDataMapping() {
|
||||
return [];
|
||||
}
|
||||
|
||||
getHeaders() {
|
||||
return [];
|
||||
}
|
||||
|
||||
getFormFields() {
|
||||
return [];
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
createTable(elementId) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default BaseGraphAdapter;
|
||||
102
web/api/CustomFieldAdapter.js
Normal file
102
web/api/CustomFieldAdapter.js
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
import AdapterBase from './AdapterBase';
|
||||
|
||||
/*
|
||||
* CustomFieldAdapter
|
||||
*/
|
||||
|
||||
class CustomFieldAdapter extends AdapterBase {
|
||||
constructor(endPoint, tab, filter, orderBy) {
|
||||
super(endPoint, tab, filter, orderBy);
|
||||
this.tableType = '';
|
||||
}
|
||||
|
||||
getDataMapping() {
|
||||
return [
|
||||
'id',
|
||||
'name',
|
||||
'display',
|
||||
'display_order',
|
||||
];
|
||||
}
|
||||
|
||||
getHeaders() {
|
||||
return [
|
||||
{ sTitle: 'ID', bVisible: false },
|
||||
{ sTitle: 'Name' },
|
||||
{ sTitle: 'Display Status' },
|
||||
{ sTitle: 'Priority' },
|
||||
];
|
||||
}
|
||||
|
||||
getFormFields() {
|
||||
return [
|
||||
['id', { label: 'ID', type: 'hidden' }],
|
||||
['name', { label: 'Name', type: 'text', validation: '' }],
|
||||
['display', { label: 'Display Status', type: 'select', source: [['Form', 'Show'], ['Hidden', 'Hidden']] }],
|
||||
['field_type', { label: 'Field Type', type: 'select', source: [['text', 'Text Field'], ['textarea', 'Text Area'], ['select', 'Select'], ['select2', 'Select2'], ['select2multi', 'Multi Select'], ['fileupload', 'File Upload'], ['date', 'Date'], ['datetime', 'Date Time'], ['time', 'Time']] }],
|
||||
['field_label', { label: 'Field Label', type: 'text', validation: '' }],
|
||||
['field_validation', {
|
||||
label: 'Validation', type: 'select2', validation: 'none', sort: 'none', 'null-label': 'Required', 'allow-null': true, source: [['none', 'None'], ['number', 'Number'], ['numberOrEmpty', 'Number or Empty'], ['float', 'Decimal'], ['email', 'Email'], ['emailOrEmpty', 'Email or Empty']],
|
||||
}],
|
||||
['field_options', {
|
||||
label: 'Field Options',
|
||||
type: 'datagroup',
|
||||
form: [
|
||||
['label', { label: 'Label', type: 'text', validation: '' }],
|
||||
['value', { label: 'Value', type: 'text', validation: 'none' }],
|
||||
],
|
||||
html: '<div id="#_id_#" class="panel panel-default"><div class="panel-body">#_delete_##_edit_#<span style="color:#999;font-size:13px;font-weight:bold">#_label_#</span>:#_value_#</div></div>',
|
||||
validation: 'none',
|
||||
}],
|
||||
['display_order', { label: 'Priority', type: 'text', validation: 'number' }],
|
||||
['display_section', { label: 'Display Section', type: 'text', validation: 'none' }],
|
||||
];
|
||||
}
|
||||
|
||||
setTableType(type) {
|
||||
this.tableType = type;
|
||||
}
|
||||
|
||||
doCustomValidation(params) {
|
||||
const validateName = function (str) {
|
||||
const name = /^[a-z][a-z0-9._]+$/;
|
||||
return str != null && name.test(str);
|
||||
};
|
||||
|
||||
if (!validateName(params.name)) {
|
||||
return 'Invalid name for custom field';
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
forceInjectValuesBeforeSave(params) {
|
||||
const data = [params.name]; const options = []; let
|
||||
optionsData;
|
||||
data.push({});
|
||||
data[1].label = params.field_label;
|
||||
data[1].type = params.field_type;
|
||||
data[1].validation = params.field_validation;
|
||||
if (['select', 'select2', 'select2multi'].indexOf(params.field_type) >= 0) {
|
||||
optionsData = (params.field_options === '' || params.field_options === undefined)
|
||||
? [] : JSON.parse(params.field_options);
|
||||
for (const index in optionsData) {
|
||||
options.push([optionsData[index].value, optionsData[index].label]);
|
||||
}
|
||||
data[1].source = options;
|
||||
}
|
||||
if (params.field_validation == null || params.field_validation === undefined) {
|
||||
params.field_validation = '';
|
||||
}
|
||||
params.data = JSON.stringify(data);
|
||||
params.type = this.tableType;
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
||||
export default CustomFieldAdapter;
|
||||
37
web/api/IdNameAdapter.js
Normal file
37
web/api/IdNameAdapter.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
import AdapterBase from './AdapterBase';
|
||||
/**
|
||||
* IdNameAdapter
|
||||
*/
|
||||
|
||||
class IdNameAdapter extends AdapterBase {
|
||||
constructor(endPoint, tab, filter, orderBy) {
|
||||
super(endPoint, tab, filter, orderBy);
|
||||
}
|
||||
|
||||
getDataMapping() {
|
||||
return [
|
||||
'id',
|
||||
'name',
|
||||
];
|
||||
}
|
||||
|
||||
getHeaders() {
|
||||
return [
|
||||
{ sTitle: 'ID', bVisible: false },
|
||||
{ sTitle: 'Name' },
|
||||
];
|
||||
}
|
||||
|
||||
getFormFields() {
|
||||
return [
|
||||
['id', { label: 'ID', type: 'hidden' }],
|
||||
['name', { label: 'Name', type: 'text', validation: '' }],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
export default IdNameAdapter;
|
||||
58
web/api/LogViewAdapter.js
Normal file
58
web/api/LogViewAdapter.js
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
/* global timeUtils */
|
||||
/**
|
||||
* LogViewAdapter
|
||||
*/
|
||||
|
||||
import AdapterBase from './AdapterBase';
|
||||
|
||||
class LogViewAdapter extends AdapterBase {
|
||||
getLogs(id) {
|
||||
const object = { id };
|
||||
const reqJson = JSON.stringify(object);
|
||||
|
||||
const callBackData = [];
|
||||
callBackData.callBackData = [];
|
||||
callBackData.callBackSuccess = 'getLogsSuccessCallBack';
|
||||
callBackData.callBackFail = 'getLogsFailCallBack';
|
||||
|
||||
this.customAction('getLogs', `admin=${this.modulePathName}`, reqJson, callBackData);
|
||||
}
|
||||
|
||||
getLogsSuccessCallBack(callBackData) {
|
||||
let tableLog = '<table class="table table-condensed table-bordered table-striped" style="font-size:14px;"><thead><tr><th>Notes</th></tr></thead><tbody>_days_</tbody></table> ';
|
||||
const rowLog = '<tr><td><span class="logTime label label-default">_date_</span> <b>_status_</b><br/>_note_</td></tr>';
|
||||
|
||||
const logs = callBackData.data;
|
||||
let html = '';
|
||||
let rowsLogs = '';
|
||||
|
||||
|
||||
for (let i = 0; i < logs.length; i++) {
|
||||
let trow = rowLog;
|
||||
trow = trow.replace(/_date_/g, logs[i].time);
|
||||
trow = trow.replace(/_status_/g, `${logs[i].status_from} -> ${logs[i].status_to}`);
|
||||
trow = trow.replace(/_note_/g, logs[i].note);
|
||||
rowsLogs += trow;
|
||||
}
|
||||
|
||||
if (rowsLogs !== '') {
|
||||
tableLog = tableLog.replace('_days_', rowsLogs);
|
||||
html += tableLog;
|
||||
}
|
||||
|
||||
this.showMessage('Logs', html);
|
||||
|
||||
timeUtils.convertToRelativeTime($('.logTime'));
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
getLogsFailCallBack(callBackData) {
|
||||
this.showMessage('Error', 'Error occured while getting data');
|
||||
}
|
||||
}
|
||||
|
||||
export default LogViewAdapter;
|
||||
2528
web/api/ModuleBase.js
Normal file
2528
web/api/ModuleBase.js
Normal file
File diff suppressed because it is too large
Load Diff
216
web/api/ObjectAdapter.js
Normal file
216
web/api/ObjectAdapter.js
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
import AdapterBase from './AdapterBase';
|
||||
/**
|
||||
* ObjectAdapter
|
||||
*/
|
||||
|
||||
class ObjectAdapter extends AdapterBase {
|
||||
constructor(endPoint, tab, filter, orderBy) {
|
||||
super(endPoint, tab, filter, orderBy);
|
||||
this.container = null;
|
||||
this.loadMoreButton = null;
|
||||
this.start = 0;
|
||||
this.pageSize = 6;
|
||||
this.currentPage = 1;
|
||||
this.hasMoreData = true;
|
||||
this.searchTerm = '';
|
||||
this.searchInput = null;
|
||||
}
|
||||
|
||||
getObjectHTML(object) {
|
||||
const template = this.getCustomTemplate(this.getTemplateName());
|
||||
let t = template;
|
||||
for (const index in object) {
|
||||
t = t.replace(new RegExp(`#_${index}_#`, 'g'), object[index]);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
setPageSize(pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
addDomEvents(object) {
|
||||
|
||||
}
|
||||
|
||||
getTemplateName() {
|
||||
return '';
|
||||
}
|
||||
|
||||
renderObject(object) {
|
||||
const objDom = this.getObjectDom(object.id);
|
||||
|
||||
const html = this.getObjectHTML(object);
|
||||
const domObj = $(html);
|
||||
|
||||
|
||||
if (objDom !== undefined && objDom != null) {
|
||||
objDom.replace(domObj);
|
||||
} else {
|
||||
this.container.append(domObj);
|
||||
}
|
||||
|
||||
this.addDomEvents(domObj);
|
||||
}
|
||||
|
||||
setContainer(container) {
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
setLoadMoreButton(loadMoreButton) {
|
||||
const that = this;
|
||||
this.loadMoreButton = loadMoreButton;
|
||||
this.loadMoreButton.off().on('click', () => {
|
||||
that.loadMoreButton.attr('disabled', 'disabled');
|
||||
that.loadMore([]);
|
||||
});
|
||||
}
|
||||
|
||||
showLoadError(msg) {
|
||||
$(`#${this.getTableName()}_error`).html(msg);
|
||||
$(`#${this.getTableName()}_error`).show();
|
||||
}
|
||||
|
||||
hideLoadError() {
|
||||
$(`#${this.getTableName()}_error`).hide();
|
||||
}
|
||||
|
||||
setSearchBox(searchInput) {
|
||||
const that = this;
|
||||
this.searchInput = searchInput;
|
||||
this.searchInput.off();
|
||||
this.searchInput.keydown(function (event) {
|
||||
const val = $(this).val();
|
||||
if (event.which === 13) {
|
||||
event.preventDefault();
|
||||
that.search([]);
|
||||
} else if ((event.which === 8 || event.which === 46) && val.length === 1 && that.searchTerm !== '') {
|
||||
that.search([]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getObjectDom(id) {
|
||||
const obj = this.container.find(`#obj_${id}`);
|
||||
if (obj.length) {
|
||||
return obj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
loadMore(callBackData) {
|
||||
if (!this.hasMoreData) {
|
||||
return;
|
||||
}
|
||||
this.currentPage++;
|
||||
this.get(callBackData, true);
|
||||
}
|
||||
|
||||
get(callBackData, loadMore) {
|
||||
const that = this;
|
||||
|
||||
this.hideLoadError();
|
||||
|
||||
if (!loadMore) {
|
||||
this.currentPage = 1;
|
||||
if (this.container != null) {
|
||||
this.container.html('');
|
||||
}
|
||||
this.hasMoreData = true;
|
||||
this.tableData = [];
|
||||
}
|
||||
|
||||
this.start = (this.currentPage - 1) * this.pageSize;
|
||||
|
||||
|
||||
this.container = $(`#${this.getTableName()}`).find('.objectList');
|
||||
|
||||
that.showLoader();
|
||||
|
||||
|
||||
let url = `${this.getDataUrl(that.getDataMapping())
|
||||
}&iDisplayStart=${this.start}&iDisplayLength=${this.pageSize}&objects=1`;
|
||||
|
||||
if (this.searchTerm !== '' && this.searchTerm !== undefined && this.searchTerm != null) {
|
||||
url += `&sSearch=${this.searchTerm}`;
|
||||
}
|
||||
|
||||
$.post(url, (data) => {
|
||||
that.getSuccessCallBack(callBackData, data);
|
||||
}, 'json').always(() => { that.hideLoader(); });
|
||||
|
||||
that.initFieldMasterData();
|
||||
|
||||
this.trackEvent('get', this.tab, this.table);
|
||||
}
|
||||
|
||||
search(callBackData) {
|
||||
const that = this;
|
||||
this.searchTerm = $(`#${this.getTableName()}_search`).val();
|
||||
|
||||
this.get(callBackData);
|
||||
}
|
||||
|
||||
|
||||
getSuccessCallBack(callBackData, serverData) {
|
||||
const data = [];
|
||||
|
||||
if (serverData.length === 0 && this.container.html() === '') {
|
||||
this.showLoadError('No Results Found !!!');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getFilters() == null) {
|
||||
$(`#${this.getTableName()}_filterBtn`).hide();
|
||||
$(`#${this.getTableName()}_resetFilters`).hide();
|
||||
} else {
|
||||
$(`#${this.getTableName()}_filterBtn`).show();
|
||||
$(`#${this.getTableName()}_resetFilters`).show();
|
||||
if (this.currentFilterString !== '' && this.currentFilterString != null) {
|
||||
$(`#${this.getTableName()}_resetFilters`).html(`${this.currentFilterString}<i class="fa fa-times"></i>`);
|
||||
} else {
|
||||
$(`#${this.getTableName()}_resetFilters`).html('Reset Filters');
|
||||
$(`#${this.getTableName()}_resetFilters`).hide();
|
||||
}
|
||||
}
|
||||
|
||||
$(`#${this.getTableName()}`).find('.search-controls').show();
|
||||
if (serverData.length > this.pageSize) {
|
||||
this.hasMoreData = true;
|
||||
serverData.pop();
|
||||
this.loadMoreButton.removeAttr('disabled');
|
||||
this.loadMoreButton.show();
|
||||
} else {
|
||||
this.hasMoreData = false;
|
||||
this.loadMoreButton.hide();
|
||||
}
|
||||
|
||||
this.scrollToElementBottom(this.container);
|
||||
for (let i = 0; i < serverData.length; i++) {
|
||||
data.push(this.preProcessTableData(serverData[i]));
|
||||
}
|
||||
this.sourceData = serverData;
|
||||
if (callBackData.callBack !== undefined && callBackData.callBack != null) {
|
||||
if (callBackData.callBackData === undefined || callBackData.callBackData == null) {
|
||||
callBackData.callBackData = [];
|
||||
}
|
||||
callBackData.callBackData.push(serverData);
|
||||
callBackData.callBackData.push(data);
|
||||
this.callFunction(callBackData.callBack, callBackData.callBackData);
|
||||
}
|
||||
|
||||
this.tableData = data;
|
||||
|
||||
if (!(callBackData.noRender !== undefined && callBackData.noRender != null && callBackData.noRender === true)) {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
this.renderObject(data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ObjectAdapter;
|
||||
60
web/api/SubAdapterBase.js
Normal file
60
web/api/SubAdapterBase.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
import AdapterBase from './AdapterBase';
|
||||
/**
|
||||
* @class SubAdapterBase
|
||||
* @param endPoint
|
||||
* @param tab
|
||||
* @param filter
|
||||
* @param orderBy
|
||||
* @returns
|
||||
*/
|
||||
|
||||
class SubAdapterBase extends AdapterBase {
|
||||
deleteRow(id) {
|
||||
this.deleteParams.id = id;
|
||||
this.confirmDelete();
|
||||
}
|
||||
|
||||
createTable(elementId) {
|
||||
let item; let itemHtml; let itemDelete; let itemEdit;
|
||||
const data = this.getTableData();
|
||||
|
||||
const deleteButton = `<button id="#_id_#_delete" onclick="modJs.subModJsList['tab${elementId}'].deleteRow('_id_');return false;" type="button" style="position: absolute;bottom: 5px;right: 5px;font-size: 13px;" tooltip="Delete"><li class="fa fa-times"></li></button>`;
|
||||
const editButton = `<button id="#_id_#_edit" onclick="modJs.subModJsList['tab${elementId}'].edit('_id_');return false;" type="button" style="position: absolute;bottom: 5px;right: 35px;font-size: 13px;" tooltip="Edit"><li class="fa fa-edit"></li></button>`;
|
||||
|
||||
const table = $('<div class="list-group"></div>');
|
||||
|
||||
// add Header
|
||||
const header = this.getSubHeader();
|
||||
table.append(header);
|
||||
if (data.length === 0) {
|
||||
table.append(`<a href="#" class="list-group-item">${this.getNoDataMessage()}</a>`);
|
||||
} else {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
item = data[i];
|
||||
itemDelete = deleteButton.replace(/_id_/g, item[0]);
|
||||
itemEdit = editButton.replace(/_id_/g, item[0]);
|
||||
itemHtml = this.getSubItemHtml(item, itemDelete, itemEdit);
|
||||
table.append(itemHtml);
|
||||
}
|
||||
}
|
||||
$(`#${elementId}`).html('');
|
||||
$(`#${elementId}`).append(table);
|
||||
$('#plainMessageModel').modal('hide');
|
||||
}
|
||||
|
||||
getNoDataMessage() {
|
||||
return 'No data found';
|
||||
}
|
||||
|
||||
getSubHeader() {
|
||||
const header = $(`<a href="#" onclick="return false;" class="list-group-item" style="background:#eee;"><h4 class="list-group-item-heading">${this.getSubHeaderTitle()}</h4></a>`);
|
||||
return header;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default SubAdapterBase;
|
||||
297
web/api/TableEditAdapter.js
Normal file
297
web/api/TableEditAdapter.js
Normal file
@@ -0,0 +1,297 @@
|
||||
/* global modJs */
|
||||
/*
|
||||
Copyright (c) 2018 [Glacies UG, Berlin, Germany] (http://glacies.de)
|
||||
Developer: Thilina Hasantha (http://lk.linkedin.com/in/thilinah | https://github.com/thilinah)
|
||||
*/
|
||||
import AdapterBase from './AdapterBase';
|
||||
/**
|
||||
* TableEditAdapter
|
||||
*/
|
||||
|
||||
class TableEditAdapter extends AdapterBase {
|
||||
constructor(endPoint, tab, filter, orderBy) {
|
||||
super(endPoint, tab, filter, orderBy);
|
||||
this.cellDataUpdates = {};
|
||||
this.modulePath = '';
|
||||
this.rowFieldName = '';
|
||||
this.columnFieldName = '';
|
||||
this.rowTable = '';
|
||||
this.columnTable = '';
|
||||
this.valueTable = '';
|
||||
this.csvData = [];
|
||||
this.columnIDMap = {};
|
||||
}
|
||||
|
||||
setModulePath(path) {
|
||||
this.modulePath = path;
|
||||
}
|
||||
|
||||
setRowFieldName(name) {
|
||||
this.rowFieldName = name;
|
||||
}
|
||||
|
||||
setTables(rowTable, columnTable, valueTable) {
|
||||
this.rowTable = rowTable;
|
||||
this.columnTable = columnTable;
|
||||
this.valueTable = valueTable;
|
||||
}
|
||||
|
||||
setColumnFieldName(name) {
|
||||
this.columnFieldName = name;
|
||||
}
|
||||
|
||||
getDataMapping() {
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
getFormFields() {
|
||||
return [
|
||||
];
|
||||
}
|
||||
|
||||
get() {
|
||||
this.getAllData();
|
||||
}
|
||||
|
||||
getAllData(save) {
|
||||
let req = {};
|
||||
req.rowTable = this.rowTable;
|
||||
req.columnTable = this.columnTable;
|
||||
req.valueTable = this.valueTable;
|
||||
req = this.addAdditionalRequestData('getAllData', req);
|
||||
req.save = (save === undefined || save == null || save === false) ? 0 : 1;
|
||||
const reqJson = JSON.stringify(req);
|
||||
|
||||
const callBackData = [];
|
||||
callBackData.callBackData = [];
|
||||
callBackData.callBackSuccess = 'getAllDataSuccessCallBack';
|
||||
callBackData.callBackFail = 'getAllDataFailCallBack';
|
||||
|
||||
this.customAction('getAllData', this.modulePath, reqJson, callBackData);
|
||||
}
|
||||
|
||||
getDataItem(row, column, allData) {
|
||||
const columnData = allData[1];
|
||||
const rowData = allData[0];
|
||||
const serverData = allData[2];
|
||||
|
||||
if (column === -1) {
|
||||
return rowData[row].name;
|
||||
}
|
||||
return this.getDataItemByKeyValues(this.rowFieldName, rowData[row].id, this.columnFieldName, columnData[column].id, serverData);
|
||||
}
|
||||
|
||||
getDataItemByKeyValues(rowKeyName, rowKeyVal, colKeyName, colKeyVal, data) {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (data[i][rowKeyName] === rowKeyVal && data[i][colKeyName] === colKeyVal) {
|
||||
return (data[i].amount !== undefined && data[i].amount != null) ? data[i].amount : '';
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
getAllDataSuccessCallBack(allData) {
|
||||
const serverData = allData[2];
|
||||
const columnData = allData[1];
|
||||
const rowData = allData[0];
|
||||
const data = [];
|
||||
for (let i = 0; i < rowData.length; i++) {
|
||||
const row = [];
|
||||
for (let j = -1; j < columnData.length; j++) {
|
||||
row[j + 1] = this.getDataItem(i, j, allData);
|
||||
}
|
||||
data.push(this.preProcessTableData(row));
|
||||
}
|
||||
this.sourceData = serverData;
|
||||
|
||||
|
||||
this.tableData = data;
|
||||
this.setHeaders(columnData, rowData);
|
||||
this.createTable(this.getTableName());
|
||||
$(`#${this.getTableName()}Form`).hide();
|
||||
$(`#${this.getTableName()}`).show();
|
||||
|
||||
this.csvData = [];
|
||||
|
||||
let tmpRow = [];
|
||||
for (let i = 0; i < columnData.length; i++) {
|
||||
tmpRow.push(columnData[i].name);
|
||||
}
|
||||
tmpRow = this.modifyCSVHeader(tmpRow);
|
||||
this.csvData.push(tmpRow);
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
this.csvData.push(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
modifyCSVHeader(header) {
|
||||
return header;
|
||||
}
|
||||
|
||||
getAllDataFailCallBack(callBackData, serverData) {
|
||||
|
||||
}
|
||||
|
||||
setHeaders(columns, rows) {
|
||||
const headers = [];
|
||||
headers.push({ sTitle: '', sWidth: '180px;' });
|
||||
let sclass = '';
|
||||
this.columnIDMap = {};
|
||||
for (let i = 0; i < columns.length; i++) {
|
||||
this.columnIDMap[columns[i].id] = i;
|
||||
if (columns[i].editable === undefined || columns[i].editable == null || columns[i].editable === 'Yes') {
|
||||
sclass = 'editcell';
|
||||
} else {
|
||||
sclass = '';
|
||||
}
|
||||
headers.push({
|
||||
sTitle: columns[i].name,
|
||||
sClass: sclass,
|
||||
fnCreatedCell(nTd, sData, oData, iRow, iCol) {
|
||||
$(nTd).data('colId', columns[iCol - 1].id);
|
||||
$(nTd).data('rowId', rows[iRow].id);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
getHeaders() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
createTable(elementId) {
|
||||
const data = this.getTableData();
|
||||
const headers = this.getHeaders();
|
||||
|
||||
if (this.showActionButtons()) {
|
||||
headers.push({ sTitle: '', sClass: 'center' });
|
||||
}
|
||||
|
||||
|
||||
if (this.showActionButtons()) {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
data[i].push(this.getActionButtonsHtml(data[i][0], data[i]));
|
||||
}
|
||||
}
|
||||
let html = '';
|
||||
html = `${this.getTableTopButtonHtml()}<div class="box-body table-responsive"><table cellpadding="0" cellspacing="0" border="0" class="table table-bordered table-striped" id="grid"></table></div>`;
|
||||
|
||||
// Find current page
|
||||
const activePage = $(`#${elementId} .dataTables_paginate .active a`).html();
|
||||
let start = 0;
|
||||
if (activePage !== undefined && activePage != null) {
|
||||
start = parseInt(activePage, 10) * 15 - 15;
|
||||
}
|
||||
|
||||
$(`#${elementId}`).html(html);
|
||||
|
||||
const dataTableParams = {
|
||||
oLanguage: {
|
||||
sLengthMenu: '_MENU_ records per page',
|
||||
},
|
||||
aaData: data,
|
||||
aoColumns: headers,
|
||||
bSort: false,
|
||||
iDisplayLength: 15,
|
||||
iDisplayStart: start,
|
||||
};
|
||||
|
||||
|
||||
const customTableParams = this.getCustomTableParams();
|
||||
|
||||
$.extend(dataTableParams, customTableParams);
|
||||
|
||||
$(`#${elementId} #grid`).dataTable(dataTableParams);
|
||||
|
||||
$('.dataTables_paginate ul').addClass('pagination');
|
||||
$('.dataTables_length').hide();
|
||||
$('.dataTables_filter input').addClass('form-control');
|
||||
$('.dataTables_filter input').attr('placeholder', 'Search');
|
||||
$('.dataTables_filter label').contents().filter(function () {
|
||||
return (this.nodeType === 3);
|
||||
}).remove();
|
||||
// $('.tableActionButton').tooltip();
|
||||
$(`#${elementId} #grid`).editableTableWidget();
|
||||
|
||||
$(`#${elementId} #grid .editcell`).on('validate', function (evt, newValue) {
|
||||
return modJs.validateCellValue($(this), evt, newValue);
|
||||
});
|
||||
|
||||
this.afterCreateTable(elementId);
|
||||
}
|
||||
|
||||
afterCreateTable(elementId) {
|
||||
|
||||
}
|
||||
|
||||
addCellDataUpdate(colId, rowId, data) {
|
||||
this.cellDataUpdates[`${colId}=${rowId}`] = [colId, rowId, data];
|
||||
}
|
||||
|
||||
addAdditionalRequestData(type, req) {
|
||||
return req;
|
||||
}
|
||||
|
||||
sendCellDataUpdates() {
|
||||
let req = this.cellDataUpdates;
|
||||
req.rowTable = this.rowTable;
|
||||
req.columnTable = this.columnTable;
|
||||
req.valueTable = this.valueTable;
|
||||
req = this.addAdditionalRequestData('updateData', req);
|
||||
const reqJson = JSON.stringify(req);
|
||||
|
||||
const callBackData = [];
|
||||
callBackData.callBackData = [];
|
||||
callBackData.callBackSuccess = 'updateDataSuccessCallBack';
|
||||
callBackData.callBackFail = 'updateDataFailCallBack';
|
||||
this.showLoader();
|
||||
this.customAction('updateData', this.modulePath, reqJson, callBackData);
|
||||
}
|
||||
|
||||
updateDataSuccessCallBack(callBackData, serverData) {
|
||||
this.hideLoader();
|
||||
modJs.cellDataUpdates = {};
|
||||
modJs.get();
|
||||
}
|
||||
|
||||
updateDataFailCallBack(callBackData, serverData) {
|
||||
this.hideLoader();
|
||||
}
|
||||
|
||||
sendAllCellDataUpdates() {
|
||||
let req = this.cellDataUpdates;
|
||||
req.rowTable = this.rowTable;
|
||||
req.columnTable = this.columnTable;
|
||||
req.valueTable = this.valueTable;
|
||||
req = this.addAdditionalRequestData('updateAllData', req);
|
||||
const reqJson = JSON.stringify(req);
|
||||
|
||||
const callBackData = [];
|
||||
callBackData.callBackData = [];
|
||||
callBackData.callBackSuccess = 'updateDataAllSuccessCallBack';
|
||||
callBackData.callBackFail = 'updateDataAllFailCallBack';
|
||||
this.showLoader();
|
||||
this.customAction('updateAllData', this.modulePath, reqJson, callBackData);
|
||||
}
|
||||
|
||||
updateDataAllSuccessCallBack(callBackData, serverData) {
|
||||
this.hideLoader();
|
||||
modJs.cellDataUpdates = {};
|
||||
modJs.getAllData(true);
|
||||
}
|
||||
|
||||
updateDataAllFailCallBack(callBackData, serverData) {
|
||||
this.hideLoader();
|
||||
}
|
||||
|
||||
showActionButtons() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default TableEditAdapter;
|
||||
Reference in New Issue
Block a user