Cleanup, split export and download functions in snapshot.

pull/3335/head
Isaac Connor 2021-08-06 19:18:02 -04:00
parent 672de6e84f
commit f0b2f75d91
3 changed files with 46 additions and 43 deletions

View File

@ -1,6 +1,3 @@
var backBtn = $j('#backBtn');
var saveBtn = $j('#saveBtn');
var deleteBtn = $j('#deleteBtn');
// Manage the DELETE CONFIRMATION modal button // Manage the DELETE CONFIRMATION modal button
function manageDelConfirmModalBtns() { function manageDelConfirmModalBtns() {
@ -26,28 +23,27 @@ function manageDelConfirmModalBtns() {
}); });
} }
function exportResponse(respObj, respText) { function downloadResponse(respObj, respText) {
clearInterval(exportTimer); clearInterval(downloadTimer);
if ( respObj.result != 'Ok' ) { if (respObj.result != 'Ok' ) {
$j('#exportProgressTicker').text(respObj.message); $j('#downloadProgressTicker').text(respObj.message);
} else { } else {
$j('#exportProgressTicker').text(exportSucceededString); $j('#downloadProgressTicker').text(downloadSucceededString);
setTimeout(startDownload, 1500, decodeURIComponent(respObj.exportFile)); setTimeout(startDownload, 1500, decodeURIComponent(respObj.exportFile));
} }
return; return;
} }
function startDownload(file) { function startDownload(file) {
console.log('Starting download of ' + file);
window.location.replace(file); window.location.replace(file);
} }
function exportProgress() { function downloadProgress() {
if ( exportTimer ) { if (downloadTimer) {
var tickerText = $j('#exportProgressTicker').text(); var tickerText = $j('#downloadProgressTicker').text();
if ( tickerText.length < 1 || tickerText.length > 4 ) { if (tickerText.length < 1 || tickerText.length > 4) {
$j('#exportProgressTicker').text('.'); $j('#downloadProgressTicker').text('.');
} else { } else {
$j('#exportProgressTicker').append('.'); $j('#downloadProgressTicker').append('.');
} }
} }
} }
@ -59,14 +55,9 @@ function initPage() {
archiveBtn.prop('disabled', !(!eventData.Archived && canEdit.Events)); archiveBtn.prop('disabled', !(!eventData.Archived && canEdit.Events));
unarchiveBtn.prop('disabled', !(eventData.Archived && canEdit.Events)); unarchiveBtn.prop('disabled', !(eventData.Archived && canEdit.Events));
*/ */
saveBtn.prop('disabled', !(canEdit.Events || (snapshot.CreatedBy == user.Id) ));
/*
downloadBtn.prop('disabled', !canView.Events);
*/
deleteBtn.prop('disabled', !canEdit.Events);
// Don't enable the back button if there is no previous zm page to go back to // Don't enable the back button if there is no previous zm page to go back to
backBtn.prop('disabled', !document.referrer.length); $j('#backBtn').prop('disabled', !document.referrer.length);
// Manage the BACK button // Manage the BACK button
bindButton('#backBtn', 'click', null, function onBackClick(evt) { bindButton('#backBtn', 'click', null, function onBackClick(evt) {
@ -81,6 +72,7 @@ function initPage() {
}); });
// Manage the EDIT button // Manage the EDIT button
$j('#saveBtn').prop('disabled', !(canEdit.Events || (snapshot.CreatedBy == user.Id) ));
bindButton('#saveBtn', 'click', null, function onSaveClick(evt) { bindButton('#saveBtn', 'click', null, function onSaveClick(evt) {
/* /*
if ( ! canEdit.Events ) { if ( ! canEdit.Events ) {
@ -92,7 +84,8 @@ function initPage() {
}); });
// Manage the EXPORT button // Manage the EXPORT button
bindButton('#exportBtn', 'click', null, function onExportClick(evt) { $j('#downloadBtn').prop('disabled', !canView.Events);
bindButton('#downloadBtn', 'click', null, function onDownloadClick(evt) {
evt.preventDefault(); evt.preventDefault();
formData = { formData = {
eids: snapshot.EventIds, eids: snapshot.EventIds,
@ -107,17 +100,21 @@ function initPage() {
exportFile: 'Snapshot'+snapshot.Id exportFile: 'Snapshot'+snapshot.Id
}; };
$j.getJSON(thisUrl + '?view=event&request=event&action=export', formData) $j.getJSON(thisUrl + '?view=event&request=event&action=export', formData)
.done(exportResponse) .done(downloadResponse)
.fail(logAjaxFail); .fail(logAjaxFail);
$j('#exportProgress').removeClass('hidden'); $j('#downloadProgress').removeClass('hidden');
$j('#exportProgress').addClass('warnText'); $j('#downloadProgress').addClass('warnText');
$j('#exportProgress').text(exportProgressString); $j('#downloadProgress').text(downloadProgressString);
//exportProgress(); downloadTimer = setInterval(downloadProgress, 500);
exportTimer = setInterval(exportProgress, 500); });
//window.location.assign('?view=export&eids[]='+snapshot.EventIds.join('&eids[]=')); $j('#exportBtn').prop('disabled', !canView.Events);
bindButton('#exportBtn', 'click', null, function onExportClick(evt) {
console.log('export clicked');
evt.preventDefault();
window.location.assign('?view=export&eids[]='+snapshot.EventIds.join('&eids[]='));
}); });
/* /*
@ -135,6 +132,7 @@ function initPage() {
}); });
*/ */
// Manage the DELETE button // Manage the DELETE button
$j('#deleteBtn').prop('disabled', !canEdit.Events);
bindButton('#deleteBtn', 'click', null, function onDeleteClick(evt) { bindButton('#deleteBtn', 'click', null, function onDeleteClick(evt) {
if ( !canEdit.Events ) { if ( !canEdit.Events ) {
enoperm(); enoperm();

View File

@ -26,5 +26,9 @@ var eventDataStrings = {
// //
var deleteString = "<?php echo validJsStr(translate('Delete')) ?>"; var deleteString = "<?php echo validJsStr(translate('Delete')) ?>";
var causeString = "<?php echo validJsStr(translate('AttrCause')) ?>"; var causeString = "<?php echo validJsStr(translate('AttrCause')) ?>";
var downloadProgressString = "<?php echo validJsStr(translate('Downloading')) ?>";
var downloadFailedString = '<?php echo translate('Download Failed') ?>';
var downloadSucceededString = '<?php echo translate('Download Succeeded') ?>';
var WEB_LIST_THUMB_WIDTH = '<?php echo ZM_WEB_LIST_THUMB_WIDTH ?>'; var WEB_LIST_THUMB_WIDTH = '<?php echo ZM_WEB_LIST_THUMB_WIDTH ?>';
var WEB_LIST_THUMB_HEIGHT = '<?php echo ZM_WEB_LIST_THUMB_HEIGHT ?>'; var WEB_LIST_THUMB_HEIGHT = '<?php echo ZM_WEB_LIST_THUMB_HEIGHT ?>';

View File

@ -60,6 +60,7 @@ if ( !$snapshot->Id() ) {
--> -->
<button id="saveBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Save') ?>"><i class="fa fa-save"></i></button> <button id="saveBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Save') ?>"><i class="fa fa-save"></i></button>
<button id="exportBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Export') ?>"><i class="fa fa-external-link"></i></button> <button id="exportBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Export') ?>"><i class="fa fa-external-link"></i></button>
<button id="downloadBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Download') ?>" disabled><i class="fa fa-download"></i></button>
<button id="deleteBtn" class="btn btn-danger" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Delete') ?>"><i class="fa fa-trash"></i></button> <button id="deleteBtn" class="btn btn-danger" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Delete') ?>"><i class="fa fa-trash"></i></button>
<?php } // end if snapshot->Id ?> <?php } // end if snapshot->Id ?>
</div> </div>
@ -94,8 +95,8 @@ if ( !$snapshot->Id() ) {
?> ?>
</div><!--content--> </div><!--content-->
<?php } // end if snapshot->Id() ?> <?php } // end if snapshot->Id() ?>
</form> </form>
<h2 id="exportProgress" class="<?php <h2 id="downloadProgress" class="<?php
if ( isset($_REQUEST['generated']) ) { if ( isset($_REQUEST['generated']) ) {
if ( $_REQUEST['generated'] ) if ( $_REQUEST['generated'] )
echo 'infoText'; echo 'infoText';
@ -105,16 +106,16 @@ if ( !$snapshot->Id() ) {
echo 'hidden warnText'; echo 'hidden warnText';
} }
?>"> ?>">
<span id="exportProgressText"> <span id="downloadProgressText">
<?php <?php
if ( isset($_REQUEST['generated']) ) { if ( isset($_REQUEST['generated']) ) {
if ( $_REQUEST['generated'] ) if ( $_REQUEST['generated'] )
echo translate('ExportSucceeded'); echo translate('Download Succeeded');
else else
echo translate('ExportFailed'); echo translate('Download Failed');
} }
?></span> ?></span>
<span id="exportProgressTicker"></span> <span id="downloadProgressTicker"></span>
</h2> </h2>
</div><!--page--> </div><!--page-->
<?php xhtmlFooter() ?> <?php xhtmlFooter() ?>