* 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/dist
|
||||
build/extra/*.lock.db
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $Author$
|
||||
// $Date$
|
||||
// $URL$
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
|
@ -185,16 +185,16 @@ Api.blogger.newPost = function(appKey, id, name, password, content, publish) {
|
|||
}
|
||||
|
||||
var parts = Api.blogger._getContentParts(content);
|
||||
var story = new Story;
|
||||
story.site = site;
|
||||
story.creator = user;
|
||||
story.update({
|
||||
|
||||
var story = Story.add(site, {
|
||||
title: parts.title,
|
||||
text: parts.text,
|
||||
status: publish ? Story.PUBLIC : Story.CLOSED,
|
||||
mode: Story.FEATURED
|
||||
});
|
||||
site.stories.add(story);
|
||||
|
||||
story.site = site;
|
||||
story.creator = user;
|
||||
return story._id;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
//
|
||||
// The Antville Project
|
||||
// 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'');
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -17,10 +19,9 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $Author$
|
||||
// $Date$
|
||||
// $URL$
|
||||
//
|
||||
|
||||
/**
|
||||
* @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_pings: 0,
|
||||
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 +
|
||||
" to add a post to site " + site.name);
|
||||
}
|
||||
|
||||
var story = new Story;
|
||||
story.site = site;
|
||||
story.creator = user;
|
||||
story.update({
|
||||
|
||||
var story = Story.add(site.stories, {
|
||||
title: content.title,
|
||||
text: content.description,
|
||||
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,
|
||||
tags: content.categories
|
||||
});
|
||||
site.stories.add(story);
|
||||
|
||||
story.site = site;
|
||||
story.creator = user;
|
||||
story.setMetadata('postSource', content.postSource);
|
||||
return story._id;
|
||||
}
|
||||
|
||||
|
@ -165,6 +167,8 @@ Api.metaWeblog.editPost = function(id, name, password, content, publish) {
|
|||
Story.OPEN : Story.CLOSED,
|
||||
tags: content.categories
|
||||
});
|
||||
|
||||
story.setMetadata('postSource', content.postSource);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $Author$
|
||||
// $Date$
|
||||
// $URL$
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
|
@ -122,7 +122,7 @@ Api.mt.getPostCategories = function(id, name, password) {
|
|||
return result;
|
||||
}
|
||||
|
||||
// FIXME: What kind of stupid API is this?
|
||||
// FIXME: How do I post a new story?
|
||||
/**
|
||||
*
|
||||
* @param {Number} id
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $Author$
|
||||
// $Date$
|
||||
// $URL$
|
||||
|
||||
/**
|
||||
|
@ -85,11 +85,9 @@ Stories.prototype.main_action = function() {
|
|||
}
|
||||
|
||||
Stories.prototype.create_action = function() {
|
||||
var story = new Story;
|
||||
if (req.postParams.save) {
|
||||
try {
|
||||
story.update(req.postParams);
|
||||
this.add(story);
|
||||
story = Story.add(this, req.postParams);
|
||||
story.notify(req.action);
|
||||
delete session.data.backup;
|
||||
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.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");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -19,17 +19,46 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $Author$
|
||||
// $Date$
|
||||
// $URL$
|
||||
|
||||
/**
|
||||
* @fileOverview Defindes the Story prototype.
|
||||
* @fileOverview Defines the Story prototype.
|
||||
*/
|
||||
|
||||
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
|
||||
* @returns {String[]}
|
||||
|
@ -53,22 +82,6 @@ Story.getCommentModes = defineConstants(Story, markgettext("closed"),
|
|||
/* markgettext("readonly"), markgettext("moderated"), */
|
||||
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
|
||||
* @constructor
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
// limitations under the License.
|
||||
//
|
||||
// $Revision$
|
||||
// $LastChangedBy$
|
||||
// $LastChangedDate$
|
||||
// $Author$
|
||||
// $Date$
|
||||
// $URL$
|
||||
|
||||
app.addRepository("modules/helma/Aspects.js");
|
||||
|
@ -209,11 +209,11 @@ Site.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);
|
||||
}
|
||||
|
||||
Stories.prototype.onCodeUpdate = function() {
|
||||
return helma.aspects.addBefore(this, "create_action",
|
||||
return helma.aspects.addBefore(this, "create_action",
|
||||
aspects.fixStoryEditorParams);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue