noyainrain / wall

Digital wall (display) that can be controlled remotely, for example via mobile or tablet.
9 stars 4 forks source link

Make posts editable #185

Closed noyainrain closed 9 years ago

noyainrain commented 9 years ago

Add an edit() method on the server and an EditPostScreen on the remote.

noyainrain commented 9 years ago

Server draft:

post_edit: post_id, attrs...

Edit the post given by post_id.

attrs are the attributes to modify. Which attributes can be modified depends on the post type. See the specific post type's documentation for more information.

If a given attribute has an invalid value, a ValueError is returned.

post_edit

Dispatched when a post has been edited.

class Post(Object):
    def do_edit(self, **attrs):
        """Subclass API: edit the post.

        More precisely, this means to validate and then set the given `attrs`.

        Called by `edit()`, which takes care of validating and setting common
        post attributes and finally storing the modified post in the database.
        The default implementation does nothing.
        """
        pass
noyainrain commented 9 years ago

Remote draft:

/**
 * Screen for editing a `Post`.
 *
 * Provides an UI for editing all common post attributes. Content can be added
 * to the `.edit-post-screen-content` element.
 *
 * Properties:
 *
 * - `post`: post to edit.
 *
 * Subclass API: subclasses should add form fields to the content area for any
 * post attribute that can be modified. They should implement `updateContent()`
 * and may implement `getContentAttributes()`.
 *
 * Prototype properties:
 *
 * - `contentErrorMsgs`: object which maps `ValueError` codes to UI error
 *   messages specific to the post type. Defaults to `{}`.
 */
ns.EditPostScreen.prototype = Object.create(wall.remote.Screen.prototype, {
    /**
     * Subclass API: Retrieve attributes to edit from the content form fields.
     *
     * The default implementation simply returns `name` and `value` for any
     * `input` and `textarea` element.
     */
    getContentAttributes: {value: function() {}},

    /**
     * Subclass API: update the content area.
     *
     * Called when `post` is set.
     */
    updateContent: {value: function() {}}
});

/**
 * Attributes:
 * 
 * - `editPostScreens`: registered `EditPostScreen`s indexed by the name of the
 *   associated post type.
 */
ns.RemoteUi.prototype = Object.create(wall.Ui.prototype, {
    /**
     * Register a new `PostElement` for `postType`.
     *
     * `postElement` is the constructor to register. Optionally, an
     * `EditPostScreen` can be registered along, given by the `editPostScreen`
     * constructor.
     */
    registerPostElement: {value: function(postType, postElement,
                                          editPostScreen) {}},

    /**
     * Register a new `EditPostScreen` for `postType`.
     *
     * `editPostScreen` is the constructor to register.
     */
    registerEditPostScreen: {value: function(postType, editPostScreen) {
});