| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- // @require variables:
- if ('undefined' === typeof TABLE_AJAX_NODE_ID) throw "Missing TABLE_AJAX_NODE_ID"; // $this->_htmlID,
- if ('undefined' === typeof TABLE_AJAX_LABEL) throw "Missing TABLE_AJAX_LABEL"; // this->getLabelHtml()
- if ('undefined' === typeof FUNCTION_EDIT_ROUTE) throw "Missing FUNCTION_EDIT_ROUTE";
- if ('undefined' === typeof URL_EDIT_FORM_AJAX) throw "Missing URL_EDIT_FORM_AJAX";
- function TableAjax__EDIT_Route(args) {
- var recordID = args;
- if (typeof args == 'object') {
- recordID = args.shift();
- recordID = parseInt(recordID);
- }
- if (typeof recordID !== 'number' || recordID <= 0) {
- // TODO: msg
- return false;
- }
- var cont = jQuery('#' + TABLE_AJAX_NODE_ID).parent();
- cont.hide();
- // remove previous task content
- var taskCnt = jQuery('#'+TABLE_AJAX_NODE_ID+'_task');
- taskCnt.parent().remove();
- taskCnt.remove();
- var taskCont = jQuery('<div class="AjaxTableCont"></div>').insertBefore(cont);
- jQuery('<ul class="breadcrumb">' +
- '<li><a href="#" onclick="return tableAjaxBackToTable();">' + TABLE_AJAX_LABEL + '</a></li>' +
- '<li class="active">Edytuj rekord</li>' +
- '</ul>').appendTo(taskCont);
- taskCnt = jQuery('<div id="' + TABLE_AJAX_NODE_ID + '_task" class="AjaxTableTaskCnt AjaxTable-loading"></div>').appendTo(taskCont);
- jQuery('<span class="loading-info"> loading ...</span>').appendTo(taskCnt);
- window.fetch(URL_EDIT_FORM_AJAX + recordID, {
- method: 'GET',
- credentials: 'same-origin',
- }).then(function(response) {
- return response.json()
- }).then(function __route_edit_payload(payload) {
- taskCnt.removeClass('AjaxTable-loading');
- // console.log('editFormJson :: payload', payload)
- if ('success' == payload.type) {
- var node = document.createElement('div')
- taskCnt.get(0).appendChild(node)
- p5UI__buildDom(payload.body.reactNode, node)
- initDateTimePicker(jQuery(node));
- // console.log('editFormJson :: dom loaded - TODO: add action on save - P5UI__FeatureEditForm')
- } else {
- console.log('editFormJson :: ERROR payload', payload)
- }
- }).catch(function __route_edit_catch(e) {
- taskCnt.removeClass('AjaxTable-loading');
- console.log('editFormJson :: ERROR', e)
- p5UI__notifyAjaxCallback({
- type: 'error',
- msg: 'Request error ' + e
- });
- })
- }
- global[FUNCTION_EDIT_ROUTE] = TableAjax__EDIT_Route
|