
if (!Kwo) var Kwo = {};

Kwo.CallForum = Class.create(Kwo.Dialog, {

  initialize: function($super, opts) {
    this.name = "auth";
    this.width = 420;
    this.height = 410;
    opts = opts || {};
    if ("callback" in opts) {
      this.onCallback = function () {
        if (Object.isString()) {
          Kwo.go(opts["callback"]);
        }
        else {
          opts["callback"].call();
          this.close();
        }
      }
    }
    else {
      this.onCallback = function () {
        if ("onAuth" in Kwo) {
          Kwo.onAuth.call();
        }
        this.close();
      }
   }
    $super("/board/topic.edit", opts);
  }
});


Kwo.Forum = {

  editTopic: function(args) {
    Kwo.go("/board/topic.edit", args);
  },

  onTopicSubmit: function(args) {
    Kwo.exec("/board/topic.save", args,
             {callback: Kwo.Forum.onTopicCallback, disable:true});
  },

  onTopicCallback: function(res) {
    if (Kwo.hasError(res)) {
      Kwo.error(res);
    }
    else {
      var msg = "Votre sujet a été soumis à modération. Il sera ajouté après validation de son contenu.";
      new BT.Class.Confirm({'content': msg, 'ok': function() { Kwo.go(res); }});
      //Kwo.go(res);
    }
  }

};

Kwo.CallTopic = Class.create(Kwo.Dialog, {

  initialize: function($super, opts) {
    this.name = "auth";
    this.width = 420;
    this.height = 360;
    opts = opts || {};
    if ("callback" in opts) {
      this.onCallback = function () {
        if (Object.isString()) {
          Kwo.go(opts["callback"]);
        }
        else {
          opts["callback"].call();
          this.close();
        }
      }
    }
    else {
      this.onCallback = function () {
        if ("onAuth" in Kwo) {
          Kwo.onAuth.call();
        }
        this.close();
      }
   }
    $super("/board/comment.edit", opts);
  }
});

Kwo.Topic = {

  editComment: function(args) {
    Kwo.go("/board/comment.edit", args);
  },

  onCommentSubmit: function(args) {
    Kwo.exec("/sys/item.comment", args,
             {callback: Kwo.Topic.onCommentCallback, disable:true});
  },

  onCommentCallback: function(res) {
    if (Kwo.hasError(res)) {
      Kwo.error(res);
    }
    else {
      var msg = "Votre commentaire a été soumis à modération. Il sera ajouté après validation de son contenu.";
      new BT.Class.Confirm({'content': msg, 'ok': function() { Kwo.go(res); }});
    }
  }

};