text: (function(GoNorth) {
      "use strict";
      (function(DefaultNodeShapes) {
          (function(Actions) {
  
              /// Action Type for adding text to a quest
              Actions.actionTypeAddQuestToText = 10;
  
              /**
               * Add Text to Quest Action
               * @class
               */
              Actions.AddQuestTextAction = function()
              {
                  GoNorth.DefaultNodeShapes.Actions.BaseAction.apply(this);
                  GoNorth.DefaultNodeShapes.Shapes.SharedObjectLoading.apply(this);
              };
  
              Actions.AddQuestTextAction.prototype = jQuery.extend({ }, GoNorth.DefaultNodeShapes.Actions.BaseAction.prototype);
              Actions.AddQuestTextAction.prototype = jQuery.extend(Actions.AddQuestTextAction.prototype, GoNorth.DefaultNodeShapes.Shapes.SharedObjectLoading.prototype);
  
              /**
               * Returns the HTML Content of the action
               * 
               * @returns {string} HTML Content of the action
               */
              Actions.AddQuestTextAction.prototype.getContent = function() {
                  return  "<div class='gn-actionNodeObjectSelectContainer'>" + 
                              "<a class='gn-clickable gn-nodeActionSelectQuest gn-nodeNonClickableOnReadonly'></a>&nbsp;" +
                              "<a class='gn-clickable gn-nodeActionOpenQuest' title='" + DefaultNodeShapes.Localization.Actions.OpenQuestTooltip + "' style='display: none'><i class='glyphicon glyphicon-eye-open'></i></a>" +
                          "</div>" +
                          "<div class='gn-nodeActionText'>" + DefaultNodeShapes.Localization.Actions.QuestText + "</div>" +
                          "<textarea class='gn-nodeActionQuestText'></textarea>";
              };
  
              /**
               * Gets called once the action was intialized
               * 
               * @param {object} contentElement Content element
               * @param {ActionNode} actionNode Parent Action node
               */
              Actions.AddQuestTextAction.prototype.onInitialized = function(contentElement, actionNode) {
                  this.contentElement = contentElement;
                  this.contentElement.find(".gn-nodeActionSelectQuest").html(DefaultNodeShapes.Localization.Actions.ChooseQuestLabel);
  
                  var questOpenLink = contentElement.find(".gn-nodeActionOpenQuest");
  
                  // Deserialize
                  var existingQuestId = this.deserializeData();
                  if(existingQuestId)
                  {
                      questOpenLink.show();
  
                      actionNode.showLoading();
                      actionNode.hideError();
  
                      this.loadObjectShared(existingQuestId).then(function(quest) {
                          contentElement.find(".gn-nodeActionSelectQuest").text(quest.name);
                          actionNode.hideLoading();
                      }).fail(function(xhr) {
                          actionNode.hideLoading();
                          actionNode.showError();
                      });
                  }
  
                  // Handlers
                  var self = this;
                  var selectQuestAction = contentElement.find(".gn-nodeActionSelectQuest");
                  contentElement.find(".gn-nodeActionSelectQuest").on("click", function() {
                      DefaultNodeShapes.openQuestSearchDialog().then(function(quest) {
                          selectQuestAction.data("questid", quest.id);
                          selectQuestAction.text(quest.name);
                          self.saveData();
                          
                          questOpenLink.show();
                      });
                  });
  
                  var questText = contentElement.find(".gn-nodeActionQuestText");
                  questText.on("input", function(e) {
                      self.saveData();
                  });
  
                  questOpenLink.on("click", function() {
                      if(selectQuestAction.data("questid"))
                      {
                          window.open("/Aika/Quest?id=" + selectQuestAction.data("questid"));
                      }
                  });
              };
  
              /**
               * Deserializes the data
               */
              Actions.AddQuestTextAction.prototype.deserializeData = function() {
                  var actionData = this.nodeModel.get("actionData");
                  if(!actionData)
                  {
                      return "";
                  }
  
                  var data = JSON.parse(actionData);
                  
                  var questId = "";
                  if(data.questId)
                  {
                      this.contentElement.find(".gn-nodeActionSelectQuest").data("questid", data.questId);
                      questId = data.questId;
                  }
                  else
                  {
                      this.contentElement.find(".gn-nodeActionSelectQuest").data("questid", "");
                  }
  
                  this.contentElement.find(".gn-nodeActionQuestText").val(data.questText);
  
                  return questId;
              }
  
              /**
               * Saves the data
               */
              Actions.AddQuestTextAction.prototype.saveData = function() {
                  // The serialized data is also used in the Aika changeQuestTextInNpcDialogAction. If anything changes this must be taken into consideration.
                  
                  var questId = this.getObjectId();
                  var questText = this.contentElement.find(".gn-nodeActionQuestText").val();
                  var serializeData = {
                      questId: questId,
                      questText: questText
                  };
  
                  this.nodeModel.set("actionData", JSON.stringify(serializeData));
  
                  // Set related object data
                  this.nodeModel.set("actionRelatedToObjectType", GoNorth.DefaultNodeShapes.Actions.RelatedToObjectQuest);
                  this.nodeModel.set("actionRelatedToObjectId", questId);
              }
  
              /**
               * Builds the action
               * 
               * @returns {object} Action
               */
              Actions.AddQuestTextAction.prototype.buildAction = function() {
                  return new Actions.AddQuestTextAction();
              };
  
              /**
               * Returns the type of the action
               * 
               * @returns {number} Type of the action
               */
              Actions.AddQuestTextAction.prototype.getType = function() {
                  return Actions.actionTypeAddQuestToText;
              };
  
              /**
               * Returns the label of the action
               * 
               * @returns {string} Label of the action
               */
              Actions.AddQuestTextAction.prototype.getLabel = function() {
                  return DefaultNodeShapes.Localization.Actions.AddQuestTextLabel;
              };
  
              /**
               * Returns the object type name. Used for dependency objects
               * 
               * @returns {string} Object Type name used for depends on objects 
               */
              Actions.AddQuestTextAction.prototype.getObjectTypeName = function() {
                  return Actions.RelatedToObjectQuest;
              };
  
              /**
               * Returns the object id
               * 
               * @returns {string} Object Id
               */
              Actions.AddQuestTextAction.prototype.getObjectId = function() {
                  return this.contentElement.find(".gn-nodeActionSelectQuest").data("questid");
              };
              
              /**
               * Returns the object resource
               * 
               * @returns {int} Object Resource
               */
              Actions.AddQuestTextAction.prototype.getObjectResource = function() {
                  return GoNorth.DefaultNodeShapes.Shapes.ObjectResourceQuest;
              };
  
              /**
               * Loads the quest
               * 
               * @param {string} questId Quest Id
               * @returns {jQuery.Deferred} Deferred for the quest loading
               */
              Actions.AddQuestTextAction.prototype.loadObject = function(questId) {
                  var def = new jQuery.Deferred();
  
                  GoNorth.HttpClient.get("/api/AikaApi/GetQuest?id=" + questId).done(function(data) {
                      def.resolve(data);
                  }).fail(function(xhr) {
                      def.reject();
                  });
  
                  return def.promise();
              };
  
              /**
               * Returns statistics for the action
               * @param {object} parsedActionData Parsed action data
               * @returns Node statistics
               */
              Actions.AddQuestTextAction.prototype.getStatistics = function(parsedActionData) {
                  return {
                      wordCount: GoNorth.Util.getWordCount(parsedActionData.questText)
                  };
              };
  
              GoNorth.DefaultNodeShapes.Shapes.addAvailableAction(new Actions.AddQuestTextAction());
  
          }(DefaultNodeShapes.Actions = DefaultNodeShapes.Actions || {}));
      }(GoNorth.DefaultNodeShapes = GoNorth.DefaultNodeShapes || {}));
  }(window.GoNorth = window.GoNorth || {}));