You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
360 lines
6.4 KiB
360 lines
6.4 KiB
4 years ago
|
var ModuleWorkDocs = {
|
||
|
|
||
|
initialized: false,
|
||
|
|
||
|
init: function () {
|
||
|
|
||
|
if (this.initialized)
|
||
|
return;
|
||
|
|
||
|
this.initialized = true;
|
||
|
},
|
||
|
|
||
|
|
||
|
index: function () {
|
||
|
this.addWork();
|
||
|
this.deleteBtn();
|
||
|
this.clearLogs();
|
||
|
},
|
||
|
|
||
|
|
||
|
edit: function () {
|
||
|
this.saveBtn();
|
||
|
this.MouseTrap();
|
||
|
},
|
||
|
|
||
|
|
||
|
run: function () {
|
||
|
this.btnStart();
|
||
|
this.btnStartNew();
|
||
|
},
|
||
|
|
||
|
|
||
|
log: function () {
|
||
|
this.clearLog();
|
||
|
this.ajaxTable();
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
MouseTrap: function () {
|
||
|
|
||
|
Mousetrap.bind(['ctrl+s', 'command+s'], function (event) {
|
||
|
|
||
|
if (event.preventDefault) {
|
||
|
event.preventDefault();
|
||
|
} else {
|
||
|
event.returnValue = false;
|
||
|
}
|
||
|
|
||
|
ModuleWorkDocs.saveWork();
|
||
|
|
||
|
return false;
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
addWork: function () {
|
||
|
$('#addNewForm').on('submit', function (event) {
|
||
|
event.preventDefault(false);
|
||
|
|
||
|
let form = this,
|
||
|
select = $('#rubric_id').val();
|
||
|
|
||
|
if (! select.length)
|
||
|
{
|
||
|
$.jGrowl(error_mesage_rubric_id, {
|
||
|
header: error_header_rubric_id,
|
||
|
theme: 'error'
|
||
|
});
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
form.submit();
|
||
|
|
||
|
return true;
|
||
|
});
|
||
|
},
|
||
|
|
||
|
//
|
||
|
saveWork: function () {
|
||
|
let form = $("#saveForm");
|
||
|
|
||
|
form.ajaxSubmit({
|
||
|
url: form.attr('action'),
|
||
|
dataType: 'JSON',
|
||
|
beforeSubmit: function () {
|
||
|
$.alerts._overlay('show');
|
||
|
},
|
||
|
success: function (data) {
|
||
|
$.alerts._overlay('hide');
|
||
|
|
||
|
$.jGrowl(data['message'], {
|
||
|
header: data['header'],
|
||
|
theme: data['theme']
|
||
|
});
|
||
|
|
||
|
if (data.work_id) {
|
||
|
$('#work_id').val(data.work_id);
|
||
|
$('.hideBtn').show();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
saveBtn: function () {
|
||
|
$('.SaveWork').on('click', function (event) {
|
||
|
event.preventDefault();
|
||
|
|
||
|
ModuleWorkDocs.saveWork();
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
deleteBtn: function () {
|
||
|
$('.Delete').on('click', function (event) {
|
||
|
event.preventDefault();
|
||
|
|
||
|
let href = $(this).attr('href');
|
||
|
|
||
|
jConfirm(
|
||
|
del_confirm,
|
||
|
del_title,
|
||
|
function (succes) {
|
||
|
if (succes) {
|
||
|
$.alerts._overlay('show');
|
||
|
window.location = href;
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
|
||
|
//
|
||
|
clearLogs: function () {
|
||
|
$('.clearLogs').on('click', function (event) {
|
||
|
event.preventDefault();
|
||
|
|
||
|
let href = $(this).attr('href');
|
||
|
|
||
|
jConfirm(
|
||
|
clear_confirm,
|
||
|
clear_title,
|
||
|
function (succes) {
|
||
|
if (succes) {
|
||
|
$.alerts._overlay('show');
|
||
|
|
||
|
$.ajax({
|
||
|
url: href,
|
||
|
type: 'POST',
|
||
|
dataType: "json",
|
||
|
success: function(data) {
|
||
|
$.alerts._overlay('hide');
|
||
|
$('.col-time').html('');
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
clearLog: function () {
|
||
|
$('.clearLog').on('click', function (event) {
|
||
|
event.preventDefault();
|
||
|
|
||
|
let href = $(this).attr('href');
|
||
|
|
||
|
jConfirm(
|
||
|
clear_confirm,
|
||
|
clear_title,
|
||
|
function (succes) {
|
||
|
if (succes) {
|
||
|
$.alerts._overlay('show');
|
||
|
|
||
|
$.ajax({
|
||
|
url: href,
|
||
|
type: 'POST',
|
||
|
dataType: "json",
|
||
|
success: function(data) {
|
||
|
$.alerts._overlay('hide');
|
||
|
logs.fnClearTable();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
btnStart: function () {
|
||
|
$('.btnStart').on('click', function(event) {
|
||
|
event.preventDefault(false);
|
||
|
|
||
|
$('#showLog').hide();
|
||
|
|
||
|
ModuleWorkDocs.startWork();
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
btnStartNew: function () {
|
||
|
$('.btnStartNew').on('click', function(event) {
|
||
|
event.preventDefault();
|
||
|
|
||
|
$('#showLog').hide();
|
||
|
$('#blockRun').hide();
|
||
|
$('#btnBlockNew').hide();
|
||
|
$('#btnBlockWork').show();
|
||
|
$('#blockContinue').show();
|
||
|
|
||
|
ModuleWorkDocs.startWork(true);
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
addRow: function (document) {
|
||
|
let doc =
|
||
|
'<tr>' +
|
||
|
'<td>' +
|
||
|
'<a href="index.php?do=docs&action=edit&rubric_id=' + document.rubric_id + '&Id=' + document.document_id + '&cp=' + sess + '" target="_blank">' + document.document_id + '</a>' +
|
||
|
'</td>' +
|
||
|
'<td>' +
|
||
|
'<a href="' + ave_path + document.document_alias + '" target="_blank">' + document.document_title + '</a>' +
|
||
|
'</td>' +
|
||
|
'<td>' +
|
||
|
'<small>' +
|
||
|
document.document_log +
|
||
|
'</small>' +
|
||
|
'</td>' +
|
||
|
'</tr>';
|
||
|
|
||
|
logTable.append(doc);
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
startWork: function (startnew = false) {
|
||
|
let check = $('#stepBlock').data('run');
|
||
|
|
||
|
let href = (check === 'file')
|
||
|
? '/modules/workdocs/stepone.php?cp=' + sess
|
||
|
: 'index.php?do=modules&action=modedit&mod=workdocs&cp=' + sess;
|
||
|
|
||
|
$.ajax({
|
||
|
url: href,
|
||
|
data: ({
|
||
|
'moduleaction':'step',
|
||
|
'rubric_id': runData.data('rubric-id'),
|
||
|
'work_id': runData.data('work-id'),
|
||
|
'limit': startnew ? 0 : limitSql
|
||
|
}),
|
||
|
dataType: 'JSON',
|
||
|
beforeSend: function() {
|
||
|
$('.btnStart').prop('disabled', true);
|
||
|
},
|
||
|
complete: function() {
|
||
|
//
|
||
|
},
|
||
|
success: function(data) {
|
||
|
if (data.success)
|
||
|
{
|
||
|
if (startnew) {
|
||
|
logTable.find('tbody').html('');
|
||
|
limitSql = 0;
|
||
|
}
|
||
|
|
||
|
limitSql = limitSql + 1;
|
||
|
|
||
|
$('#noRecords').hide();
|
||
|
|
||
|
if (allRecords > limitSql) {
|
||
|
$('#delay').removeClass('yellow');
|
||
|
|
||
|
if (! $('#delay').hasClass('green'))
|
||
|
$('#delay').addClass('green');
|
||
|
|
||
|
$('#delay').html('Doc: ' + data.document_title);
|
||
|
|
||
|
var percent = ModuleWorkDocs.getPercent(limitSql, allRecords);
|
||
|
|
||
|
readyRecords.html(limitSql);
|
||
|
|
||
|
progressbar.progressbar({value: percent});
|
||
|
|
||
|
procents.html(percent + '%');
|
||
|
|
||
|
NProgress.set(percent/100);
|
||
|
|
||
|
if (logTable)
|
||
|
ModuleWorkDocs.addRow(data);
|
||
|
|
||
|
ModuleWorkDocs.startWork();
|
||
|
}
|
||
|
else {
|
||
|
progressbar.progressbar({value: 100});
|
||
|
$('procents').html('100%');
|
||
|
readyRecords.html(allRecords);
|
||
|
$('#showLog').show();
|
||
|
$('.btnStart').prop('disabled', false);
|
||
|
$('#btnBlockWork').hide();
|
||
|
$('#btnBlockNew').show();
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
error: function (xhr, ajaxOptions, thrownError) {
|
||
|
$('.btnStart').prop('disabled', false);
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
getPercent: function (ready, count) {
|
||
|
return Math.round((ready / count) * 100);
|
||
|
},
|
||
|
|
||
|
|
||
|
//
|
||
|
ajaxTable: function () {
|
||
|
let logTable = $('#logsTable'),
|
||
|
work_id = logTable.data('work-id');
|
||
|
|
||
|
logs = logTable.dataTable({
|
||
|
"bJQueryUI": true,
|
||
|
'bAutoWidth': false,
|
||
|
'bProcessing': true,
|
||
|
'bServerSide': true,
|
||
|
'sPaginationType': "full_numbers",
|
||
|
'aaSorting': [[1,'asc']],
|
||
|
//"sDom": '<""f>rt<"F"lp>',
|
||
|
'iDisplayLength': 25,
|
||
|
'sAjaxSource': 'index.php?do=modules&action=modedit&mod=workdocs&moduleaction=json&work_id='+ work_id +'&cp=' + sess,
|
||
|
"oLanguage": {
|
||
|
"sLengthMenu": sLengthMenu,
|
||
|
"sZeroRecords": sZeroRecords,
|
||
|
"sInfo": sInfo,
|
||
|
"sInfoEmpty": sInfoEmpty,
|
||
|
"sInfoFiltered": sInfoFiltered
|
||
|
},
|
||
|
"stripeClasses": ['strip'],
|
||
|
"aoColumnDefs": [{
|
||
|
"sClass": "center",
|
||
|
"aTargets": [ 0,-2 ]
|
||
|
}]
|
||
|
});
|
||
|
}
|
||
|
};
|