| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- if (!RUN_ANT_JOB_URL) throw "Missing RUN_ANT_JOB_URL";
- if (!RUN_TEST_ANT_JOB_URL) throw "Missing RUN_TEST_ANT_JOB_URL";
- var DBG = (DBG) ? true : false;
- var DBG1 = true;
- function p5UI_runAntAsyncJob(event, targetNode, props) {
- event.stopPropagation();
- event.preventDefault();
- var props = props || {};
- var href = targetNode.getAttribute('href');
- var namespace = targetNode.getAttribute('data-namespace');
- var primaryKey = targetNode.getAttribute('data-primaryKey');
- var ant_path = targetNode.getAttribute('data-ant_path');
- var ant_template = targetNode.getAttribute('data-ant_template');
- DBG1 && console.log("DBG:p5UI_runAntAsyncJob ", { props_TEST: props.TEST ? true : false, targetNode, href, namespace, primaryKey, ant_path, ant_template })
- if (targetNode._isLoading) return;
- {
- targetNode._isLoading = true;
- var handleRemoveRefreshIcon = _addRefreshIcon(targetNode);
-
- var handleRemoveRefreshIcon = (function (targetNode) {
- return function () {
- if (targetNode._isLoading) {
- targetNode._isLoading = false;
- _removeRefreshIcon(targetNode);
- }
- }
- })(targetNode);
- // setTimeout(handleRemoveRefreshIcon, 1000);
- global.fetch(props.TEST ? RUN_TEST_ANT_JOB_URL : RUN_ANT_JOB_URL, {
- method: 'POST',
- header: {
- 'contentType': 'applications/json'
- },
- credentials: 'same-origin',
- body: JSON.stringify({
- namespace,
- primaryKey,
- ant_path,
- ant_template,
- })
- }).then(function (response) {
- handleRemoveRefreshIcon()
- return response.json()
- })
- .then(function (result) {
- DBG1 && console.log("DBG:response", { result })
- if (result.type && 'error' === result.type) return _handleResponseError(result);
- if (result.type && 'success' === result.type) return _handleResponseSuccess(result);
- _handleResponseError(result);
- });
- }
- return false;
- }
- function _handleResponseError(result) {
- p5UI__notifyAjaxCallback(result);
- }
- function _handleResponseSuccess(result) {
- p5UI__notifyAjaxCallback(result);
- }
- function _addRefreshIcon(targetNode) {
- var loadingNode = document.createElement('i');
- loadingNode.setAttribute('class', 'glyphicon glyphicon-refresh');
- loadingNode.style.marginLeft = "8px";
- loadingNode._p5Node = 'loading-icon';
- targetNode.appendChild(loadingNode);
- }
- function _removeRefreshIcon(targetNode) {
- var lastNode = targetNode.lastChild;
- if (!lastNode) return;
- DBG1 && console.log("DBG:_removeRefreshIcon", { targetNode, lastNode, lastNode_p5Node: lastNode._p5Node });
- if (!lastNode._p5Node) return;
- if ('loading-icon' != lastNode._p5Node) return;
- targetNode.removeChild(lastNode);
- }
- global.p5UI_runAntAsyncJob = p5UI_runAntAsyncJob;
|