juanpujol / codeet

Open code snippets hosted on your server on an external code editor for quick updates.
1 stars 0 forks source link

Save notification #2

Open juanpujol opened 9 years ago

juanpujol commented 9 years ago

After using this for 2 days I really want to see some notification after saving.

I propose to have a method that can be called from the host app.

JoaoMosmann commented 9 years ago

Codeet.js already supports a save notification. When an instance receive a message codeet-save, along with the body text, comes a onSaved method that can be called when the document is successfully saved.

Example:

codeet.open({
    name: article.title,
    body: article.content,
    language: 'html',
    callback: function (response) {
        article.content = response.body;
        article.save().then(function () {
            response.onSaved();
        });
    }
});

It sends a post message codeet-saved back to Codeet.

So we only have to think how to display the message at Codeet.

I also think that is interesting to implement an onSaveFailure() to send a message with details about a problem during the saving.

juanpujol commented 9 years ago

I was thinking more on something like.

codeet.open({
    name: article.title,
    body: article.content,
    language: 'html',
    callback: function (response) {
        article.content = response.body;
        article.save().then(function () {
          codeet.notification({
            type: 'SUCCESS',
            body: 'File successfully saved'
          })
        }, function(response){
          codeet.notification({
            type: 'ERROR',
            body: 'Sorry, shit happens'
          })
        });
    }
});

If we have a notification method on codeet.js we can scale better. We can add support to more notifications eventually. When calling this method we append message: codeet-notification so Codeet core knows is a notification and based on the type we setup a layout using the body as content.

What do you think?

JoaoMosmann commented 9 years ago

I totally agree with.

But instead of calling codeet.notification(config) it shoud be codeet.notification(instance, config) or instance.notification(config)

I've created a issue in the codeet.js repo https://github.com/juanpujol/codeet.js/issues/1