Fix autosave #789

Track last saved draft than compare the new filename against the old filename when saving.
This commit is contained in:
danpros 2024-10-10 12:09:36 +07:00
commit 9beafa63bb
7 changed files with 59 additions and 31 deletions

View file

@ -172,6 +172,7 @@ $( function() {
<?php if ($type == 'is_post'):?>
<input type="hidden" name="is_post" value="is_post">
<?php endif;?>
<input id="oldfile" type="hidden" name="oldfile" class="text"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
</div>
</div>
@ -300,7 +301,6 @@ $( function() {
var base_path = '<?php echo site_url() ?>';
var initial_image = '<?php echo $images;?>';
var parent_page = '';
var oldfile = '';
var addEdit = 'add';
var saveInterval = 60000;
</script>
@ -341,7 +341,7 @@ $('.img-container').on("click", ".the-img", function(e) {
document.getElementById('hideButton').addEventListener('click', toggleDivs);
</script>
<?php if (config('autosave.enable') == 'true' ):?>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js"></script>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js?v=1"></script>
<?php endif;?>
<script>
if (localStorage.getItem("preview-state") === "open") {

View file

@ -46,6 +46,7 @@
<textarea id="wmd-input" class="form-control wmd-input <?php if (isset($postContent)) {if (empty($postContent)) {echo 'error';}} ?>" name="content" cols="20" rows="10"><?php if (isset($postContent)) {echo $postContent;} ?></textarea>
<br>
<input type="hidden" id="pType" name="posttype" value="<?php echo $type; ?>">
<input id="oldfile" type="hidden" name="oldfile" class="text"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
<?php if ($type == 'is_page' || $type == 'is_subpage') :?>
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Publish');?>"/> <input type="submit" name="draft" class="btn btn-primary draft" value="<?php echo i18n('Save_as_draft');?>"/>
@ -126,7 +127,6 @@
var base_path = '<?php echo site_url() ?>';
var initial_image = '<?php echo $images;?>';
var parent_page = '<?php echo isset($parent) ? $parent : '';?>';
var oldfile = '';
var addEdit = 'add';
var saveInterval = 60000;
</script>
@ -167,7 +167,7 @@ $('.img-container').on("click", ".the-img", function(e) {
</script>
<?php if (config('autosave.enable') == 'true' ):?>
<?php if ($type == 'is_page' || $type == 'is_subpage') :?>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js"></script>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js?v=1"></script>
<?php endif;?>
<?php endif;?>
<script>

View file

@ -218,7 +218,7 @@ $( function() {
<?php if ($type == 'is_post'):?>
<input type="hidden" name="is_post" value="is_post">
<?php endif;?>
<input type="hidden" name="oldfile" class="text" value="<?php echo $filename; ?>"/>
<input id="oldfile" type="hidden" name="oldfile" class="text" value="<?php echo $filename; ?>"/>
<input type="hidden" name="csrf_token" value="<?php echo get_csrf() ?>">
</div>
</div>
@ -350,7 +350,6 @@ $( function() {
var base_path = '<?php echo site_url() ?>';
var initial_image = '<?php echo $images;?>';
var parent_page = '';
var oldfile = '<?php echo $filename;?>';
var addEdit = 'edit';
var saveInterval = 60000;
</script>
@ -392,7 +391,7 @@ $('.img-container').on("click", ".the-img", function(e) {
</script>
<?php if (config('autosave.enable') == 'true' ):?>
<?php if ($isdraft[4] == 'draft') : ?>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js"></script>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js?v=1"></script>
<?php endif;?>
<?php endif;?>
<script>

View file

@ -151,10 +151,10 @@ $images = image_gallery(null, 1, 40);
<?php if($type == 'is_frontpage' || $type == 'is_profile') { ?>
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Save');?>"/>
<?php } elseif ($type == 'is_category') {?>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input id="oldfile" type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input type="submit" name="submit" class="btn btn-primary submit" value="<?php echo i18n('Save_category');?>"/>
<?php } else {?>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<input id="oldfile" type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
<?php $dd = find_subpage($oldmd); ?>
<?php $dr = find_draft_subpage($oldmd);?>
<?php if (stripos($dir . '/', '/draft/') !== false) { ?>
@ -274,7 +274,6 @@ $images = image_gallery(null, 1, 40);
var base_path = '<?php echo site_url() ?>';
var initial_image = '<?php echo $images;?>';
var parent_page = '<?php echo isset($parent) ? $parent : '';?>';
var oldfile = '<?php echo isset($url) ? $url : '';?>';
var addEdit = 'edit';
var saveInterval = 60000;
</script>
@ -319,7 +318,7 @@ $('.img-container').on("click", ".the-img", function(e) {
<?php if (config('autosave.enable') == 'true'):?>
<?php if ($type !== 'is_category' && $type !== 'is_profile' && $type !== 'is_frontpage') :?>
<?php if (stripos($dir . '/', '/draft/') !== false): ?>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js"></script>
<script src="<?php echo site_url();?>system/resources/js/save_draft.js?v=1"></script>
<?php endif;?>
<?php endif;?>
<?php endif;?>