| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- // @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('<tr></tr>');
- var fFun = CAN_WRITE_RECORD
- ? jQuery('<i class=\"glyphicon glyphicon-remove\" style=\"cursor:pointer; margin-right:2px\" data-filename=\"' + file.name + '\"></i>')
- : null
- ;
- var fNameCell = jQuery('<td style=\"overflow: hidden;\"></td>');
- var fName = jQuery('<div style=\"overflow:hidden; white-space:nowrap;\" title=\"' + file.name + '\"></div>');
- if (fFun) fName.append(fFun);
- fName.append(file.name);
- fName.appendTo(fNameCell);
- node.append(fNameCell);
- node.append('<td style=\"overflow:hidden; white-space:nowrap; text-align:center;\">' + '<a href=\"' + file.web + '\" target=\"_blank\" class=\"glyphicon glyphicon-download-alt\"></a>' + '</td>');
- if (SHARE_POINT) {
- node.append('<td style=\"overflow:hidden; white-space:nowrap; text-align:center;\">' + '<a href=\"' + SHARE_POINT + '/' + file.name + '\" target=\"_blank\" class=\"glyphicon glyphicon-folder-open\"></a>' + '</td>');
- }
- node.append('<td style=\"overflow:hidden; white-space:nowrap; text-align:right;\">' + file.sizeStr + '</td>');
- node.append('<td style=\"overflow:hidden; white-space:nowrap;\">' + file.created + '</td>');
- 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('<tr><td colspan=\"6\"><div class=\"alert alert-danger\">' + txt + '</div></td></tr>');
- 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('<tr></tr>');
- var fNameCell = jQuery('<td style=\"overflow: hidden;\"></td>');
- var fName = jQuery('<div style=\"overflow:hidden; white-space:nowrap;\" title=\"' + file.name + '\"></div>');
- fName.append(file.name);
- fName.appendTo(fNameCell);
- node.append(fNameCell);
- node.append('<td style=\"overflow:hidden; white-space:nowrap; text-align:center;\">' + '<a href=\"' + file.web + '\" target=\"_blank\" class=\"glyphicon glyphicon-download-alt\"></a>' + '</td>');
- node.append('<td style=\"overflow:hidden; white-space:nowrap; text-align:right;\">' + file.sizeStr + '</td>');
- node.append('<td style=\"overflow:hidden; white-space:nowrap;\">' + file.created + '</td>');
- node.appendTo(fileListNode);
- });
- }
- function fileListActions() { // FUNCTION_FILE_LIST_ACTIONS
- var filePermsReload = jQuery('#' + NODE_ID_FILES_LIST_ACTIONS);
- var btnReload = jQuery('<button class="btn-link btn-sm" title="odśwież uprawnienia do plików"><span class="glyphicon glyphicon-refresh"></span>Odśwież</button>');
- 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 = '<button type="button" class="close" data-dismiss="alert"><i class="glyphicon glyphicon-remove"></i></button>';
- if (typeof data == 'object') {
- if (data.type == 'error') {
- outJqNode.html('<div class="alert alert-danger">' + btnClose + data.msg + '</div>');
- } else if (data.type == 'SUCCESS') {
- outJqNode.html('<div class="alert alert-success">' + btnClose + data.msg + '</div>');
- fileListUpdateAjax();
- // TODO: scanFileListUpdateAjax...
- }
- } else {
- if (data.substr(0, 7) == 'WARNING') {
- data = data.substr(7);
- outJqNode.html('<div class="alert alert-warning">' + btnClose + data + '</div>');
- } else if (data.substr(0, 5) == 'error') {
- data = data.substr(5);
- outJqNode.html('<div class="alert alert-danger">' + btnClose + data + '</div>');
- } else if (data.substr(0, 7) == 'SUCCESS') {
- data = data.substr(7);
- outJqNode.html('<div class="alert alert-success">' + btnClose + data + '</div>');
- fileListUpdateAjax();
- // TODO: scanFileListUpdateAjax...
- } else if (data.substr(0, 4) == 'INFO') {
- data = data.substr(4);
- outJqNode.html('<div class="alert alert-info">' + btnClose + data + '</div>');
- }
- }
- }
- })
- fileListActions()
- var fileList = JSON_FILES
- fileListUpdate(fileList)
- var connTbls = CONN_TABLES
- if (connTbls) {
- var connTblsOut = '';
- for(var key in connTbls) {
- connTblsOut += '<button class="btn btn-sm btn-default conn-tbl-load" data-zasobid="' + key + '">' + connTbls[key] + '</button>';
- };
- if (connTblsOut) {
- connTblsOut = 'Pliki w powiązanych tabelach: <div class="btn-group">' + connTblsOut + '</div>';
- connTblsOut += '<div style="max-height:180px; overflow:auto; border-bottom:1px solid #ddd;">' +
- '<table class="table table-bordered table-hover">' +
- '<colgroup>' +
- '<col style="">' +
- '<col style="width:30px;">' +
- ( (SHARE_POINT) ? '<col style="width:30px;">' : '' ) +
- '<col style="width:80px;">' +
- '<col style="width:140px;">' +
- '</colgroup>' +
- '<tbody class="files-list">' +
- '</tbody>' +
- '</table>' +
- '</div>';
- 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 = '<div class="progress">' +
- '<div class="progress-bar" role="progressbar" aria-valuenow="' + intPercent + '" aria-valuemin="0" aria-valuemax="100" style="width: ' + intPercent + '%;">' +
- intPercent + '%' +
- '</div>' +
- '</div>'
- } 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
|