From f1d20a82d40bdce23f128f0640f9dfc481fb60ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Mon, 17 Aug 2015 17:44:38 +0800 Subject: [PATCH] Major bug fixes due to migration issue --- botanjs/src/Astro/Blog/AstroEdit/Article.js | 105 +++++++++++------- botanjs/src/Astro/Blog/AstroEdit/Draft.js | 6 +- .../src/Astro/Blog/Components/Entry/Blog.css | 6 +- .../Blog/Components/ToggleButton/_this.css | 10 +- .../Blog/Components/ToggleButton/_this.js | 9 +- .../src/externs/_AstJson_.AJaxGetArticle.js | 6 +- 6 files changed, 88 insertions(+), 54 deletions(-) diff --git a/botanjs/src/Astro/Blog/AstroEdit/Article.js b/botanjs/src/Astro/Blog/AstroEdit/Article.js index 2af3458..9440cdc 100644 --- a/botanjs/src/Astro/Blog/AstroEdit/Article.js +++ b/botanjs/src/Astro/Blog/AstroEdit/Article.js @@ -20,12 +20,20 @@ /** @type {Astro.Blog.Components.Bubble} */ var Bubble = __import( "Astro.Blog.Components.Bubble" ); - var postData = __import( "System.Net.postData" ); + var opostData = __import( "System.Net.postData" ); var prettyDate = __import( "Astro.utils.Date.pretty" ); var Visualizer = ns[ NS_INVOKE ]( "Visualizer" ); var Tag = ns[ NS_INVOKE ]( "Tag" ); + + // Editor Override + var postData = function( processor, data, success, failed ) + { + data[ "editor" ] = 1; + opostData( processor, data, success, failed ); + }; + var Article = function( processorSet ) { var pBubble = new Bubble(); @@ -110,7 +118,7 @@ //// private methods ////// Handlers /////// - , saveSuccess = function (obj) + , saveSuccess = function ( obj ) { disableSaveFunction(); ae_mdate.innerHTML = prettyDate( new Date( obj.date_modified ) ); @@ -120,6 +128,16 @@ ArticleModel.content = _content; ArticleModel.date_modified = obj.date_modified; + // If this is a published article + // we need to set the ref_id for ArticleModel + // then set current id to draft's id + if( ArticleModel.article_id != obj.article_id ) + { + ArticleModel.draft = true; + ArticleModel.ref_id = __article_id; + ArticleModel.article_id = obj.article_id; + } + // Set article id if this is a new document if ( obj.article_id ) ArticleModel.article_id = __article_id = obj.article_id; @@ -127,7 +145,7 @@ window.history.replaceState( ArticleModel, "", base_path + "astroedit/" + __article_id + "/" ); } - , publishSuccess = function (obj) + , publishSuccess = function ( obj ) { ae_publish.innerHTML = "Done edit"; ae_backup.innerHTML = "Backup(Ctrl + s)"; @@ -135,23 +153,28 @@ ArticleModel.date_published = obj.date_published; ae_pdate.innerHTML = prettyDate( new Date( obj.date_published ) ); - this.contentUpdate && saveSuccess(obj); + this.contentUpdate && saveSuccess( obj ); - new MessageBox("AstroEdit", "You have successfully published your article!", "Stay here", "Exit and goto article", publishAction).show(); + new MessageBox( + "AstroEdit" + , "You have successfully published your article!" + , "Stay here", "Exit and goto article" + , publishAction + ).show(); } - , publishAction = function (stay) + , publishAction = function ( stay ) { - if (!stay) + if ( !stay ) { window.open( base_path + "article/view/" + ArticleModel.slug + "/") && window.close(); } } - , restoreArticle = function(obj) + , restoreArticle = function( obj ) { debug.Info("[Document] Looking for stored data"); - if (obj) + if ( obj ) { debug.Info("[Document] .. data found"); // Set stored article id @@ -187,20 +210,17 @@ if ( obj && obj.entry ) { debug.Info( "[Document] Article Loaded" ); - if ( obj.backup ) + if ( obj.entry.ref_id ) { + // This is a backup item + __article_id = obj.article_id; + pBubble.setColor( "royalblue" ); pBubble.pop( "Using backup entry" ); Cycle.delay( function () { pBubble.blurp() }, 3000 ); } + setArticle( obj.entry ); - if ( !obj.entry.article_id ) - { - // sever will not return article_id - // since it is an UPDATE - // Store the article_id manually - obj.entry.article_id = __article_id; - } __statePusher( obj.entry, __article_id ); } else @@ -237,9 +257,9 @@ _ae_tag && _ae_tag.setTags( ArticleModel.tags ); } - , deleteDraft = function (confirmed) + , deleteDraft = function ( confirmed ) { - if (confirmed) + if ( confirmed ) { var _data = { "draft": ArticleModel.draft ? 1 : 0 @@ -251,15 +271,21 @@ } } - , deleteSuccess = function () + , deleteSuccess = function ( obj ) { - location.reload(true); + var loc = window.location; + loc.replace( + loc.href.replace( + "/" + ArticleModel.article_id + , ArticleModel.ref_id ? ( "/" + ArticleModel.ref_id ) : "" + ) + ); } , serverFailed = function ( obj ) { pBubble.setColor( "red" ); - pBubble.pop( obj["mesg"] ); + pBubble.pop( obj ? obj["mesg"] : "Server Error" ); Cycle.delay( function () { pBubble.blurp() }, 3000 ); } @@ -273,7 +299,7 @@ this.saveOrBackup = function () { - if (canSave) + if ( canSave ) { // Store current content and title _title = ae_title.value.trim(); @@ -286,17 +312,10 @@ , title: _title , content: _content , tags: _ae_tag.getTags() - , draft: ArticleModel.draft ? 1 : 0 + , draft: 1 }; - if (ArticleModel.draft == 0) - { - // This a published article - // action is Backup - _data.backup = 1; - } - - postData( processorSet, _data, saveSuccess, serverFailed); + postData( processorSet, _data, saveSuccess, serverFailed ); } }; @@ -385,12 +404,22 @@ this.drop = function () { - new MessageBox( - "Delete draft" - , "Are you sure you want to delete this draft? (Published article will only remove backup draft.)" - , "Delete", "No" - , deleteDraft - ).show(); + if( ArticleModel.draft ) + { + new MessageBox( + "Delete draft" + , "Are you sure you want to delete this draft? (Published article will only remove backup draft.)" + , "Delete", "No" + , deleteDraft + ).show(); + } + else + { + new MessageBox( + "Delete Draft" + , "There is no draft to delete" + ).show(); + } }; this.updateContent = contentUpdate; diff --git a/botanjs/src/Astro/Blog/AstroEdit/Draft.js b/botanjs/src/Astro/Blog/AstroEdit/Draft.js index 695d0aa..31aa5c3 100644 --- a/botanjs/src/Astro/Blog/AstroEdit/Draft.js +++ b/botanjs/src/Astro/Blog/AstroEdit/Draft.js @@ -70,8 +70,8 @@ // Register on click function entry.addEventListener( "click", function() { - article.load( entry.getAttribute( "value" ), __pushState ); - } ); + article.load( this.getAttribute( "value" ), __pushState ); + }.bind( entry ) ); } ae_drafts_h = ae_drafts.clientHeight; @@ -147,7 +147,7 @@ , __pushState = function ( obj, article_id ) { - window.history.pushState( obj, "", "../" + article_id + "/" ); + window.history.pushState( obj, "", "/astroedit/" + article_id + "/" ); } setupExpand(); diff --git a/botanjs/src/Astro/Blog/Components/Entry/Blog.css b/botanjs/src/Astro/Blog/Components/Entry/Blog.css index 8fc6172..2759945 100644 --- a/botanjs/src/Astro/Blog/Components/Entry/Blog.css +++ b/botanjs/src/Astro/Blog/Components/Entry/Blog.css @@ -62,9 +62,9 @@ background-color: crimson; } -.b_publish { background-color: slategrey; } -.b_publish:before { content: 'Publish'; background-color: purple; } -.b_publish:after { content: 'Unpublish'; background-color: orangered; } +.b_scope { background-color: slategrey; } +.b_scope:before { content: 'Private'; background-color: purple; } +.b_scope:after { content: 'Public'; background-color: orangered; } .b_notify { background-color: slategrey; } .b_notify:before { content: 'Follow'; } diff --git a/botanjs/src/Astro/Blog/Components/ToggleButton/_this.css b/botanjs/src/Astro/Blog/Components/ToggleButton/_this.css index aeb0d7f..3034041 100644 --- a/botanjs/src/Astro/Blog/Components/ToggleButton/_this.css +++ b/botanjs/src/Astro/Blog/Components/ToggleButton/_this.css @@ -31,8 +31,6 @@ .btn_toggle:before, .btn_toggle:after { - padding-top: 0.2em; - text-align: center; position: absolute; @@ -65,7 +63,7 @@ .btn_toggle:after { content: ''; background-color: royalblue; - top: 200%; + top: 100%; -webkit-transition: all 750ms cubic-bezier(0.215, 0.610, 0.355, 1.000); -moz-transition: all 750ms cubic-bezier(0.215, 0.610, 0.355, 1.000); @@ -74,11 +72,11 @@ transition: all 500ms cubic-bezier(0.215, 0.610, 0.355, 1.000); /* easeOutCubic */ } -.btn_toggle[active]:after { +.btn_toggle[active="1"]:after { top: 0%; } -.btn_toggle[active]:before { - top: -120%; +.btn_toggle[active="1"]:before { + top: -100%; } diff --git a/botanjs/src/Astro/Blog/Components/ToggleButton/_this.js b/botanjs/src/Astro/Blog/Components/ToggleButton/_this.js index 8e0fe65..a7efe98 100644 --- a/botanjs/src/Astro/Blog/Components/ToggleButton/_this.js +++ b/botanjs/src/Astro/Blog/Components/ToggleButton/_this.js @@ -20,7 +20,7 @@ var n_toggle = function (args) { - if(stage.getAttribute('active')) + if( stage.getAttribute("active") == 1 ) { stage.removeAttribute('active'); } @@ -39,7 +39,10 @@ IDOMElement(stage).addEventListener( 'Click' , function (e) { - var _action = stage.getAttribute('active') ? obj.disable : obj.enable; + var _action = stage.getAttribute( "active" ) == 1 + ? obj[ "disable" ] + : obj[ "enable" ] + ; postData( processor, _action, n_toggle, nError ); } ); @@ -47,7 +50,7 @@ var init = function() { - var toggles = config.get( "toggle_btns" ); + var toggles = config.get( "ToggleButtons" ); for( var i in toggles ) { new ToggleButton( toggles[ i ][0], toggles[ i ][1], toggles[ i ][2] ); diff --git a/botanjs/src/externs/_AstJson_.AJaxGetArticle.js b/botanjs/src/externs/_AstJson_.AJaxGetArticle.js index 697ca25..71eebd7 100644 --- a/botanjs/src/externs/_AstJson_.AJaxGetArticle.js +++ b/botanjs/src/externs/_AstJson_.AJaxGetArticle.js @@ -4,9 +4,13 @@ _AstJson_.AJaxGetArticle = {}; /** @type {Boolean} */ _AstJson_.AJaxGetArticle.status; /** @type {String} */ -_AstJson_.AJaxGetArticle.backup; +_AstJson_.AJaxGetArticle.ref_id; +/** @type {String} */ +_AstJson_.AJaxGetArticle.article_id; /** @type {Object} */ _AstJson_.AJaxGetArticle.entry; + /** @type {String} */ + _AstJson_.AJaxGetArticle.entry._id; /** @type {String} */ _AstJson_.AJaxGetArticle.entry.slug; /** @type {Boolean} */