var $ = require("jquery");
var utils = require("../utils");

module.exports = function(dataSources){

  var contentFactory = {
    load : function(rerender){
      var value = [];
      var suppressRerender = false;
      var feedbackTrans = dataSources.get("translations").get("feedback");

      return {
        render : function(){
          var sourceField = $("<input type='text'></input>");

          var initField = $("<textarea></textarea>");
          var numberField = $("<input type='checkbox'></input>")
          var renameField = $("<input type='text'></input>")

          var createButton = $("<input type='button' value='Create'></input>")
            .click(function(){
              var source = sourceField.val();
              var init = initField.val();
              var name = renameField.val();

              var checked = numberField.is(":checked")
              if(checked){
                init = parseFloat(init) || 0;
              }

              if(source){
                  feedbackTrans(source, init, dataSources, name);
                  rerender();
              }
            });

          return $("<span></span>")
            .append($("<h3>Feedback Translation: </h3>"))
            .append($("<p>The source must be a tap data source or else infinite subscriptions will be generated by the feedback loop</p>"))
            .append($("<div></div>").append($("<span>Source: </span>")).append(sourceField))
            .append($("<div></div>").append($("<span>Number: </span>")).append(numberField))
            .append($("<div></div>").append($("<span>Init: </span>")).append(initField))
            .append($("<div></div>").append($("<span>Name: </span>")).append(renameField))
            .append(createButton);

        }, unload: function(){
          suppressRerender = true;
        }
      };
    }
  };

  dataSources.get("contentTypes").set("feedback-translation", contentFactory);
}

var $ = require("jquery");
var utils = require("../utils");

module.exports = function(dataSources){

  var contentFactory = {
    load : function(rerender){
      var value = [];
      var suppressRerender = false;
      var feedbackTrans = dataSources.get("translations").get("feedback");

      return {
        render : function(){
          var sourceField = $("<input type='text'></input>");

          var initField = $("<textarea></textarea>");
          var renameField = $("<input type='text'></input>")

          var createButton = $("<input type='button' value='Create'></input>")
            .click(function(){
              var source = sourceField.val();
              var init = JSON.parse(initField.val()) || null;
              var name = renameField.val();

              if(source){
                  feedbackTrans(source, init, dataSources, name);
                  rerender();
              }
            });

          return $("<span></span>")
            .append($("<h3>Feedback Translation: </h3>"))
            .append($("<p>The source must be a tap data source or else infinite subscriptions will be generated by the feedback loop</p>"))
            .append($("<div></div>").append($("<span>Source: </span>")).append(sourceField))
            .append($("<div></div>").append($("<span>Init: </span>")).append(initField))
            .append($("<div></div>").append($("<span>Name: </span>")).append(renameField))
            .append(createButton);

        }, unload: function(){
          suppressRerender = true;
        }
      };
    }
  };

  dataSources.get("contentTypes").set("feedback-translation", contentFactory);
}

fix feedback