// @require variables:
if ('undefined' === typeof UNIQ_HASH) throw "Missing UNIQ_HASH"; // $this->_htmlID,
if ('undefined' === typeof FUNCTION_FILE_LIST_UPDATE_AJAX) throw "Missing FUNCTION_FILE_LIST_UPDATE_AJAX"; // "fileListUpdateAjax{$this->_htmlID}", // fileListUpdateAjax
if ('undefined' === typeof FUNCTION_FILE_LIST_UPDATE) throw "Missing FUNCTION_FILE_LIST_UPDATE"; // "fileListUpdate{$this->_htmlID}", // fileListUpdate
if ('undefined' === typeof FUNCTION_CONN_TBL_LIST_UPDATE_AJAX) throw "Missing FUNCTION_CONN_TBL_LIST_UPDATE_AJAX"; // "connTblListUpdateAjax{$this->_htmlID}", // connTblListUpdateAjax
if ('undefined' === typeof FUNCTION_CONN_TBL_LIST_UPDATE) throw "Missing FUNCTION_CONN_TBL_LIST_UPDATE"; // "connTblListUpdate{$this->_htmlID}", // connTblListUpdate
if ('undefined' === typeof FUNCTION_FILE_LIST_ACTIONS) throw "Missing FUNCTION_FILE_LIST_ACTIONS"; // "fileListActions{$this->_htmlID}", // fileListActions
if ('undefined' === typeof CONN_TABLES) throw "Missing CONN_TABLES"; // $this->getConnectedTables(),
if ('undefined' === typeof NODE_ID_FILES_FRM) throw "Missing NODE_ID_FILES_FRM"; // "FILES_FRM_{$this->_htmlID}",
if ('undefined' === typeof NODE_ID_FRM_UPLOAD_RESULTS) throw "Missing NODE_ID_FRM_UPLOAD_RESULTS"; // "FRM_UPLOAD_RESULTS_{$this->_htmlID}",
if ('undefined' === typeof NODE_ID_FILES_TAB) throw "Missing NODE_ID_FILES_TAB"; // "FILES_TAB_{$this->_htmlID}",
if ('undefined' === typeof NODE_ID_FILES_LIST) throw "Missing NODE_ID_FILES_LIST"; // "FILES_LIST_{$this->_htmlID}",
if ('undefined' === typeof NODE_ID_FILES_CONN_TBLS) throw "Missing NODE_ID_FILES_CONN_TBLS"; // "FILES_CONN_TBLS_{$this->_htmlID}",
if ('undefined' === typeof NODE_ID_FILES_LIST_ACTIONS) throw "Missing NODE_ID_FILES_LIST_ACTIONS"; // "FILES_LIST_ACTIONS_{$this->_htmlID}",
if ('undefined' === typeof NODE_ID_FILES_MULTIPLE_UPLOAD) throw "Missing NODE_ID_FILES_MULTIPLE_UPLOAD"; // "FILES_MULTIPLE_UPLOAD_{$this->_htmlID}",
if ('undefined' === typeof URL_FILE_LIST_UPDATE_AJAX) throw "Missing URL_FILE_LIST_UPDATE_AJAX";
if ('undefined' === typeof URL_FILE_REMOVE_AJAX) throw "Missing URL_FILE_REMOVE_AJAX";
if ('undefined' === typeof URL_CONNECTED_TABLE_LIST) throw "Missing URL_CONNECTED_TABLE_LIST";
if ('undefined' === typeof URL_FILE_PERMS_REFRESH) throw "Missing URL_FILE_PERMS_REFRESH";
if ('undefined' === typeof URL_FILE_UPLOAD) throw "Missing URL_FILE_UPLOAD";
if ('undefined' === typeof CAN_WRITE_RECORD) throw "Missing CAN_WRITE_RECORD";
if ('undefined' === typeof SHARE_POINT) throw "Missing SHARE_POINT";
if ('undefined' === typeof JSON_FILES) throw "Missing JSON_FILES";
function fileListUpdateAjax() { // FUNCTION_FILE_LIST_UPDATE_AJAX
var postData = {};
jQuery.ajax({
url: URL_FILE_LIST_UPDATE_AJAX,
type: 'POST',
data: postData,
success: function(data) {
fileListUpdate(data);
},
error: function(jhr, textStatus, errorThrown) {
console.log('request error: ', errorThrown, ' textStatus: ', textStatus);
}
});
}
function fileListUpdate(fileListJson) { // FUNCTION_FILE_LIST_UPDATE
var fileListNode = jQuery('#' + NODE_ID_FILES_LIST);
fileListNode.empty();
fileListJson.map(function(file){
var node = jQuery('
');
var fFun = CAN_WRITE_RECORD
? jQuery('')
: null
;
var fNameCell = jQuery(' | ');
var fName = jQuery('');
if (fFun) fName.append(fFun);
fName.append(file.name);
fName.appendTo(fNameCell);
node.append(fNameCell);
node.append('' + '' + ' | ');
if (SHARE_POINT) {
node.append('' + '' + ' | ');
}
node.append('' + file.sizeStr + ' | ');
node.append('' + file.created + ' | ');
node.appendTo(fileListNode);
if (fFun) {
jQuery(fFun).click(function(e){
var n = jQuery(e.target);
var fname= n.data('filename');
if (!fname) {
return false;
}
if (confirm('Czy jesteś pewien, że chcesz usunąć plik o nazwie ' + fname + '?')) {
var postData = new FormData()
postData.append('filename', fname)
window.fetch(URL_FILE_REMOVE_AJAX, {
method: 'POST',
body: postData,
credentials: 'same-origin',
}).then(function (response) {
return response.json()
}).then(function (response) {
p5UI__notifyAjaxCallback(response)
fileListUpdateAjax()
}).catch(function (e) {
p5UI__notifyAjaxCallback({ type: 'error', msg: e })
console.warn(e)
fileListUpdateAjax()
})
}
});
}
});
}
function connTblListUpdateAjax(connTblID) { // FUNCTION_CONN_TBL_LIST_UPDATE_AJAX
var postData = {};
// clear current file list
jQuery('#' + NODE_ID_FILES_CONN_TBLS).find('.files-list').empty();
jQuery.ajax({
url: URL_CONNECTED_TABLE_LIST + '&connTblID=' + connTblID,
type: 'POST',
data: postData,
success: function(data) {
connTblListUpdate(data);
},
error: function(jqXHR, textStatus, errorThrown) {
var txt = jqXHR.responseText || 'Error';
jQuery('#' + NODE_ID_FILES_CONN_TBLS).find('.files-list').html('' + txt + ' |
');
if (priv.options.debug) console.log('connTblListUpdateAjax error: ', errorThrown, ' textStatus: ', textStatus);
}
});
}
function connTblListUpdate(fileListJson) { // FUNCTION_CONN_TBL_LIST_UPDATE
var fileListNode = jQuery('#' + NODE_ID_FILES_CONN_TBLS).find('.files-list');
fileListNode.empty();
fileListJson.map(function(file){
var node = jQuery('
');
var fNameCell = jQuery(' | ');
var fName = jQuery('');
fName.append(file.name);
fName.appendTo(fNameCell);
node.append(fNameCell);
node.append('' + '' + ' | ');
node.append('' + file.sizeStr + ' | ');
node.append('' + file.created + ' | ');
node.appendTo(fileListNode);
});
}
function fileListActions() { // FUNCTION_FILE_LIST_ACTIONS
var filePermsReload = jQuery('#' + NODE_ID_FILES_LIST_ACTIONS);
var btnReload = jQuery('');
btnReload.on('click', function(e) {
//console.log('TODO: click reload perms...');
function notifyAjaxCallback(data) {
var notify = {};
notify.type = (data && data.type)? data.type : '';
notify.msg = (data && data.msg)? data.msg : '';
switch (notify.type) {
case 'success':
if (!notify.msg) notify.msg = 'OK';
break;
case 'info':
if (!notify.msg) notify.msg = '';
break;
case 'error':
if (!notify.msg) notify.msg = 'Wystąpiły błędy';
break;
case 'warning':
notify.type = 'warn';
if (!notify.msg) notify.msg = 'Wystąpiły błędy';
break;
default:
notify.msg = 'Nieznany błąd';
if (data && data.errorCode) notify.msg += ' ' + data.errorCode;
notify.type = '';
}
jQuery.notify(notify.msg, notify.type);
}
var reqData = {};
jQuery.ajax({
data: reqData,
dataType: 'json',
type: "GET",
url: URL_FILE_PERMS_REFRESH,
})
.done(function(data, textStatus, jqXHR){
notifyAjaxCallback(data);
if (data && data.files) {
fileListUpdate(data.files);
}
})
.fail(function(jqXHR){// jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
if (jqXHR.responseJSON) {
notifyAjaxCallback(jqXHR.responseJSON);
}
else {
var txt = jqXHR.responseText || 'Wystąpiły błędy';
if (jqXHR.status == 404) {
jQuery.notify(jqXHR.responseText, 'error');
} else {
jQuery.notify(jqXHR.responseText, 'warn');
}
}
});
});
filePermsReload.append(btnReload);
}
jQuery(document).ready(function(){
jQuery('#' + NODE_ID_FILES_TAB + ' a').click(function(e) {
e.preventDefault();
jQuery(this).tab('show');
})
.on('shown.bs.tab', function(e) {
var fileSource = jQuery(e.target).data('toggle')
, frm = jQuery('#' + NODE_ID_FILES_FRM).get(0);
if (frm['M_DIST_UPLOAD_SOURCE']) {
frm['M_DIST_UPLOAD_SOURCE'].value = fileSource;
}
})
jQuery('#' + NODE_ID_FILES_FRM).ajaxForm({
url: URL_FILE_UPLOAD,
beforeSubmit: function(args, $form, options) {
//console.log('#' + NODE_ID_FILES_FRM + '.ajaxForm->beforeSubmit()...');
var argsMap = [];
args.map(function(v, k) {
argsMap[v.name] = v.value;
});
// validate
if (argsMap['M_DIST_UPLOAD_SOURCE'] == 'local') {
if (!argsMap['M_DIST_FILES_NAME']) {
//console.log('#' + NODE_ID_FILES_FRM+'.ajaxForm->beforeSubmit() M_DIST_UPLOAD_SOURCE=local && !M_DIST_FILES_NAME');
return false;
}
}
else if (argsMap['M_DIST_UPLOAD_SOURCE'] == 'scan') {
if (!argsMap['SCANS_COLUMN_ADD']) {
//console.log('#' + NODE_ID_FILES_FRM+'.ajaxForm->beforeSubmit() M_DIST_UPLOAD_SOURCE=scan && !SCANS_COLUMN_ADD');
return false;
}
}
else {
return false;
}
jQuery('#' + NODE_ID_FRM_UPLOAD_RESULTS).html('Wysyłanie...');
},
success: function(data) {
//console.log('#' + NODE_ID_FILES_FRM+'.ajaxForm->success()...');
var outJqNode = jQuery('#' + NODE_ID_FRM_UPLOAD_RESULTS);
var btnClose = '';
if (typeof data == 'object') {
if (data.type == 'error') {
outJqNode.html('' + btnClose + data.msg + '
');
} else if (data.type == 'SUCCESS') {
outJqNode.html('' + btnClose + data.msg + '
');
fileListUpdateAjax();
// TODO: scanFileListUpdateAjax...
}
} else {
if (data.substr(0, 7) == 'WARNING') {
data = data.substr(7);
outJqNode.html('' + btnClose + data + '
');
} else if (data.substr(0, 5) == 'error') {
data = data.substr(5);
outJqNode.html('' + btnClose + data + '
');
} else if (data.substr(0, 7) == 'SUCCESS') {
data = data.substr(7);
outJqNode.html('' + btnClose + data + '
');
fileListUpdateAjax();
// TODO: scanFileListUpdateAjax...
} else if (data.substr(0, 4) == 'INFO') {
data = data.substr(4);
outJqNode.html('' + btnClose + data + '
');
}
}
}
})
fileListActions()
var fileList = JSON_FILES
fileListUpdate(fileList)
var connTbls = CONN_TABLES
if (connTbls) {
var connTblsOut = '';
for(var key in connTbls) {
connTblsOut += '';
};
if (connTblsOut) {
connTblsOut = 'Pliki w powiązanych tabelach: ' + connTblsOut + '
';
connTblsOut += '' +
'
' +
'' +
'' +
'' +
( (SHARE_POINT) ? '' : '' ) +
'' +
'' +
'' +
'' +
'' +
'
' +
'
';
var _connTblsWrap = jQuery('#' + NODE_ID_FILES_CONN_TBLS);
_connTblsWrap.css('marginBottom', '26px');
_connTblsWrap.html(connTblsOut);
_connTblsWrap.find('.conn-tbl-load').each(function(){
jQuery(this).click(function(e){
var tblID = jQuery(e.target).data('zasobid');
if (tblID) {
connTblListUpdateAjax(tblID);
}// TODO: else show error
});
});
}
}
initDateTimePicker(jQuery('#' + NODE_ID_FILES_FRM));
});
function p5TAFiles_onDropMultiple(event, targetNode, pk, ns) {
event.preventDefault()
targetNode.style.backgroundColor = '#eee'
var files = p5Utils__getFilesFromDropEvent(event)
if (!files) {
p5UI__notifyAjaxCallback({
type: 'info',
msg: 'brak plików',
})
return false
}
try {
var initialContent = (NODE_ID_FILES_MULTIPLE_UPLOAD)
? document.getElementById(NODE_ID_FILES_MULTIPLE_UPLOAD).innerHTML
: ''
;
p5TA_uploadWithProgress(files, ns, pk, {
onProgress: function (loadedPercent) {
var intPercent = Math.floor(loadedPercent)
if (NODE_ID_FILES_MULTIPLE_UPLOAD) {
document.getElementById(NODE_ID_FILES_MULTIPLE_UPLOAD).innerHTML = '' +
'
' +
intPercent + '%' +
'
' +
'
'
} else {
p5UI__notifyAjaxCallback({ type: 'info', msg: 'wgrano ' + intPercent + '%' })
}
},
onLoad: function (response) {
if (NODE_ID_FILES_MULTIPLE_UPLOAD) {
document.getElementById(NODE_ID_FILES_MULTIPLE_UPLOAD).innerHTML = initialContent
}
try {
var respJson = JSON.parse(response)
} catch (e) {
p5UI__notifyAjaxCallback({ type: 'error', msg: 'Wystąpił błąd podczas wgrywania plików' })
return false
}
if (respJson && respJson.type && respJson.msg) {
p5UI__notifyAjaxCallback(respJson)
}
fileListUpdateAjax()
},
onError: function (e) {
p5UI__notifyAjaxCallback({ type: 'error', msg: e })
console.warn('error', e)
}
})
} catch (e) {
console.warn(e)
}
}
function p5TAFiles_onDragOverMultiple(event, targetNode) { // 'ondragover' => "p5TAFiles_onDragOverMultiple", // "event.preventDefault(); this.style.backgroundColor='#D9EDF7'",
event.preventDefault()
targetNode.style.backgroundColor = '#D9EDF7'
}
function p5TAFiles_onDragLeaveMultiple(event, targetNode) { // 'ondragleave' => "p5TAFiles_onDragLeaveMultiple", // "event.preventDefault(); this.style.backgroundColor='#eee'",
event.preventDefault()
targetNode.style.backgroundColor = '#eee'
}
function p5TAFiles_onDragEndMultiple(event, targetNode) { // 'ondragend' => "p5TAFiles_onDragEndMultiple", // "event.preventDefault(); this.style.backgroundColor='#eee'",
event.preventDefault()
targetNode.style.backgroundColor = '#eee'
}
global[FUNCTION_FILE_LIST_UPDATE_AJAX] = fileListUpdateAjax
global[FUNCTION_FILE_LIST_UPDATE] = fileListUpdate
global[FUNCTION_CONN_TBL_LIST_UPDATE_AJAX] = connTblListUpdateAjax
global[FUNCTION_CONN_TBL_LIST_UPDATE] = connTblListUpdate
global[FUNCTION_FILE_LIST_ACTIONS] = fileListActions
global['p5TAFiles_onDropMultiple'] = p5TAFiles_onDropMultiple
global['p5TAFiles_onDragOverMultiple'] = p5TAFiles_onDragOverMultiple
global['p5TAFiles_onDragLeaveMultiple'] = p5TAFiles_onDragLeaveMultiple
global['p5TAFiles_onDragEndMultiple'] = p5TAFiles_onDragEndMultiple