mirror of
https://github.com/danpros/htmly.git
synced 2026-04-18 19:46:21 +05:30
Refactor autosave draft script and add error handling
This commit is contained in:
parent
908c3d0789
commit
a0b8059647
3 changed files with 34 additions and 35 deletions
|
|
@ -182,3 +182,7 @@ pre code {
|
|||
align-items: center;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.notice.error {
|
||||
background-color: #fdd;
|
||||
}
|
||||
|
|
@ -145,6 +145,7 @@ $( function() {
|
|||
<?php if (isset($error)) { ?>
|
||||
<div class="error-message"><?php echo $error ?></div>
|
||||
<?php } ?>
|
||||
<div class="notice error" id="response-error"></div>
|
||||
<div class="notice" id="response"></div>
|
||||
<div class="row">
|
||||
<div class="hide-button" style="margin-bottom:1em;width:100%;text-align:right;"><button type="button" title="<?php echo i18n('Focus_mode');?>" id="hideButton" class="note-btn btn btn-sm <?php echo ((config('admin.theme') === 'light' || is_null(config('admin.theme'))) ? "btn-light" : "btn-dark");?>" style="width:38px;height:38px;font-size:18px;" ><i class="fa fa-eye" aria-hidden="true"></i></button></div>
|
||||
|
|
|
|||
|
|
@ -1,42 +1,28 @@
|
|||
const response = document.getElementById("response");
|
||||
function hideError() {
|
||||
$("#response-error").fadeOut(600, function() {
|
||||
$("#response-error").css("display", "none");
|
||||
});
|
||||
}
|
||||
|
||||
function updateData() {
|
||||
var title = $("#pTitle").val();
|
||||
var url = $("#pURL").val();
|
||||
var content = $("#wmd-input").val();
|
||||
var description = $("#pMeta").val();
|
||||
var tag = $("#pTag").val();
|
||||
var category = $("#pCategory").val();
|
||||
var posttype = $("#pType").val();
|
||||
var pimage = $("#pImage").val();
|
||||
var paudio = $("#pAudio").val();
|
||||
var pvideo = $("#pVideo").val();
|
||||
var pquote = $("#pQuote").val();
|
||||
var plink = $("#pLink").val();
|
||||
var pDate = $("#pDate").val();
|
||||
var pTime = $("#pTime").val();
|
||||
var oldfile = $("#oldfile").val();
|
||||
var dateTime = pDate + " " + pTime;
|
||||
var autoSave = 'autoSave';
|
||||
|
||||
// Prepare data to send to PHP
|
||||
var data = {
|
||||
title: title,
|
||||
url: url,
|
||||
content: content,
|
||||
description: description,
|
||||
tag: tag,
|
||||
category: category,
|
||||
posttype: posttype,
|
||||
pimage: pimage,
|
||||
paudio: paudio,
|
||||
pvideo: pvideo,
|
||||
pquote: pquote,
|
||||
plink: plink,
|
||||
dateTime: dateTime,
|
||||
autoSave: autoSave,
|
||||
title: $("#pTitle").val(),
|
||||
url: $("#pURL").val(),
|
||||
content: $("#wmd-input").val(),
|
||||
description: $("#pMeta").val(),
|
||||
tag: $("#pTag").val(),
|
||||
category: $("#pCategory").val(),
|
||||
posttype: $("#pType").val(),
|
||||
pimage: $("#pImage").val(),
|
||||
paudio: $("#pAudio").val(),
|
||||
pvideo: $("#pVideo").val(),
|
||||
pquote: $("#pQuote").val(),
|
||||
plink: $("#pLink").val(),
|
||||
dateTime: $("#pDate").val() + " " + $("#pTime").val(),
|
||||
autoSave: 'autoSave',
|
||||
addEdit: addEdit,
|
||||
oldfile: oldfile,
|
||||
oldfile: $("#oldfile").val(),
|
||||
parent_page: parent_page
|
||||
};
|
||||
|
||||
|
|
@ -47,6 +33,7 @@ function updateData() {
|
|||
success: function(response) {
|
||||
$("#response").html(response.message);
|
||||
$("#oldfile").val(response.file);
|
||||
hideError();
|
||||
$("#response").fadeIn(600, function() {
|
||||
$("#response").css("display", "block");
|
||||
});
|
||||
|
|
@ -55,6 +42,13 @@ function updateData() {
|
|||
$("#response").css("display", "none");
|
||||
});
|
||||
}, 6000);
|
||||
},
|
||||
error: function(response) {
|
||||
$("#response-error").html("Error in Autosaving: " + response.statusText);
|
||||
$("#response-error").fadeIn(600, function() {
|
||||
$("#response-error").css("display", "block");
|
||||
});
|
||||
setTimeout(hideError, saveInterval/2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue