Major bug fixes due to migration issue

This commit is contained in:
斟酌 鵬兄 2015-08-17 17:44:38 +08:00
parent f88643cead
commit f1d20a82d4
6 changed files with 88 additions and 54 deletions

View File

@ -20,12 +20,20 @@
/** @type {Astro.Blog.Components.Bubble} */ /** @type {Astro.Blog.Components.Bubble} */
var Bubble = __import( "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 prettyDate = __import( "Astro.utils.Date.pretty" );
var Visualizer = ns[ NS_INVOKE ]( "Visualizer" ); var Visualizer = ns[ NS_INVOKE ]( "Visualizer" );
var Tag = ns[ NS_INVOKE ]( "Tag" ); 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 Article = function( processorSet )
{ {
var pBubble = new Bubble(); var pBubble = new Bubble();
@ -110,7 +118,7 @@
//// private methods //// private methods
////// Handlers /////// ////// Handlers ///////
, saveSuccess = function (obj) , saveSuccess = function ( obj )
{ {
disableSaveFunction(); disableSaveFunction();
ae_mdate.innerHTML = prettyDate( new Date( obj.date_modified ) ); ae_mdate.innerHTML = prettyDate( new Date( obj.date_modified ) );
@ -120,6 +128,16 @@
ArticleModel.content = _content; ArticleModel.content = _content;
ArticleModel.date_modified = obj.date_modified; 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 // Set article id if this is a new document
if ( obj.article_id ) if ( obj.article_id )
ArticleModel.article_id = __article_id = obj.article_id; ArticleModel.article_id = __article_id = obj.article_id;
@ -127,7 +145,7 @@
window.history.replaceState( ArticleModel, "", base_path + "astroedit/" + __article_id + "/" ); window.history.replaceState( ArticleModel, "", base_path + "astroedit/" + __article_id + "/" );
} }
, publishSuccess = function (obj) , publishSuccess = function ( obj )
{ {
ae_publish.innerHTML = "Done edit"; ae_publish.innerHTML = "Done edit";
ae_backup.innerHTML = "Backup(Ctrl + s)"; ae_backup.innerHTML = "Backup(Ctrl + s)";
@ -135,23 +153,28 @@
ArticleModel.date_published = obj.date_published; ArticleModel.date_published = obj.date_published;
ae_pdate.innerHTML = prettyDate( new Date( 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(); window.open( base_path + "article/view/" + ArticleModel.slug + "/") && window.close();
} }
} }
, restoreArticle = function(obj) , restoreArticle = function( obj )
{ {
debug.Info("[Document] Looking for stored data"); debug.Info("[Document] Looking for stored data");
if (obj) if ( obj )
{ {
debug.Info("[Document] .. data found"); debug.Info("[Document] .. data found");
// Set stored article id // Set stored article id
@ -187,20 +210,17 @@
if ( obj && obj.entry ) if ( obj && obj.entry )
{ {
debug.Info( "[Document] Article Loaded" ); 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.setColor( "royalblue" );
pBubble.pop( "Using backup entry" ); pBubble.pop( "Using backup entry" );
Cycle.delay( function () { pBubble.blurp() }, 3000 ); Cycle.delay( function () { pBubble.blurp() }, 3000 );
} }
setArticle( obj.entry ); 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 ); __statePusher( obj.entry, __article_id );
} }
else else
@ -237,9 +257,9 @@
_ae_tag && _ae_tag.setTags( ArticleModel.tags ); _ae_tag && _ae_tag.setTags( ArticleModel.tags );
} }
, deleteDraft = function (confirmed) , deleteDraft = function ( confirmed )
{ {
if (confirmed) if ( confirmed )
{ {
var _data = { var _data = {
"draft": ArticleModel.draft ? 1 : 0 "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 ) , serverFailed = function ( obj )
{ {
pBubble.setColor( "red" ); pBubble.setColor( "red" );
pBubble.pop( obj["mesg"] ); pBubble.pop( obj ? obj["mesg"] : "Server Error" );
Cycle.delay( function () { pBubble.blurp() }, 3000 ); Cycle.delay( function () { pBubble.blurp() }, 3000 );
} }
@ -273,7 +299,7 @@
this.saveOrBackup = function () this.saveOrBackup = function ()
{ {
if (canSave) if ( canSave )
{ {
// Store current content and title // Store current content and title
_title = ae_title.value.trim(); _title = ae_title.value.trim();
@ -286,17 +312,10 @@
, title: _title , title: _title
, content: _content , content: _content
, tags: _ae_tag.getTags() , tags: _ae_tag.getTags()
, draft: ArticleModel.draft ? 1 : 0 , draft: 1
}; };
if (ArticleModel.draft == 0) postData( processorSet, _data, saveSuccess, serverFailed );
{
// This a published article
// action is Backup
_data.backup = 1;
}
postData( processorSet, _data, saveSuccess, serverFailed);
} }
}; };
@ -385,12 +404,22 @@
this.drop = function () this.drop = function ()
{ {
new MessageBox( if( ArticleModel.draft )
"Delete draft" {
, "Are you sure you want to delete this draft? (Published article will only remove backup draft.)" new MessageBox(
, "Delete", "No" "Delete draft"
, deleteDraft , "Are you sure you want to delete this draft? (Published article will only remove backup draft.)"
).show(); , "Delete", "No"
, deleteDraft
).show();
}
else
{
new MessageBox(
"Delete Draft"
, "There is no draft to delete"
).show();
}
}; };
this.updateContent = contentUpdate; this.updateContent = contentUpdate;

View File

@ -70,8 +70,8 @@
// Register on click function // Register on click function
entry.addEventListener( "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; ae_drafts_h = ae_drafts.clientHeight;
@ -147,7 +147,7 @@
, __pushState = function ( obj, article_id ) , __pushState = function ( obj, article_id )
{ {
window.history.pushState( obj, "", "../" + article_id + "/" ); window.history.pushState( obj, "", "/astroedit/" + article_id + "/" );
} }
setupExpand(); setupExpand();

View File

@ -62,9 +62,9 @@
background-color: crimson; background-color: crimson;
} }
.b_publish { background-color: slategrey; } .b_scope { background-color: slategrey; }
.b_publish:before { content: 'Publish'; background-color: purple; } .b_scope:before { content: 'Private'; background-color: purple; }
.b_publish:after { content: 'Unpublish'; background-color: orangered; } .b_scope:after { content: 'Public'; background-color: orangered; }
.b_notify { background-color: slategrey; } .b_notify { background-color: slategrey; }
.b_notify:before { content: 'Follow'; } .b_notify:before { content: 'Follow'; }

View File

@ -31,8 +31,6 @@
.btn_toggle:before, .btn_toggle:after { .btn_toggle:before, .btn_toggle:after {
padding-top: 0.2em;
text-align: center; text-align: center;
position: absolute; position: absolute;
@ -65,7 +63,7 @@
.btn_toggle:after { .btn_toggle:after {
content: ''; content: '';
background-color: royalblue; background-color: royalblue;
top: 200%; top: 100%;
-webkit-transition: all 750ms cubic-bezier(0.215, 0.610, 0.355, 1.000); -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); -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 */ 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%; top: 0%;
} }
.btn_toggle[active]:before { .btn_toggle[active="1"]:before {
top: -120%; top: -100%;
} }

View File

@ -20,7 +20,7 @@
var n_toggle = function (args) var n_toggle = function (args)
{ {
if(stage.getAttribute('active')) if( stage.getAttribute("active") == 1 )
{ {
stage.removeAttribute('active'); stage.removeAttribute('active');
} }
@ -39,7 +39,10 @@
IDOMElement(stage).addEventListener( IDOMElement(stage).addEventListener(
'Click' 'Click'
, function (e) { , 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 ); postData( processor, _action, n_toggle, nError );
} }
); );
@ -47,7 +50,7 @@
var init = function() var init = function()
{ {
var toggles = config.get( "toggle_btns" ); var toggles = config.get( "ToggleButtons" );
for( var i in toggles ) for( var i in toggles )
{ {
new ToggleButton( toggles[ i ][0], toggles[ i ][1], toggles[ i ][2] ); new ToggleButton( toggles[ i ][0], toggles[ i ][1], toggles[ i ][2] );

View File

@ -4,9 +4,13 @@ _AstJson_.AJaxGetArticle = {};
/** @type {Boolean} */ /** @type {Boolean} */
_AstJson_.AJaxGetArticle.status; _AstJson_.AJaxGetArticle.status;
/** @type {String} */ /** @type {String} */
_AstJson_.AJaxGetArticle.backup; _AstJson_.AJaxGetArticle.ref_id;
/** @type {String} */
_AstJson_.AJaxGetArticle.article_id;
/** @type {Object} */ /** @type {Object} */
_AstJson_.AJaxGetArticle.entry; _AstJson_.AJaxGetArticle.entry;
/** @type {String} */
_AstJson_.AJaxGetArticle.entry._id;
/** @type {String} */ /** @type {String} */
_AstJson_.AJaxGetArticle.entry.slug; _AstJson_.AJaxGetArticle.entry.slug;
/** @type {Boolean} */ /** @type {Boolean} */