* Added Story.add() method as counterpart to Story.remove() and to establish kind of internal API
* Rewrote external API (Api prototype) reducing redundant code by calling Story.add() method
This commit is contained in:
parent
fe159c3112
commit
2ca26e4f28
7 changed files with 70 additions and 53 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,4 +1,6 @@
|
||||||
/.*
|
/.*
|
||||||
|
/antville.eml
|
||||||
|
/antville.iml
|
||||||
build/build.properties
|
build/build.properties
|
||||||
build/dist
|
build/dist
|
||||||
build/extra/*.lock.db
|
build/extra/*.lock.db
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
// $Revision$
|
// $Revision$
|
||||||
// $LastChangedBy$
|
// $Author$
|
||||||
// $LastChangedDate$
|
// $Date$
|
||||||
// $URL$
|
// $URL$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileOverview Methods that implement Blogger's XML-RPC API.
|
* @fileOverview Methods that implement Blogger's XML-RPC API.
|
||||||
* See http://www.blogger.com/developers/api/1_docs/ for further details.
|
* See http://goo.gl/u8lZZ for further details.
|
||||||
* The blogger.getTemplate and blogger.setTemplate methods are not supported
|
* The blogger.getTemplate and blogger.setTemplate methods are not supported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -185,16 +185,16 @@ Api.blogger.newPost = function(appKey, id, name, password, content, publish) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var parts = Api.blogger._getContentParts(content);
|
var parts = Api.blogger._getContentParts(content);
|
||||||
var story = new Story;
|
|
||||||
story.site = site;
|
var story = Story.add(site, {
|
||||||
story.creator = user;
|
|
||||||
story.update({
|
|
||||||
title: parts.title,
|
title: parts.title,
|
||||||
text: parts.text,
|
text: parts.text,
|
||||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||||
mode: Story.FEATURED
|
mode: Story.FEATURED
|
||||||
});
|
});
|
||||||
site.stories.add(story);
|
|
||||||
|
story.site = site;
|
||||||
|
story.creator = user;
|
||||||
return story._id;
|
return story._id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
//
|
|
||||||
// The Antville Project
|
// The Antville Project
|
||||||
// http://code.google.com/p/antville
|
// http://code.google.com/p/antville
|
||||||
//
|
//
|
||||||
// Copyright 2001-2007 by The Antville People
|
// Copyright 2007-2011 by Tobi Schäfer.
|
||||||
|
//
|
||||||
|
// Copyright 2001–2007 Robert Gaggl, Hannes Wallnöfer, Tobi Schäfer,
|
||||||
|
// Matthias & Michael Platzer, Christoph Lincke.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the ``License'');
|
// Licensed under the Apache License, Version 2.0 (the ``License'');
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -17,10 +19,9 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
// $Revision$
|
// $Revision$
|
||||||
// $LastChangedBy$
|
// $Author$
|
||||||
// $LastChangedDate$
|
// $Date$
|
||||||
// $URL$
|
// $URL$
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileOverview Methods that implement the MetaWeblog XML-RPC API.
|
* @fileOverview Methods that implement the MetaWeblog XML-RPC API.
|
||||||
|
@ -50,7 +51,8 @@ Api.metaWeblog._getStruct = function(story) {
|
||||||
mt_allow_comments: story.commentMode === Story.OPEN ? 1 : 0,
|
mt_allow_comments: story.commentMode === Story.OPEN ? 1 : 0,
|
||||||
mt_allow_pings: 0,
|
mt_allow_pings: 0,
|
||||||
mt_convert_breaks: null,
|
mt_convert_breaks: null,
|
||||||
mt_keywords: null
|
mt_keywords: null,
|
||||||
|
postSource: story.getMetadata('postSource')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,11 +122,8 @@ Api.metaWeblog.newPost = function(id, name, password, content, publish) {
|
||||||
throw Error("Permission denied for user " + user.name +
|
throw Error("Permission denied for user " + user.name +
|
||||||
" to add a post to site " + site.name);
|
" to add a post to site " + site.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
var story = new Story;
|
var story = Story.add(site.stories, {
|
||||||
story.site = site;
|
|
||||||
story.creator = user;
|
|
||||||
story.update({
|
|
||||||
title: content.title,
|
title: content.title,
|
||||||
text: content.description,
|
text: content.description,
|
||||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||||
|
@ -132,7 +131,10 @@ Api.metaWeblog.newPost = function(id, name, password, content, publish) {
|
||||||
commentMode: content.discussions === 0 ? Story.CLOSED : Story.OPEN,
|
commentMode: content.discussions === 0 ? Story.CLOSED : Story.OPEN,
|
||||||
tags: content.categories
|
tags: content.categories
|
||||||
});
|
});
|
||||||
site.stories.add(story);
|
|
||||||
|
story.site = site;
|
||||||
|
story.creator = user;
|
||||||
|
story.setMetadata('postSource', content.postSource);
|
||||||
return story._id;
|
return story._id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +167,8 @@ Api.metaWeblog.editPost = function(id, name, password, content, publish) {
|
||||||
Story.OPEN : Story.CLOSED,
|
Story.OPEN : Story.CLOSED,
|
||||||
tags: content.categories
|
tags: content.categories
|
||||||
});
|
});
|
||||||
|
|
||||||
|
story.setMetadata('postSource', content.postSource);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
// $Revision$
|
// $Revision$
|
||||||
// $LastChangedBy$
|
// $Author$
|
||||||
// $LastChangedDate$
|
// $Date$
|
||||||
// $URL$
|
// $URL$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileOverview Methods that implement Movable Type's XML-RPC API.
|
* @fileOverview Methods that implement Movable Type's XML-RPC API.
|
||||||
* See http://www.sixapart.com/developers/xmlrpc/movable_type_api for details.
|
* See http://www.sixapart.com/pronet/breese/xmlrpc/movable_type_api/ for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @namespace */
|
/** @namespace */
|
||||||
|
@ -122,7 +122,7 @@ Api.mt.getPostCategories = function(id, name, password) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: What kind of stupid API is this?
|
// FIXME: How do I post a new story?
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Number} id
|
* @param {Number} id
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
// $Revision$
|
// $Revision$
|
||||||
// $LastChangedBy$
|
// $Author$
|
||||||
// $LastChangedDate$
|
// $Date$
|
||||||
// $URL$
|
// $URL$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,11 +85,9 @@ Stories.prototype.main_action = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Stories.prototype.create_action = function() {
|
Stories.prototype.create_action = function() {
|
||||||
var story = new Story;
|
|
||||||
if (req.postParams.save) {
|
if (req.postParams.save) {
|
||||||
try {
|
try {
|
||||||
story.update(req.postParams);
|
story = Story.add(this, req.postParams);
|
||||||
this.add(story);
|
|
||||||
story.notify(req.action);
|
story.notify(req.action);
|
||||||
delete session.data.backup;
|
delete session.data.backup;
|
||||||
res.message = gettext("The story was successfully created.");
|
res.message = gettext("The story was successfully created.");
|
||||||
|
@ -102,7 +100,7 @@ Stories.prototype.create_action = function() {
|
||||||
|
|
||||||
res.data.title = gettext("Add Story");
|
res.data.title = gettext("Add Story");
|
||||||
res.data.action = this.href(req.action);
|
res.data.action = this.href(req.action);
|
||||||
res.data.body = story.renderSkinAsString("Story#edit");
|
res.data.body = (new Story).renderSkinAsString("Story#edit");
|
||||||
this._parent.renderSkin("Site#page");
|
this._parent.renderSkin("Site#page");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,46 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
// $Revision$
|
// $Revision$
|
||||||
// $LastChangedBy$
|
// $Author$
|
||||||
// $LastChangedDate$
|
// $Date$
|
||||||
// $URL$
|
// $URL$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileOverview Defindes the Story prototype.
|
* @fileOverview Defines the Story prototype.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
markgettext("Story");
|
markgettext("Story");
|
||||||
markgettext("story");
|
markgettext("story");
|
||||||
|
|
||||||
|
this.handleMetadata("title");
|
||||||
|
this.handleMetadata("text");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function
|
||||||
|
* @param {Story[]} parent
|
||||||
|
* @param {Object} data
|
||||||
|
* @returns {Story}
|
||||||
|
*/
|
||||||
|
Story.add = function(parent, data) {
|
||||||
|
var story = new Story;
|
||||||
|
story.update(data);
|
||||||
|
parent.add(story);
|
||||||
|
return story;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @function
|
||||||
|
*/
|
||||||
|
Story.remove = function() {
|
||||||
|
if (this.constructor === Story) {
|
||||||
|
HopObject.remove.call(this.comments);
|
||||||
|
this.deleteMetadata();
|
||||||
|
this.setTags(null);
|
||||||
|
this.remove();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @function
|
* @function
|
||||||
* @returns {String[]}
|
* @returns {String[]}
|
||||||
|
@ -53,22 +82,6 @@ Story.getCommentModes = defineConstants(Story, markgettext("closed"),
|
||||||
/* markgettext("readonly"), markgettext("moderated"), */
|
/* markgettext("readonly"), markgettext("moderated"), */
|
||||||
markgettext("open"));
|
markgettext("open"));
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
Story.remove = function() {
|
|
||||||
if (this.constructor === Story) {
|
|
||||||
HopObject.remove.call(this.comments);
|
|
||||||
this.deleteMetadata();
|
|
||||||
this.setTags(null);
|
|
||||||
this.remove();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.handleMetadata("title");
|
|
||||||
this.handleMetadata("text");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Story
|
* @name Story
|
||||||
* @constructor
|
* @constructor
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
// $Revision$
|
// $Revision$
|
||||||
// $LastChangedBy$
|
// $Author$
|
||||||
// $LastChangedDate$
|
// $Date$
|
||||||
// $URL$
|
// $URL$
|
||||||
|
|
||||||
app.addRepository("modules/helma/Aspects.js");
|
app.addRepository("modules/helma/Aspects.js");
|
||||||
|
@ -209,11 +209,11 @@ Site.prototype.onCodeUpdate = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Story.prototype.onCodeUpdate = function() {
|
Story.prototype.onCodeUpdate = function() {
|
||||||
helma.aspects.addBefore(this, "edit_action", aspects.fixStoryEditorParams);
|
helma.aspects.addBefore(this, "edit_action", aspects.fixStoryEditorParams);
|
||||||
return helma.aspects.addBefore(this, "update", aspects.setTopics);
|
return helma.aspects.addBefore(this, "update", aspects.setTopics);
|
||||||
}
|
}
|
||||||
|
|
||||||
Stories.prototype.onCodeUpdate = function() {
|
Stories.prototype.onCodeUpdate = function() {
|
||||||
return helma.aspects.addBefore(this, "create_action",
|
return helma.aspects.addBefore(this, "create_action",
|
||||||
aspects.fixStoryEditorParams);
|
aspects.fixStoryEditorParams);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue