<commit_before>/*global angular */

/**
 * @ngdoc directive
 * @name TatUi.directive:messagesItem
 * @restrict AE
 * @description
 * display a route message
 */
angular.module('TatUi').directive('messagesStandardviewItem', function($compile) {
  'use strict';

  return {
    restrict: 'E',
    scope: {
      message: '=',
      topic: '=',
      isTopicDeletableMsg: "=",
      isTopicUpdatableMsg: "=",
      isTopicDeletableAllMsg: "=",
      isTopicUpdatableAllMsg: "=",
      isTopicRw: "="
    },
    replace: true,
    templateUrl: '../build/tatwebui-plugin-standardview/standardview/list/standardview-item.directive.html',
    link: function(scope, element) {
      var listWrapper = element.find('div.tat-replies');
      listWrapper.append(
        '

');
      $compile(listWrapper)(scope);
    },
    controllerAs: 'MessageStandardviewItemCtrl',
    /**
     * @ngdoc controller
     * @name TatUi.controller:messagesItem
     * @requires TatUi.Authentication       Tat Authentication
     * @requires TatUi.TatEngineMessageRsc  Tat Engine Resource Message
     * @requires TatUi.TatEngine            Global Tat Engine service
     *
     * @description Directive controller
     */
    controller: function($scope, $rootScope, TatEngineMessageRsc,
      TatEngineMessagesRsc, TatEngine, TatMessage, Authentication) {
      var self = this;
      this.answerPanel = false;
      this.isTopicBookmarks = false;
      this.isTopicTasks = false;

      this.canDoneMessage = false;
      this.canDeleteFromTasksMessage = false;
      this.canAddToTasksMessage = true;
      this.privateTasksTopic = 'Private/' + Authentication.getIdentity().username + '/Tasks';

      self.setInToDoneText = "";
      this.getBrightness = function(rgb) {
        var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(rgb);
        return result ?
          0.2126 * parseInt(result[1], 16) +
          0.7152 * parseInt(result[2], 16) +
          0.0722 * parseInt(result[3], 16) : 0;
      };

      /**
       * @ngdoc function
       * @name replyMessage
       * @methodOf TatUi.controller:messagesItem
       * @description Reply to a message
       */
      this.replyMessage = function(message) {
        $scope.replying = false;
        TatEngineMessageRsc.create({
          'topic': $scope.topic.topic.indexOf("/") === 0 ? $scope.topic.topic.substr(1) : $scope.topic.topic,
          'idReference': message._id,
          'text': self.replyText
        }).$promise.then(function(resp) {
          self.replyText = "";
          if (!message.replies) {
            message.replies = [];
          }
          message.replies.unshift(resp.message);
        }, function(resp) {
          $scope.replying = true;
          TatEngine.displayReturn(resp);
        });
      };

      this.getText = function() {
        return $scope.message.text;
      };

      this.addLabelDoing = function(message) {
        TatMessage.addLabel(message, $scope.topic.topic, "doing", "#5484ed",
          function() {
              TatMessage.addLabel(message,
              $scope.topic.topic,
              "doing:" + Authentication.getIdentity().username,
              "#5484ed" //blue
          )}
        );
        self.removeLabel(message, "done");
      };

      /**
       * @ngdoc function
       * @name toggleTaskMessage
       * @methodOf TatUi.controller:messagesItem
       * @description create or remove a task from one message
       */
      this.addToTasksMessage = function(message) {
        if (message.topics.length == 1 && self.isTopicTasks) {
          self.addLabelDoing(message);
          return;
        }

        TatEngineMessageRsc.update({
          'idReference': message._id,
          'action': 'task',
          'topic': self.privateTasksTopic
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          self.addLabelDoing(message);
          message.topics.push("/" + self.privateTasksTopic);
          self.computeFlagsTask(message);
        }, function(resp) {
          TatEngine.displayReturn(resp);
        });
      };

      this.deleteFromTasksMessage = function(message) {
        // msg only in tasks topic
        if (message.topics.length == 1 && self.isTopicTasks) {
          self.removeLabel(message, "doing");
          return;
        }

        $scope.setInToDone = false;
        TatEngineMessageRsc.update({
          'idReference': $scope.message._id,
          'action': 'untask',
          'topic': self.privateTasksTopic
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          self.removeLabel(message, "doing");
          if (self.isTopicTasks) {
            message.hide = true;
          }
          self.removePrivateTopicOnLocalMsg(message);
          self.computeFlagsTask(message);
        }, function(resp) {
          TatEngine.displayReturn(resp);
        });
      };

      this.addLabelDone = function(message) {
        TatMessage.addLabel(message, $scope.topic.topic, "done", "#14892c"); // green
        self.removeLabel(message, "doing");
        self.canDoneMessage = false;
      };

      this.removePrivateTopicOnLocalMsg = function(message) {
        message.topics = _.remove(message.topics, function(t) {
          if (t.indexOf("/" + self.privateTasksTopic) === 0) {
            return false;
          }
          return true;
        });
      };

      this.doneMessage = function(message) {
        // msg only in tasks topic
        if (message.topics.length == 1 && self.isTopicTasks) {
          self.addLabelDone(message);
          return;
        }

        $scope.setInToDone = false;
        TatEngineMessageRsc.update({
          'idReference': $scope.message._id,
          'action': 'untask',
          'topic': self.privateTasksTopic
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          self.addLabelDone(message);
          if (self.isTopicTasks) {
            message.hide = true;
          }
          self.removePrivateTopicOnLocalMsg(message);
          self.computeFlagsTask(message);
        }, function(resp) {
          TatEngine.displayReturn(resp);
        });
      };

      /**
       * @ngdoc function
       * @name bookmarkMessage
       * @methodOf TatUi.controller:messagesItem
       * @description create a bookmark from on message
       */
      this.bookmarkMessage = function() {
        var to = 'Private/' + Authentication.getIdentity().username + '/Bookmarks';
        TatEngineMessageRsc.create({
          'idReference': $scope.message._id,
          'action': 'bookmark',
          'topic': to
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          // TODO Refresh msg
        }, function(response) {
          TatEngine.displayReturn(response);
        });
      };

      /**
       * @ngdoc function
       * @name deleteMessage
       * @methodOf TatUi.controller:messagesItem
       * @description delete a message from a Private topic
       */
      this.deleteMessage = function(message) {
        TatEngineMessagesRsc.delete({
          'idMessageToDelete': message._id,
          'cascade': 'cascade/'
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          message.hide = true;
          message.displayed = false;
        }, function(response) {
          TatEngine.displayReturn(response);
        });
      };

      /**
       * @ngdoc function
       * @name updateMessage
       * @methodOf TatUi.controller:messagesItem
       * @description Update a message
       */
      this.updateMessage = function(message) {
        message.updating = false;
        TatEngineMessageRsc.update({
          'topic': $scope.topic.topic.indexOf("/") === 0 ? $scope.topic.topic.substr(1) : $scope.topic.topic,
          'idReference': message._id,
          'text': message.text,
          'action': 'update',
        }).$promise.then(function(resp) {
          message.text = resp.message.text;
        }, function(resp) {
          message.updating = true;
          TatEngine.displayReturn(resp);
        });
      };

      /**
       * @ngdoc function
       * @name hasLiked
       * @methodOf TatUi.controller:messagesItem
       * @description Define if the message is marked 'like'
       * @return {bool} If true, 'like'
       */
      this.hasLiked = function(message) {
        if (message && message.likers) {
          return _.include(message.likers, Authentication.getIdentity()
            .username);
        }
        return false;
      };

      /**
       * @ngdoc function
       * @name toggleLikeMessage
       * @methodOf TatUi.controller:messagesItem
       * @description toggle 'like' state on the message
       *
       */
      this.toggleLikeMessage = function(message) {
        var action = self.hasLiked(message) ? 'unlike' : 'like';
        TatEngineMessageRsc.update({
          'topic': $scope.topic.topic.indexOf("/") === 0 ? $scope.topic.topic.substr(1) : $scope.topic.topic,
          'idReference': message._id,
          'action': action
        }).$promise.then(function(resp) {
          if (action === 'like') {
            if (!message.likers) {
              message.likers = [];
            }
            message.likers.push(Authentication.getIdentity().username);
            message.nbLikes++;
          } else {
            message.likers = _.remove(message.likers,
              Authentication.getIdentity().username);
            message.nbLikes--;
          }
        }, function(err) {
          TatEngine.displayReturn(err);
        });
      };

      /**
       * @ngdoc function
       * @name removeLabel
       * @methodOf TatUi.controller:messagesItem
       * @description remove a label
       * @param {object} message Message on which to add a label
       * @param {object} label   Label {text} to remove
       */
      this.removeLabel = function(message, labelText) {
        if (!message.labels) {
          return;
        }
        var toRefresh = false;
        var newList = [];
        for (var i = 0; i < message.labels.length; i++) {
          var l = message.labels[i];
          if (l.text === labelText ||  (labelText === 'doing' && l.text
              .indexOf('doing:') === 0)) {
            toRefresh = true;
            TatEngineMessageRsc.update({
              'action': 'unlabel',
              'topic': $scope.topic.topic.indexOf("/") === 0 ? $scope.topic.topic.substr(1) : $scope.topic.topic,
              'idReference': $scope.message._id,
              'text': l.text
            }).$promise.then(function(resp) {
              //nothing here
            }, function(resp) {
              TatEngine.displayReturn(resp);
            });
          } else {
            newList.push(l);
          }
        }

        if (toRefresh)  {
          message.labels = newList;
        }
        self.computeFlagsTask(message);
      };

      this.urlMessage = function(message) {
        $rootScope.$broadcast('topic-change', {
          topic: $scope.topic.topic,
          idMessage: message._id,
          reload: true
        });
      };

      this.containsLabel = function(message, labelText) {
        if (message.inReplyOfIDRoot) {
          return false;
        }
        var r = false;
        if (message.labels) {
          for (var i = 0; i < message.labels.length; i++) {
            var l = message.labels[i];
            if (l.text === labelText) {
              return true;
            }
          }
        }
        return r;
      };

      this.init = function(message) {
        if ($scope.topic.topic.indexOf("Private/" + Authentication.getIdentity()
            .username + "/Bookmarks") === 0) {
          self.isTopicBookmarks = true;
        } else if ($scope.topic.topic.indexOf(self.privateTasksTopic) === 0) {
          self.isTopicTasks = true;
        }
        this.computeFlagsTask(message);
      };

      this.computeFlagsTask = function(message) {
        self.canDoneMessage = false;
        self.canDeleteFromTasksMessage = false;
        self.canAddToTasksMessage = true;
        for (var i = 0; i < message.topics.length; i++) {
          if (message.topics[i].indexOf("/" + self.privateTasksTopic) === 0) {
            if (!self.containsLabel(message, "done")) {
              self.canDoneMessage = true;
            }
            // if msg is not only in tasks topic
            if (message.topics.length > 1) {
              self.canDeleteFromTasksMessage = true;
              $scope.isTopicDeletableMsg = false;
              $scope.isTopicDeletableAllMsg = false;
            } else {
              $scope.isTopicDeletableMsg = true;
              $scope.isTopicDeletableAllMsg = true;
            }
          }
        };
        if (self.canDoneMessage || self.isTopicTasks) {
          self.canAddToTasksMessage = false;
        }
      };

      this.init($scope.message);

    }
  };
});
<commit_msg>fix: url topic name<commit_after>/*global angular */

/**
 * @ngdoc directive
 * @name TatUi.directive:messagesItem
 * @restrict AE
 * @description
 * display a route message
 */
angular.module('TatUi').directive('messagesStandardviewItem', function($compile) {
  'use strict';

  return {
    restrict: 'E',
    scope: {
      message: '=',
      topic: '=',
      isTopicDeletableMsg: "=",
      isTopicUpdatableMsg: "=",
      isTopicDeletableAllMsg: "=",
      isTopicUpdatableAllMsg: "=",
      isTopicRw: "="
    },
    replace: true,
    templateUrl: '../build/tatwebui-plugin-standardview/standardview/list/standardview-item.directive.html',
    link: function(scope, element) {
      var listWrapper = element.find('div.tat-replies');
      listWrapper.append(
        '

');
      $compile(listWrapper)(scope);
    },
    controllerAs: 'MessageStandardviewItemCtrl',
    /**
     * @ngdoc controller
     * @name TatUi.controller:messagesItem
     * @requires TatUi.Authentication       Tat Authentication
     * @requires TatUi.TatEngineMessageRsc  Tat Engine Resource Message
     * @requires TatUi.TatEngine            Global Tat Engine service
     *
     * @description Directive controller
     */
    controller: function($scope, $rootScope, TatEngineMessageRsc,
      TatEngineMessagesRsc, TatEngine, TatMessage, Authentication) {
      var self = this;
      this.answerPanel = false;
      this.isTopicBookmarks = false;
      this.isTopicTasks = false;

      this.canDoneMessage = false;
      this.canDeleteFromTasksMessage = false;
      this.canAddToTasksMessage = true;
      this.privateTasksTopic = 'Private/' + Authentication.getIdentity().username + '/Tasks';

      self.setInToDoneText = "";
      this.getBrightness = function(rgb) {
        var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(rgb);
        return result ?
          0.2126 * parseInt(result[1], 16) +
          0.7152 * parseInt(result[2], 16) +
          0.0722 * parseInt(result[3], 16) : 0;
      };

      /**
       * @ngdoc function
       * @name replyMessage
       * @methodOf TatUi.controller:messagesItem
       * @description Reply to a message
       */
      this.replyMessage = function(message) {
        $scope.replying = false;
        TatEngineMessageRsc.create({
          'topic': $scope.topic.topic.indexOf("/") === 0 ? $scope.topic.topic.substr(1) : $scope.topic.topic,
          'idReference': message._id,
          'text': self.replyText
        }).$promise.then(function(resp) {
          self.replyText = "";
          if (!message.replies) {
            message.replies = [];
          }
          message.replies.unshift(resp.message);
        }, function(resp) {
          $scope.replying = true;
          TatEngine.displayReturn(resp);
        });
      };

      this.getText = function() {
        return $scope.message.text;
      };

      this.addLabelDoing = function(message) {
        TatMessage.addLabel(message, $scope.topic.topic, "doing", "#5484ed",
          function() {
              TatMessage.addLabel(message,
              $scope.topic.topic,
              "doing:" + Authentication.getIdentity().username,
              "#5484ed" //blue
          )}
        );
        self.removeLabel(message, "done");
      };

      /**
       * @ngdoc function
       * @name toggleTaskMessage
       * @methodOf TatUi.controller:messagesItem
       * @description create or remove a task from one message
       */
      this.addToTasksMessage = function(message) {
        if (message.topics.length == 1 && self.isTopicTasks) {
          self.addLabelDoing(message);
          return;
        }

        TatEngineMessageRsc.update({
          'idReference': message._id,
          'action': 'task',
          'topic': self.privateTasksTopic
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          self.addLabelDoing(message);
          message.topics.push("/" + self.privateTasksTopic);
          self.computeFlagsTask(message);
        }, function(resp) {
          TatEngine.displayReturn(resp);
        });
      };

      this.deleteFromTasksMessage = function(message) {
        // msg only in tasks topic
        if (message.topics.length == 1 && self.isTopicTasks) {
          self.removeLabel(message, "doing");
          return;
        }

        $scope.setInToDone = false;
        TatEngineMessageRsc.update({
          'idReference': $scope.message._id,
          'action': 'untask',
          'topic': self.privateTasksTopic
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          self.removeLabel(message, "doing");
          if (self.isTopicTasks) {
            message.hide = true;
          }
          self.removePrivateTopicOnLocalMsg(message);
          self.computeFlagsTask(message);
        }, function(resp) {
          TatEngine.displayReturn(resp);
        });
      };

      this.addLabelDone = function(message) {
        TatMessage.addLabel(message, $scope.topic.topic, "done", "#14892c"); // green
        self.removeLabel(message, "doing");
        self.canDoneMessage = false;
      };

      this.removePrivateTopicOnLocalMsg = function(message) {
        message.topics = _.remove(message.topics, function(t) {
          if (t.indexOf("/" + self.privateTasksTopic) === 0) {
            return false;
          }
          return true;
        });
      };

      this.doneMessage = function(message) {
        // msg only in tasks topic
        if (message.topics.length == 1 && self.isTopicTasks) {
          self.addLabelDone(message);
          return;
        }

        $scope.setInToDone = false;
        TatEngineMessageRsc.update({
          'idReference': $scope.message._id,
          'action': 'untask',
          'topic': self.privateTasksTopic
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          self.addLabelDone(message);
          if (self.isTopicTasks) {
            message.hide = true;
          }
          self.removePrivateTopicOnLocalMsg(message);
          self.computeFlagsTask(message);
        }, function(resp) {
          TatEngine.displayReturn(resp);
        });
      };

      /**
       * @ngdoc function
       * @name bookmarkMessage
       * @methodOf TatUi.controller:messagesItem
       * @description create a bookmark from on message
       */
      this.bookmarkMessage = function() {
        var to = 'Private/' + Authentication.getIdentity().username + '/Bookmarks';
        TatEngineMessageRsc.create({
          'idReference': $scope.message._id,
          'action': 'bookmark',
          'topic': to
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          // TODO Refresh msg
        }, function(response) {
          TatEngine.displayReturn(response);
        });
      };

      /**
       * @ngdoc function
       * @name deleteMessage
       * @methodOf TatUi.controller:messagesItem
       * @description delete a message from a Private topic
       */
      this.deleteMessage = function(message) {
        TatEngineMessagesRsc.delete({
          'idMessageToDelete': message._id,
          'cascade': 'cascade/'
        }).$promise.then(function(resp) {
          TatEngine.displayReturn(resp);
          message.hide = true;
          message.displayed = false;
        }, function(response) {
          TatEngine.displayReturn(response);
        });
      };

      /**
       * @ngdoc function
       * @name updateMessage
       * @methodOf TatUi.controller:messagesItem
       * @description Update a message
       */
      this.updateMessage = function(message) {
        message.updating = false;
        TatEngineMessageRsc.update({
          'topic': $scope.topic.topic.indexOf("/") === 0 ? $scope.topic.topic.substr(1) : $scope.topic.topic,
          'idReference': message._id,
          'text': message.text,
          'action': 'update',
        }).$promise.then(function(resp) {
          message.text = resp.message.text;
        }, function(resp) {
          message.updating = true;
          TatEngine.displayReturn(resp);
        });
      };

      /**
       * @ngdoc function
       * @name hasLiked
       * @methodOf TatUi.controller:messagesItem
       * @description Define if the message is marked 'like'
       * @return {bool} If true, 'like'
       */
      this.hasLiked = function(message) {
        if (message && message.likers) {
          return _.include(message.likers, Authentication.getIdentity().username);
        }
        return false;
      };

      /**
       * @ngdoc function
       * @name toggleLikeMessage
       * @methodOf TatUi.controller:messagesItem
       * @description toggle 'like' state on the message
       *
       */
      this.toggleLikeMessage = function(message) {
        var action = self.hasLiked(message) ? 'unlike' : 'like';
        TatEngineMessageRsc.update({
          'topic': $scope.topic.topic.indexOf("/") === 0 ? $scope.topic.topic.substr(1) : $scope.topic.topic,
          'idReference': message._id,
          'action': action
        }).$promise.then(function(resp) {
          if (action === 'like') {
            if (!message.likers) {
              message.likers = [];
            }
            message.likers.push(Authentication.getIdentity().username);
            message.nbLikes++;
          } else {
            message.likers = _.remove(message.likers,
              Authentication.getIdentity().username);
            message.nbLikes--;
          }
        }, function(err) {
          TatEngine.displayReturn(err);
        });
      };

      /**
       * @ngdoc function
       * @name removeLabel
       * @methodOf TatUi.controller:messagesItem
       * @description remove a label
       * @param {object} message Message on which to add a label
       * @param {object} label   Label {text} to remove
       */
      this.removeLabel = function(message, labelText) {
        if (!message.labels) {
          return;
        }
        var toRefresh = false;
        var newList = [];
        for (var i = 0; i < message.labels.length; i++) {
          var l = message.labels[i];
          if (l.text === labelText ||  (labelText === 'doing' && l.text
              .indexOf('doing:') === 0)) {
            toRefresh = true;
            TatEngineMessageRsc.update({
              'action': 'unlabel',
              'topic': $scope.topic.topic.indexOf("/") === 0 ? $scope.topic.topic.substr(1) : $scope.topic.topic,
              'idReference': $scope.message._id,
              'text': l.text
            }).$promise.then(function(resp) {
              //nothing here
            }, function(resp) {
              TatEngine.displayReturn(resp);
            });
          } else {
            newList.push(l);
          }
        }

        if (toRefresh)  {
          message.labels = newList;
        }
        self.computeFlagsTask(message);
      };

      this.urlMessage = function(message) {
        $rootScope.$broadcast('topic-change', {
          topic: $scope.topic.topic.indexOf("/") === 0 ? $scope.topic.topic.substr(1) : $scope.topic.topic,
          idMessage: message._id,
          reload: true
        });
      };

      this.containsLabel = function(message, labelText) {
        if (message.inReplyOfIDRoot) {
          return false;
        }
        var r = false;
        if (message.labels) {
          for (var i = 0; i < message.labels.length; i++) {
            var l = message.labels[i];
            if (l.text === labelText) {
              return true;
            }
          }
        }
        return r;
      };

      this.init = function(message) {
        if ($scope.topic.topic.indexOf("Private/" + Authentication.getIdentity()
            .username + "/Bookmarks") === 0) {
          self.isTopicBookmarks = true;
        } else if ($scope.topic.topic.indexOf(self.privateTasksTopic) === 0) {
          self.isTopicTasks = true;
        }
        this.computeFlagsTask(message);
      };

      this.computeFlagsTask = function(message) {
        self.canDoneMessage = false;
        self.canDeleteFromTasksMessage = false;
        self.canAddToTasksMessage = true;
        for (var i = 0; i < message.topics.length; i++) {
          if (message.topics[i].indexOf("/" + self.privateTasksTopic) === 0) {
            if (!self.containsLabel(message, "done")) {
              self.canDoneMessage = true;
            }
            // if msg is not only in tasks topic
            if (message.topics.length > 1) {
              self.canDeleteFromTasksMessage = true;
              $scope.isTopicDeletableMsg = false;
              $scope.isTopicDeletableAllMsg = false;
            } else {
              $scope.isTopicDeletableMsg = true;
              $scope.isTopicDeletableAllMsg = true;
            }
          }
        };
        if (self.canDoneMessage || self.isTopicTasks) {
          self.canAddToTasksMessage = false;
        }
      };

      this.init($scope.message);

    }
  };
});
<|endoftext|>


<commit_before>Ext.namespace('Vps.Component');
Vps.Component.Pages = Ext.extend(Ext.Panel, {
    initComponent : function()
    {
        this.actions = {};
        this.componentConfigs = {};

        this.pageButtonMenu = new Ext.menu.Menu({
            items    : [
                '-',
                this.getAction('properties'),
                this.getAction('add'),
                this.getAction('delete'),
                this.getAction('visible'),
                this.getAction('makeHome'),
                this.getAction('preview')
            ]
        });
        this.pageButton = new Ext.Toolbar.Button({
            cls     : 'x-btn-text-icon bmenu',
            text    : trlVps('Page'),
            menu    : this.pageButtonMenu,
            icon    : '/assets/silkicons/page.png',
            disabled: true
        });

        this.treePanel = new Vps.Auto.TreePanel({
            controllerUrl: '/admin/component/pages',
            title       : trlVps('Seitenbaum'),
            region      : 'west',
            split       : true,
            width       : 300,
            collapsible : true,
            minSize     : 200,
            maxSize     : 600,
            autoScroll: true,
            tbar: []
        });

        var tbar = this.treePanel.getTopToolbar();
        tbar.add(this.pageButton);

        tbar.add('-');
        tbar.add(trlVps('Search: '));

        var filter = new Vps.Auto.Filter.Text({name: 'text', 'paramName': 'query'});
        filter.on('filter', function(f, params) {
            this.applyBaseParams(params);
            this.reload();
        }, this.treePanel);
        filter.getToolbarItem().each(function(i) {
            tbar.add(i);
        });

        tbar.add('->');
        tbar.add(this.treePanel.getAction('reload'));

        this.treePanel.onMoved = function (response) {
            this.tree.getRootNode().reload();
        };

        this.contentTabPanel = new Ext.TabPanel({
            region      : 'center'
        });
        this.contentTabPanel.on('render', function() {
            this.contentTabPanel.strip.setHeight(24);
        }, this);

        this.layout = 'border';
        this.items = [this.treePanel, this.contentTabPanel];

        Vps.Component.Pages.superclass.initComponent.call(this);

        this.treePanel.on('loaded', this.onTreePanelLoaded, this);
        this.setupEditform();

        this.editActions = {};
    },
    setupEditform : function ()
    {
       this.editDialog = new Vps.Auto.Form.Window({
            width: 400,
            height: 400,
            controllerUrl: ' '
        });
        this.editDialog.on('datachange', function(test) {
            this.treePanel.tree.root.reload();
        }, this);
    },

    onTreePanelLoaded : function(tree)
    {
        tree.loader.on('load', function(tree, node, response) {
            var result = Ext.decode(response.responseText);
            Ext.applyIf(this.componentConfigs, result.componentConfigs);
        }, this);

        this.contextMenu = new Ext.menu.Menu({
             items: [
                '-',
                this.getAction('properties'),
                this.getAction('add'),
                this.getAction('delete'),
                this.getAction('visible'),
                this.getAction('makeHome'),
                this.getAction('preview')
            ]
        });

        tree.on('click', this.treeSelectionchange, this);
        tree.on('contextmenu', function (node) {
            node.select();
            this.treeSelectionchange(node);
            this.contextMenu.show(node.ui.getAnchor());
        }, this);

        tree.on('dblclick', function (o, e) {
            var action;
            for (var i in this.editActions) {
                if (!this.editActions[i].isHidden()) {
                    action = this.editActions[i];
                }
            }
            if (action) {
                action.execute(action.initialConfig);
            }
        }, this);

    },

    treeSelectionchange : function (node) {
        if (!node) return;
        var data = node.attributes;

        this.editDialog.getAutoForm().editControllerUrl = data.editControllerUrl;
        this.editDialog.getAutoForm().addControllerUrl = data.addControllerUrl;

        if (data.disabled) {
            this.pageButton.disable();
        } else {
            this.pageButton.enable();
        }

        for (var action in data.actions) {
        	if (data.actions[action]) {
                this.getAction(action).enable();
        	} else {
                this.getAction(action).disable();
        	}
        }

        this.contextMenu.items.each(function(i) {
            if (i.initialConfig.actionKey) {
                this.contextMenu.remove(i);
            }
        }, this);
        this.pageButtonMenu.items.each(function(i) {
            if (i.initialConfig.actionKey) {
                this.pageButtonMenu.remove(i);
            }
        }, this);
        var actionsAdded = 0;
        data.editComponents.each(function(editComponent) {
            var actionKey = editComponent.componentClass+'-'+editComponent.type;
            if (!this.editActions[actionKey]) {
                this.editActions[actionKey] = new Ext.Action({
                    text    : this.componentConfigs[actionKey].title,
                    handler : function (o, e) {
                        var node = this.treePanel.tree.getSelectionModel().getSelectedNode();
                        node.attributes.editComponents.each(function(editComponent) {
                            if (editComponent.componentClass+'-'+editComponent.type == o.actionKey) {
                                this.loadComponent({
                                    id: editComponent.componentId,
                                    componentClass: editComponent.componentClass,
                                    type: editComponent.type,
                                    text: node.text,
                                    icon: node.attributes.bIcon,
                                    editComponents: node.attributes.editComponents,
                                    pageId: node.attributes.id
                                });
                                return false;
                            }
                        }, this);
                    },
                    icon    : this.componentConfigs[actionKey].icon,
                    cls     : 'x-btn-text-icon',
                    scope   : this,
                    actionKey: actionKey
                });
            }
            this.editActions[actionKey].setDisabled(data.disabled);
            this.contextMenu.insert(actionsAdded, new Ext.menu.Item(this.editActions[actionKey]));
            this.pageButtonMenu.insert(actionsAdded, new Ext.menu.Item(this.editActions[actionKey]));
            actionsAdded++;
        }, this);
    },

    loadComponent: function(data)
    {
        var panel = this.contentTabPanel.getItem('page'+data.pageId);
        if (!panel) {
            panel = this.createComponentPanel(data);
            this.contentTabPanel.add(panel);
        }
        this.contentTabPanel.setActiveTab(panel);

        panel.applyBaseParams({
            id: data.id
        });
        panel.mainComponentText = data.text;
        panel.mainComponentIcon = data.icon;
        panel.load({
            componentClass: data.componentClass,
            type: data.type,
            editComponents: data.editComponents
        });
    },

    createComponentPanel: function(data)
    {
        var panel = new Vps.Component.ComponentPanel({
            id          : 'page'+data.pageId,
            title       : data.text,
            closable    : true,
            autoLoad    : false,
            componentConfigs : this.componentConfigs
        });
        return panel;
    },

    getAction : function(type)
    {
        if (this.actions[type]) return this.actions[type];

        if (type == 'properties') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Page properties'),
                handler : function () {
                    var form = this.editDialog.getAutoForm();
                    form.controllerUrl = form.editControllerUrl;
                    if (form.formPanel) {
                        form.remove(form.formPanel, true);
                        this.editDialog.getAutoForm().formPanel = null;
                    }
                    var node = this.treePanel.tree.selModel.selNode;
                    this.editDialog.getAutoForm().setBaseParams({
                        componentId: node.attributes.editControllerComponentId
                    });
                    this.editDialog.showEdit(node.id);
                },
                icon    : '/assets/silkicons/page_gear.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'add') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Add new child page'),
                handler : function () {
            		var form = this.editDialog.getAutoForm();
                    form.controllerUrl = form.addControllerUrl;
	                if (form.formPanel) {
	                    form.remove(form.formPanel, true);
	                    this.editDialog.getAutoForm().formPanel = null;
	                }
                    var node = this.treePanel.tree.selModel.selNode;
                    this.editDialog.getAutoForm().setBaseParams({
                        componentId: node.attributes.editControllerComponentId,
                        parent_id: node.id
                    });
                    this.editDialog.showAdd();
                },
                icon    : '/assets/silkicons/page_add.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'delete') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Delete page'),
                handler : function() {
                    this.treePanel.onDelete();
                },
                icon    : '/assets/silkicons/page_delete.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'visible') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Show / hide page'),
                handler : function() {
                    this.treePanel.onVisible();
                },
                icon    : '/assets/fx_invisible/silkicons/page.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'makeHome') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Use as homepage'),
                handler : function (o, e) {
                    Ext.Msg.show({
                        title: trlVps('Use as homepage'),
                        msg: trlVps('Attention! You are about to set the selected page as the homepage of your website. This may affect the entire website. Do you wish to proceed?'),
                        buttons: Ext.Msg.YESNO,
                        icon: Ext.MessageBox.WARNING,
                        fn: function(btn, text) {
                            if (btn == 'yes') {
                                Ext.Ajax.request({
                                    url: '/admin/component/pages/json-make-home',
                                    success: function(r) {
                                        response = Ext.decode(r.responseText);
                                        var oldhome = this.treePanel.tree.getNodeById(response.oldhome);
                                        oldhome.attributes.visible = response.oldhomeVisible;
                                        this.treePanel.setVisible(oldhome);
                                        oldhome.ui.iconNode.style.backgroundImage = 'url(/assets/silkicons/page.png)';
                                        var home = this.treePanel.tree.getNodeById(response.home);
                                        home.ui.iconNode.style.backgroundImage = 'url(/assets/silkicons/application_home.png)';
                                    },
                                    params: {id: this.treePanel.tree.getSelectionModel().getSelectedNode().id },
                                    scope: this
                                });
                            }
                        },
                        scope: this
                    });
                },
                icon    : '/assets/silkicons/application_home.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'expand') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Expand here'),
                handler : function () { this.treePanel.tree.getSelectionModel().getSelectedNode().expand(true); },
                icon    : '/assets/silkicons/bullet_add.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'collapse') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Collapse here'),
                handler : function () { this.treePanel.tree.getSelectionModel().getSelectedNode().collapse(true); },
                icon    : '/assets/silkicons/bullet_delete.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'preview') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Open preview'),
                handler : function () {
                    window.open('/admin/component/pages/open-preview?page_id='+
                                this.treePanel.getSelectedId());
                },
                icon    : '/assets/silkicons/page_white_magnify.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else {
            throw 'unknown action-type: ' + type;
        }
        return this.actions[type];
    }

});

Ext.reg('vps.component.pages', Vps.Component.Pages);
<commit_msg>ersten menuepunkt vom contextmenue bei doppelklick ausfuehren<commit_after>Ext.namespace('Vps.Component');
Vps.Component.Pages = Ext.extend(Ext.Panel, {
    initComponent : function()
    {
        this.actions = {};
        this.componentConfigs = {};

        this.pageButtonMenu = new Ext.menu.Menu({
            items    : [
                '-',
                this.getAction('properties'),
                this.getAction('add'),
                this.getAction('delete'),
                this.getAction('visible'),
                this.getAction('makeHome'),
                this.getAction('preview')
            ]
        });
        this.pageButton = new Ext.Toolbar.Button({
            cls     : 'x-btn-text-icon bmenu',
            text    : trlVps('Page'),
            menu    : this.pageButtonMenu,
            icon    : '/assets/silkicons/page.png',
            disabled: true
        });

        this.treePanel = new Vps.Auto.TreePanel({
            controllerUrl: '/admin/component/pages',
            title       : trlVps('Seitenbaum'),
            region      : 'west',
            split       : true,
            width       : 300,
            collapsible : true,
            minSize     : 200,
            maxSize     : 600,
            autoScroll: true,
            tbar: []
        });

        var tbar = this.treePanel.getTopToolbar();
        tbar.add(this.pageButton);

        tbar.add('-');
        tbar.add(trlVps('Search: '));

        var filter = new Vps.Auto.Filter.Text({name: 'text', 'paramName': 'query'});
        filter.on('filter', function(f, params) {
            this.applyBaseParams(params);
            this.reload();
        }, this.treePanel);
        filter.getToolbarItem().each(function(i) {
            tbar.add(i);
        });

        tbar.add('->');
        tbar.add(this.treePanel.getAction('reload'));

        this.treePanel.onMoved = function (response) {
            this.tree.getRootNode().reload();
        };

        this.contentTabPanel = new Ext.TabPanel({
            region      : 'center'
        });
        this.contentTabPanel.on('render', function() {
            this.contentTabPanel.strip.setHeight(24);
        }, this);

        this.layout = 'border';
        this.items = [this.treePanel, this.contentTabPanel];

        Vps.Component.Pages.superclass.initComponent.call(this);

        this.treePanel.on('loaded', this.onTreePanelLoaded, this);
        this.setupEditform();

        this.editActions = {};
    },
    setupEditform : function ()
    {
       this.editDialog = new Vps.Auto.Form.Window({
            width: 400,
            height: 400,
            controllerUrl: ' '
        });
        this.editDialog.on('datachange', function(test) {
            this.treePanel.tree.root.reload();
        }, this);
    },

    onTreePanelLoaded : function(tree)
    {
        tree.loader.on('load', function(tree, node, response) {
            var result = Ext.decode(response.responseText);
            Ext.applyIf(this.componentConfigs, result.componentConfigs);
        }, this);

        this.contextMenu = new Ext.menu.Menu({
             items: [
                '-',
                this.getAction('properties'),
                this.getAction('add'),
                this.getAction('delete'),
                this.getAction('visible'),
                this.getAction('makeHome'),
                this.getAction('preview')
            ]
        });

        tree.on('click', this.treeSelectionchange, this);
        tree.on('contextmenu', function (node) {
            node.select();
            this.treeSelectionchange(node);
            this.contextMenu.show(node.ui.getAnchor());
        }, this);

        tree.on('dblclick', function (o, e) {
            var i = this.contextMenu.items.first();
            if (i) {
                i.handler.call(i.scope, i, e);
            }
        }, this);

    },

    treeSelectionchange : function (node) {
        if (!node) return;
        var data = node.attributes;

        this.editDialog.getAutoForm().editControllerUrl = data.editControllerUrl;
        this.editDialog.getAutoForm().addControllerUrl = data.addControllerUrl;

        if (data.disabled) {
            this.pageButton.disable();
        } else {
            this.pageButton.enable();
        }

        for (var action in data.actions) {
        	if (data.actions[action]) {
                this.getAction(action).enable();
        	} else {
                this.getAction(action).disable();
        	}
        }

        this.contextMenu.items.each(function(i) {
            if (i.initialConfig.actionKey) {
                this.contextMenu.remove(i);
            }
        }, this);
        this.pageButtonMenu.items.each(function(i) {
            if (i.initialConfig.actionKey) {
                this.pageButtonMenu.remove(i);
            }
        }, this);
        var actionsAdded = 0;
        data.editComponents.each(function(editComponent) {
            var actionKey = editComponent.componentClass+'-'+editComponent.type;
            if (!this.editActions[actionKey]) {
                this.editActions[actionKey] = new Ext.Action({
                    text    : this.componentConfigs[actionKey].title,
                    handler : function (o, e) {
                        var node = this.treePanel.tree.getSelectionModel().getSelectedNode();
                        node.attributes.editComponents.each(function(editComponent) {
                            if (editComponent.componentClass+'-'+editComponent.type == o.actionKey) {
                                this.loadComponent({
                                    id: editComponent.componentId,
                                    componentClass: editComponent.componentClass,
                                    type: editComponent.type,
                                    text: node.text,
                                    icon: node.attributes.bIcon,
                                    editComponents: node.attributes.editComponents,
                                    pageId: node.attributes.id
                                });
                                return false;
                            }
                        }, this);
                    },
                    icon    : this.componentConfigs[actionKey].icon,
                    cls     : 'x-btn-text-icon',
                    scope   : this,
                    actionKey: actionKey
                });
            }
            this.editActions[actionKey].setDisabled(data.disabled);
            this.contextMenu.insert(actionsAdded, new Ext.menu.Item(this.editActions[actionKey]));
            this.pageButtonMenu.insert(actionsAdded, new Ext.menu.Item(this.editActions[actionKey]));
            actionsAdded++;
        }, this);
    },

    loadComponent: function(data)
    {
        var panel = this.contentTabPanel.getItem('page'+data.pageId);
        if (!panel) {
            panel = this.createComponentPanel(data);
            this.contentTabPanel.add(panel);
        }
        this.contentTabPanel.setActiveTab(panel);

        panel.applyBaseParams({
            id: data.id
        });
        panel.mainComponentText = data.text;
        panel.mainComponentIcon = data.icon;
        panel.load({
            componentClass: data.componentClass,
            type: data.type,
            editComponents: data.editComponents
        });
    },

    createComponentPanel: function(data)
    {
        var panel = new Vps.Component.ComponentPanel({
            id          : 'page'+data.pageId,
            title       : data.text,
            closable    : true,
            autoLoad    : false,
            componentConfigs : this.componentConfigs
        });
        return panel;
    },

    getAction : function(type)
    {
        if (this.actions[type]) return this.actions[type];

        if (type == 'properties') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Page properties'),
                handler : function () {
                    var form = this.editDialog.getAutoForm();
                    form.controllerUrl = form.editControllerUrl;
                    if (form.formPanel) {
                        form.remove(form.formPanel, true);
                        this.editDialog.getAutoForm().formPanel = null;
                    }
                    var node = this.treePanel.tree.selModel.selNode;
                    this.editDialog.getAutoForm().setBaseParams({
                        componentId: node.attributes.editControllerComponentId
                    });
                    this.editDialog.showEdit(node.id);
                },
                icon    : '/assets/silkicons/page_gear.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'add') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Add new child page'),
                handler : function () {
            		var form = this.editDialog.getAutoForm();
                    form.controllerUrl = form.addControllerUrl;
	                if (form.formPanel) {
	                    form.remove(form.formPanel, true);
	                    this.editDialog.getAutoForm().formPanel = null;
	                }
                    var node = this.treePanel.tree.selModel.selNode;
                    this.editDialog.getAutoForm().setBaseParams({
                        componentId: node.attributes.editControllerComponentId,
                        parent_id: node.id
                    });
                    this.editDialog.showAdd();
                },
                icon    : '/assets/silkicons/page_add.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'delete') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Delete page'),
                handler : function() {
                    this.treePanel.onDelete();
                },
                icon    : '/assets/silkicons/page_delete.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'visible') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Show / hide page'),
                handler : function() {
                    this.treePanel.onVisible();
                },
                icon    : '/assets/fx_invisible/silkicons/page.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'makeHome') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Use as homepage'),
                handler : function (o, e) {
                    Ext.Msg.show({
                        title: trlVps('Use as homepage'),
                        msg: trlVps('Attention! You are about to set the selected page as the homepage of your website. This may affect the entire website. Do you wish to proceed?'),
                        buttons: Ext.Msg.YESNO,
                        icon: Ext.MessageBox.WARNING,
                        fn: function(btn, text) {
                            if (btn == 'yes') {
                                Ext.Ajax.request({
                                    url: '/admin/component/pages/json-make-home',
                                    success: function(r) {
                                        response = Ext.decode(r.responseText);
                                        var oldhome = this.treePanel.tree.getNodeById(response.oldhome);
                                        oldhome.attributes.visible = response.oldhomeVisible;
                                        this.treePanel.setVisible(oldhome);
                                        oldhome.ui.iconNode.style.backgroundImage = 'url(/assets/silkicons/page.png)';
                                        var home = this.treePanel.tree.getNodeById(response.home);
                                        home.ui.iconNode.style.backgroundImage = 'url(/assets/silkicons/application_home.png)';
                                    },
                                    params: {id: this.treePanel.tree.getSelectionModel().getSelectedNode().id },
                                    scope: this
                                });
                            }
                        },
                        scope: this
                    });
                },
                icon    : '/assets/silkicons/application_home.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'expand') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Expand here'),
                handler : function () { this.treePanel.tree.getSelectionModel().getSelectedNode().expand(true); },
                icon    : '/assets/silkicons/bullet_add.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'collapse') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Collapse here'),
                handler : function () { this.treePanel.tree.getSelectionModel().getSelectedNode().collapse(true); },
                icon    : '/assets/silkicons/bullet_delete.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else if (type == 'preview') {
            this.actions[type] = new Ext.Action({
                text    : trlVps('Open preview'),
                handler : function () {
                    window.open('/admin/component/pages/open-preview?page_id='+
                                this.treePanel.getSelectedId());
                },
                icon    : '/assets/silkicons/page_white_magnify.png',
                cls     : 'x-btn-text-icon',
                scope   : this
            });
        } else {
            throw 'unknown action-type: ' + type;
        }
        return this.actions[type];
    }

});

Ext.reg('vps.component.pages', Vps.Component.Pages);
<|endoftext|>


<commit_before>/*!
 * Start Bootstrap - Freelancer Bootstrap Theme (http://startbootstrap.com)
 * Code licensed under the Apache License v2.0.
 * For details, see http://www.apache.org/licenses/LICENSE-2.0.
 */

// jQuery for page scrolling feature - requires jQuery Easing plugin
$(function() {
    $('body').on('click', '.page-scroll a', function(event) {
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: $($anchor.attr('href')).offset().top
        }, 1500, 'easeInOutExpo');
        event.preventDefault();
    });
});

// Floating label headings for the contact form
$(function() {
    $("body").on("input propertychange", ".floating-label-form-group", function(e) {
        $(this).toggleClass("floating-label-form-group-with-value", !! $(e.target).val());
    }).on("focus", ".floating-label-form-group", function() {
        $(this).addClass("floating-label-form-group-with-focus");
    }).on("blur", ".floating-label-form-group", function() {
        $(this).removeClass("floating-label-form-group-with-focus");
    });
});

// Highlight the top nav as scrolling occurs
$('body').scrollspy({
    target: '.navbar-fixed-top'
})

// Closes the Responsive Menu on Menu Item Click
$('.navbar-collapse ul li a').click(function() {
    $('.navbar-toggle:visible').click();
});
<commit_msg>Delete freelancer.js<commit_after><|endoftext|>


<commit_before>import tingle from 'tingle.js';
import request from 'superagent';

class SoftPage {
    constructor (options) {
        this.options = options || {};
        this.base_url = window.location.href;
        this.init();
    }

    init () {
        let base_url = this.base_url;
        var self = this;
        this.modal = new tingle.modal({
            cssClass: ['softpage'],
            onClose: function() {
                history.replaceState({}, '', base_url); // removed due to double base url issue
                if(self.options.onSoftpageClosed) {
                    self.options.onSoftpageClosed(self);
                }
            },
            beforeClose: function() {
                if(self.options.onBeforeClose) {
                    return self.options.onBeforeClose(self);
                }
            }
        });

        // in case of browser history is changing
        window.onpopstate = function (event) {
            if (window.location.href !== base_url) { // when changing to another page
                window.location.reload(); // after history change, reload to load server-side page
            }
            if (event.state && event.state.is_soft_page) {
                this.loadPage(window.location);
            } else if (this.modal) {
                this.modal.close();
            }
        }.bind(this);
    }

    closeSoftpage() {
        this.modal.close();
    }

    loadPage(href, pushstate, softpage_content_id) {
        // init
        var modal_content = this.modal.modal.querySelector('.tingle-modal-box__content');
        // option 1: load content of element with ID
        if (softpage_content_id && softpage_content_id.length > 0) {
            var softpage_content_markup = document.getElementById(softpage_content_id).innerHTML;
            this.modal.open();
            this.modal.setContent(softpage_content_markup);
            this.modal.modal.querySelector('.tingle-modal-box').scrollTop = 0;
            // let us know that everything's alright
            if(this.options.onPageLoaded) {
                this.options.onPageLoaded(this);
            }
        }
        // otherwise, do it the regular way
        else {
            request
                .get(href)
                .set('X-Requested-With', 'XMLHttpRequest')
                .end((error, result) => {
                    this.modal.open();
                    this.modal.setContent(result.text);
                    if(this.options.onPageLoaded) {
                        this.options.onPageLoaded(this);
                    }
                    if(pushstate) {
                        history.pushState({is_soft_page: true}, '', href);
                    }
            });
        }
    }
}

export default SoftPage;
<commit_msg>Add GET parameter to url when requesting softpage<commit_after>import tingle from 'tingle.js';
import request from 'superagent';

class SoftPage {
    constructor (options) {
        this.options = options || {};
        this.base_url = window.location.href;
        this.init();
    }

    init () {
        let base_url = this.base_url;
        var self = this;
        this.modal = new tingle.modal({
            cssClass: ['softpage'],
            onClose: function() {
                history.replaceState({}, '', base_url); // removed due to double base url issue
                if(self.options.onSoftpageClosed) {
                    self.options.onSoftpageClosed(self);
                }
            },
            beforeClose: function() {
                if(self.options.onBeforeClose) {
                    return self.options.onBeforeClose(self);
                }
            }
        });

        // in case of browser history is changing
        window.onpopstate = function (event) {
            if (window.location.href !== base_url) { // when changing to another page
                window.location.reload(); // after history change, reload to load server-side page
            }
            if (event.state && event.state.is_soft_page) {
                this.loadPage(window.location);
            } else if (this.modal) {
                this.modal.close();
            }
        }.bind(this);
    }

    closeSoftpage() {
        this.modal.close();
    }

    loadPage(href, pushstate, softpage_content_id) {
        // init
        var modal_content = this.modal.modal.querySelector('.tingle-modal-box__content');
        // option 1: load content of element with ID
        if (softpage_content_id && softpage_content_id.length > 0) {
            var softpage_content_markup = document.getElementById(softpage_content_id).innerHTML;
            this.modal.open();
            this.modal.setContent(softpage_content_markup);
            this.modal.modal.querySelector('.tingle-modal-box').scrollTop = 0;
            // let us know that everything's alright
            if(this.options.onPageLoaded) {
                this.options.onPageLoaded(this);
            }
        }
        // otherwise, do it the regular way
        else {
            // Append softpage=True to the request URL in case the responding page behaves differently for softpages.
            let sofpageIdentificationUrlParameter = href.indexOf('?') === -1 ? '?softpage=true' : '&softpage=true';
            let softpageUrl = href + sofpageIdentificationUrlParameter;
            request
                .get(softpageUrl)
                .set('X-Requested-With', 'XMLHttpRequest')
                .end((error, result) => {
                    this.modal.open();
                    this.modal.setContent(result.text);
                    if(this.options.onPageLoaded) {
                        this.options.onPageLoaded(this);
                    }
                    if(pushstate) {
                        history.pushState({is_soft_page: true}, '', href);
                    }
            });
        }
    }
}

export default SoftPage;
<|endoftext|>


<commit_before>"use strict";

/*global mediaWiki, jQuery, OO*/

/*
 Used when viewing a 'Category:NameOfCategory' page.

 Finds the button #new-category-page and adds click behaviour for it.
 */
(function (mw, $, OO) {
    var titleRegex = new RegExp("^[" + mw.config.values.wgLegalTitleChars + "]{1,256}$"),
	isValidTitle = function(text) {
	    return titleRegex.test(text);
	},

	validateTitleAndSetAbilities = function(dialogue) {
	    dialogue.actions.setAbilities({
		create: isValidTitle(dialogue.pageTitle.getValue())
	    });
	};

    mw.hook('wikipage.content').add(function(content) {
	if (!mw.viewingCategoryPage) {
	    return;
	}

	var newDocumentButton = OO.ui.infuse('new-category-page'),
	    category = function() {
		var title = mw.config.values.wgTitle || "";
		return title.match(/[A-Z][a-z]*/g).join(" ").toLowerCase();
	    }(),

	    NewPageDialogue = function(config) {
		OO.ui.ProcessDialog.call(this, config);
	    };

	OO.inheritClass(NewPageDialogue, OO.ui.ProcessDialog);

	NewPageDialogue.static.title = "New " + category + " dialogue";
	NewPageDialogue.static.actions = [
	    { action: 'create', label: 'Create', flags: 'primary'},
	    { label: 'Cancel', flags: 'safe' }
	];

	NewPageDialogue.prototype.initialize = function() {
	    NewPageDialogue.parent.prototype.initialize.apply(this, arguments);

	    var dialogue = this;

	    this.pageTitle = new OO.ui.TextInputWidget({
		placeholder: 'Name of ' + category,
		validate: isValidTitle
	    });

	    this.pageTitle.on("change", function() {
		validateTitleAndSetAbilities(dialogue);
	    });

	    this.form = new OO.ui.FormLayout({
		items: [this.pageTitle],
		action: 'create'
	    });

	    this.$body.append(this.form.$element);
	};

	NewPageDialogue.prototype.getActionProcess = function(action) {
	    var dialogue = this;

	    if (action === 'create') {
		return new OO.ui.Process(function() {
		    window.location.assign(
			mw.config.values.wgServer
			    + mw.config.values.wgArticlePath
			    .replace(
				    /\$1/,
				encodeURIComponent(
				    "Category:" + dialogue.pageTitle.getValue()
				)
			    )
			    + "?category=" + category
		    );
		});
	    }
	    return NewPageDialogue.parent.prototype.getActionProcess.apply(this, arguments);
	};

	var windowManager = new OO.ui.WindowManager();
	$('body').append(windowManager.$element);

	var dialogue = new NewPageDialogue();
	windowManager.addWindows([dialogue]);

	newDocumentButton.on('click', function () {
	    var window = windowManager.openWindow(dialogue)
		    .done(function() {
			validateTitleAndSetAbilities(dialogue);
			dialogue.pageTitle.focus();
		    });
	});
    });

}(mediaWiki, jQuery, OO));
<commit_msg>In the skin, on the Projects page, clicking the 'New Project button, the placeholder will now be "Name of project" instead of "Name of projects".<commit_after>"use strict";

/*global mediaWiki, jQuery, OO*/

/*
 Used when viewing a 'Category:NameOfCategory' page.

 Finds the button #new-category-page and adds click behaviour for it.
 */
(function (mw, $, OO) {
    var titleRegex = new RegExp("^[" + mw.config.values.wgLegalTitleChars + "]{1,256}$"),
	isValidTitle = function(text) {
	    return titleRegex.test(text);
	},

	validateTitleAndSetAbilities = function(dialogue) {
	    dialogue.actions.setAbilities({
		create: isValidTitle(dialogue.pageTitle.getValue())
	    });
	};

    mw.hook('wikipage.content').add(function(content) {
	if (!mw.viewingCategoryPage) {
	    return;
	}

	var newDocumentButton = OO.ui.infuse('new-category-page'),
	    category = (function() {
		var title = mw.config.values.wgTitle || "";
		return title.match(/[A-Z][a-z]*/g).join(" ").toLowerCase();
	    }()),

	    isProjects = category === "projects",

	    NewPageDialogue = function(config) {
		OO.ui.ProcessDialog.call(this, config);
	    };

	OO.inheritClass(NewPageDialogue, OO.ui.ProcessDialog);

	NewPageDialogue.static.title = "New " + category + " dialogue";
	NewPageDialogue.static.actions = [
	    { action: 'create', label: 'Create', flags: 'primary'},
	    { label: 'Cancel', flags: 'safe' }
	];

	NewPageDialogue.prototype.initialize = function() {
	    NewPageDialogue.parent.prototype.initialize.apply(this, arguments);

	    var dialogue = this;

	    this.pageTitle = new OO.ui.TextInputWidget({
		placeholder: 'Name of ' + (isProjects ? "project" : category),
		validate: isValidTitle
	    });

	    this.pageTitle.on("change", function() {
		validateTitleAndSetAbilities(dialogue);
	    });

	    this.form = new OO.ui.FormLayout({
		items: [this.pageTitle],
		action: 'create'
	    });

	    this.$body.append(this.form.$element);
	};

	NewPageDialogue.prototype.getActionProcess = function(action) {
	    var dialogue = this;

	    if (action === 'create') {
		return new OO.ui.Process(function() {
		    window.location.assign(
			mw.config.values.wgServer
			    + mw.config.values.wgArticlePath
			    .replace(
				    /\$1/,
				encodeURIComponent(
				    "Category:" + dialogue.pageTitle.getValue()
				)
			    )
			    + "?category=" + category
		    );
		});
	    }
	    return NewPageDialogue.parent.prototype.getActionProcess.apply(this, arguments);
	};

	var windowManager = new OO.ui.WindowManager();
	$('body').append(windowManager.$element);

	var dialogue = new NewPageDialogue();
	windowManager.addWindows([dialogue]);

	newDocumentButton.on('click', function () {
	    var window = windowManager.openWindow(dialogue)
		    .done(function() {
			validateTitleAndSetAbilities(dialogue);
			dialogue.pageTitle.focus();
		    });
	});
    });

}(mediaWiki, jQuery, OO));
<|endoftext|>


<commit_before>import {isObject, isString, isArray} from "../../util.js";
import {each, values as objectValues} from "../../util.js";
import {propTypes, parseProps} from "../../props.js";
import {getValueSources} from "../../runtime/value.js";
import {getExpressionSources} from "../../runtime/expression.js";

import {setStyle, isStyleName} from "../style.js";
import {setTooltipEvents} from "../tooltip.js";
import {setEvent, isEventName} from "../events.js";

import {getPanelsElements} from "../panels.js";

import {textGeom} from "./text.js";
import {lineGeom} from "./line.js";
import {rectangleGeom} from "./rectangle.js";
import {circleGeom} from "./circle.js";
import {arcGeom} from "./arc.js";
import {curveGeom} from "./curve.js";
import {areaGeom} from "./area.js";
import {pathGeom} from "./path.js";
//import {polylineGeom} from "./polyline.js";
//import {polygonGeom} from "./polygon.js";

//Geoms types
const geomsTypes = {
    //"polyline": polylineGeom,
    //"polygon": polygonGeom,
    "text": textGeom,
    "line": lineGeom,
    "rectangle": rectangleGeom,
    "circle": circleGeom,
    "arc": arcGeom,
    "segment": segmentGeom,
    "area": areaGeom,
    "path": pathGeom
};

//Get a geom object
export function getGeom (name) {
    return geomsTypes[name];
}

//build geom data
let buildGeomData = function (context, props) {
    //Get data in context
    let data = context.source(props.source);
    //Check for transform to apply
    if (isArray(props.transform) || isObject(props.transform)) {
        data = data.map(function (item) {
            return context.transform(item, props.transform);
        });
    }
    //Return the parsed data
    return data;
};

//Get geom data
let getGeomData = function (data, props) {
    if (props.type === "curve" || props.type === "area") {
        return data; //Return the entire dataset
    }
    //Return only the first item
    return data[0];
};

//Build geom element
let createGeomElement = function (geom, parent, index, group) {
    return parent.append(geom.tag).attr("id", `geom__${group}__${index}`);
};

//Get a geom element
let getGeomElement = function (geom, parent, index, group) {
    return parent.selectAll(`#geom__${group}__${index}`);
};

//Check if render props contain a geom props
let hasGeomRenderProps = function (props, geom) {
    let keys = Object.keys(props);
    for (let i = 0; i < keys.length; i++) {
        if (typeof geom.props[keys[i]] !== "undefined") {
            return true; //Found a geom prop
        }
    }
    //No geom props found
    return false;
};

//Get rendering props
let getGeomRenderProps = function (props, event) {
    let renderProps = {}; //props.render.mount;
    //Check if init props are provided
    if (typeof props.render["init"] === "object" && props.render["init"] !== null) {
        renderProps = Object.assign({}, props.render["init"]);
    }
    //Check the current event
    if (typeof props.render[event] === "object" && props.render[event] !== null) {
        renderProps = Object.assign({}, renderProps, props.render[event]);
    }
    //Return the final props
    return renderProps;
};

//Get geom groups
let getGeomGroups = function (props) {
    if (props.type === "group") {
        if (isArray(props.geoms) === true) {
            return props.geoms; //Return the array of geoms
        }
        else if (isObject(props.geos) === true) {
            return objectValues(props.geoms); //Return only values
        }
        //Default --> not valid geoms
        return [];
    }
    //Else: return this geom props as an array
    return [props];
};

//Apply geom style
let applyGeomStyle = function (context, datum, props, target) {
    let datumValue = (isArray(datum) === true) ? datum[0] : datum; //Get datum value
    return each(props, function (key, value) {
        if (value !== null && isStyleName(key) === true) {
            return setStyle(target, key, context.value(props[key], datumValue)); //Apply style
        }
    });
};

//Create a new geom node
export function createGeomNode (context, key, props) {
    //Initialize the geom node
    let node = context.addNode({
        "id": `geom:${key}`,
        "type": "geom",
        "props": props,
        "targets": null,
        "source": null,
        "value": [],
    });
    //Get the source data
    context.panels.targets.add(node.id, node); //Bind to panels
    if (typeof props.source === "object" && props.source !== null) {
        if (typeof props.source.data === "string") {
            let source = context.data[props.source.data];
            Object.assign(node, {
                "source": source
            });
            //Add this geom node as a target node for this data object
            source.targets.add(node.id, node);
        }
    }
    //Get values sources
    getGeomGroups(node.props).forEach(function (groupProps) {
        return each(groupProps.render, function (key, renderProps) {
            return each(renderProps, function (propKey, propValue) {
                return getValueSources(context, propValue).forEach(function (source) {
                    //console.log(source);
                    source.targets.add(node.id, node); //Add this geom as a target node
                });
            })
        });
    });
    //Render this geom the first time
    //return updateShape(context, node, true);
}

//Update the provided node
export function updateGeomNode (context, node, forceRender) {
    getPanelsElements(context, node.props.panel).forEach(function (element) {
        //Check if there is a group for this geom group
        let target = element.selectAll(`g[data-geom='${node.id}']`);
        if (target.length === 0) {
            target = element.append("g").attr("data-geom", node.id); //Create a new geom group
        }
        //Render the geom
        return renderGeom(context, node, target, forceUpdate);
    });
}

//Render a geom
let renderGeom = function (context, node, parent, forceUpdate) {
    //Check for force rendering the geom
    if (forceRender === true) {
        //Clean the parent node
        //node.parent.empty();
        parent.empty();
        //Get data to apply
        Object.assign(node, {
            "value": buildShapeData(context, node.props)
        });
    }
    //Get geom groups
    getGeomGroups(node.props).forEach(function (props, groupIndex) {
        //Get the geom item
        let geom = getGeom(props.type);
        //Init props
        let updateProps = getGeomRenderProps(props, "update");
        let hoverProps = getGeomRenderProps(props, "hover");
        //Check for no force render
        if (forceRender === false) {
            //Check for no update render
            if (typeof props.render.update !== "object" || props.render.update === null) {
                return;
            }
            //Check if we should reload each rendered geom
            let reloadGeom = hasGeomRenderProps(props.render.update, geom);
            //Access to all items
            return getGeomData(node.value, props).forEach(function (data, index) {
                //Select the element attached to this data node
                let element = getGeomElement(geom, parent, index, groupIndex);
                //Check for render props
                if (reloadGeom === true) {
                    geom.render(context, data, updateProps, element); //Redraw this element
                }
                //Apply style props
                applyGeomStyle(context, data, props.render.update, element);
            });
        }
        //Build geoms for each data group
        getGeomData(node.value, props).forEach(function (data, index) {
            let element = createGeomElement(geom, parent, index, groupIndex);
            geom.render(context, data, updateProps, element);  // --> render init + update props
            //Apply style props
            applyGeomStyle(context, data, updateProps, element);
            //Register on hover events
            if (typeof props.render.hover === "object" && props.render.hover !== null) {
                //Register enter event listener --> apply hover props
                element.on("mouseenter", function (event) {
                    if (hasGeomRenderProps(props.render.hover, geom) === true) {
                        geom.render(context, data, hoverProps, element); //Redraw this element
                    }
                    //Apply style props
                    applyGeomStyle(context, data, props.render.hover, element);
                });
                //Check for update props provided
                if (typeof props.render.update === "object" && props.render.update !== null) {
                    //Register on leave event listener --> apply update props to this element
                    element.on("mouseleave", function (event) {
                        if (hasGeomRenderProps(props.render.update, geom) === true) {
                            geom.render(context, data, updateProps, element); //Redraw this element
                        }
                        //Apply style props
                        applyGeomStyle(context, data, props.render.update, element);
                    });
                }
            }
            //Register additional event listening
            each(props.on, function (eventIndex, eventProps) {
                return setEvent(element, eventProps.type, function (event) {
                    //Check for signal update event
                    if (isString(eventProps.state) && isString(eventProps.value)) {
                        //Register an action to update this state
                        let stateNode = context.state[eventProps.state];
                        if (typeof stateNode !== "undefined") {
                            context.addAction(stateNode, context.expression(eventProps.value, {
                                "datum": data,
                                "event": event //TODO: process event values
                            }));
                            //Trigger the update action
                            context.render();
                        }
                    }
                    //Check for fire this event to the api
                    if (isString(eventProps.fire)) {
                        return context.events.dispatchEvent(eventProps.fire, event, data);
                    }
                });
            });
            //Register tooltip handlers
            if (typeof props.tooltip === "object" && props.tooltip !== null) {
                setTooltipEvents(context, element, data, props.tooltip);
            }
        });
    });
}

<commit_msg>render: fixed geoms imports --> segment geom has been renamed as line<commit_after>import {isObject, isString, isArray} from "../../util.js";
import {each, values as objectValues} from "../../util.js";
import {propTypes, parseProps} from "../../props.js";
import {getValueSources} from "../../runtime/value.js";
import {getExpressionSources} from "../../runtime/expression.js";

import {setStyle, isStyleName} from "../style.js";
import {setTooltipEvents} from "../tooltip.js";
import {setEvent, isEventName} from "../events.js";

import {getPanelsElements} from "../panels.js";

import {textGeom} from "./text.js";
import {lineGeom} from "./line.js";
import {rectangleGeom} from "./rectangle.js";
import {circleGeom} from "./circle.js";
import {arcGeom} from "./arc.js";
import {curveGeom} from "./curve.js";
import {areaGeom} from "./area.js";
import {pathGeom} from "./path.js";
//import {polylineGeom} from "./polyline.js";
//import {polygonGeom} from "./polygon.js";

//Geoms types
const geomsTypes = {
    //"polyline": polylineGeom,
    //"polygon": polygonGeom,
    "text": textGeom,
    "line": lineGeom,
    "rectangle": rectangleGeom,
    "circle": circleGeom,
    "arc": arcGeom,
    "curve": curveGeom,
    "area": areaGeom,
    "path": pathGeom
};

//Get a geom object
export function getGeom (name) {
    return geomsTypes[name];
}

//build geom data
let buildGeomData = function (context, props) {
    //Get data in context
    let data = context.source(props.source);
    //Check for transform to apply
    if (isArray(props.transform) || isObject(props.transform)) {
        data = data.map(function (item) {
            return context.transform(item, props.transform);
        });
    }
    //Return the parsed data
    return data;
};

//Get geom data
let getGeomData = function (data, props) {
    if (props.type === "curve" || props.type === "area") {
        return data; //Return the entire dataset
    }
    //Return only the first item
    return data[0];
};

//Build geom element
let createGeomElement = function (geom, parent, index, group) {
    return parent.append(geom.tag).attr("id", `geom__${group}__${index}`);
};

//Get a geom element
let getGeomElement = function (geom, parent, index, group) {
    return parent.selectAll(`#geom__${group}__${index}`);
};

//Check if render props contain a geom props
let hasGeomRenderProps = function (props, geom) {
    let keys = Object.keys(props);
    for (let i = 0; i < keys.length; i++) {
        if (typeof geom.props[keys[i]] !== "undefined") {
            return true; //Found a geom prop
        }
    }
    //No geom props found
    return false;
};

//Get rendering props
let getGeomRenderProps = function (props, event) {
    let renderProps = {}; //props.render.mount;
    //Check if init props are provided
    if (typeof props.render["init"] === "object" && props.render["init"] !== null) {
        renderProps = Object.assign({}, props.render["init"]);
    }
    //Check the current event
    if (typeof props.render[event] === "object" && props.render[event] !== null) {
        renderProps = Object.assign({}, renderProps, props.render[event]);
    }
    //Return the final props
    return renderProps;
};

//Get geom groups
let getGeomGroups = function (props) {
    if (props.type === "group") {
        if (isArray(props.geoms) === true) {
            return props.geoms; //Return the array of geoms
        }
        else if (isObject(props.geos) === true) {
            return objectValues(props.geoms); //Return only values
        }
        //Default --> not valid geoms
        return [];
    }
    //Else: return this geom props as an array
    return [props];
};

//Apply geom style
let applyGeomStyle = function (context, datum, props, target) {
    let datumValue = (isArray(datum) === true) ? datum[0] : datum; //Get datum value
    return each(props, function (key, value) {
        if (value !== null && isStyleName(key) === true) {
            return setStyle(target, key, context.value(props[key], datumValue)); //Apply style
        }
    });
};

//Create a new geom node
export function createGeomNode (context, key, props) {
    //Initialize the geom node
    let node = context.addNode({
        "id": `geom:${key}`,
        "type": "geom",
        "props": props,
        "targets": null,
        "source": null,
        "value": [],
    });
    //Get the source data
    context.panels.targets.add(node.id, node); //Bind to panels
    if (typeof props.source === "object" && props.source !== null) {
        if (typeof props.source.data === "string") {
            let source = context.data[props.source.data];
            Object.assign(node, {
                "source": source
            });
            //Add this geom node as a target node for this data object
            source.targets.add(node.id, node);
        }
    }
    //Get values sources
    getGeomGroups(node.props).forEach(function (groupProps) {
        return each(groupProps.render, function (key, renderProps) {
            return each(renderProps, function (propKey, propValue) {
                return getValueSources(context, propValue).forEach(function (source) {
                    //console.log(source);
                    source.targets.add(node.id, node); //Add this geom as a target node
                });
            })
        });
    });
    //Render this geom the first time
    //return updateShape(context, node, true);
}

//Update the provided node
export function updateGeomNode (context, node, forceRender) {
    getPanelsElements(context, node.props.panel).forEach(function (element) {
        //Check if there is a group for this geom group
        let target = element.selectAll(`g[data-geom='${node.id}']`);
        if (target.length === 0) {
            target = element.append("g").attr("data-geom", node.id); //Create a new geom group
        }
        //Render the geom
        return renderGeom(context, node, target, forceUpdate);
    });
}

//Render a geom
let renderGeom = function (context, node, parent, forceUpdate) {
    //Check for force rendering the geom
    if (forceRender === true) {
        //Clean the parent node
        //node.parent.empty();
        parent.empty();
        //Get data to apply
        Object.assign(node, {
            "value": buildShapeData(context, node.props)
        });
    }
    //Get geom groups
    getGeomGroups(node.props).forEach(function (props, groupIndex) {
        //Get the geom item
        let geom = getGeom(props.type);
        //Init props
        let updateProps = getGeomRenderProps(props, "update");
        let hoverProps = getGeomRenderProps(props, "hover");
        //Check for no force render
        if (forceRender === false) {
            //Check for no update render
            if (typeof props.render.update !== "object" || props.render.update === null) {
                return;
            }
            //Check if we should reload each rendered geom
            let reloadGeom = hasGeomRenderProps(props.render.update, geom);
            //Access to all items
            return getGeomData(node.value, props).forEach(function (data, index) {
                //Select the element attached to this data node
                let element = getGeomElement(geom, parent, index, groupIndex);
                //Check for render props
                if (reloadGeom === true) {
                    geom.render(context, data, updateProps, element); //Redraw this element
                }
                //Apply style props
                applyGeomStyle(context, data, props.render.update, element);
            });
        }
        //Build geoms for each data group
        getGeomData(node.value, props).forEach(function (data, index) {
            let element = createGeomElement(geom, parent, index, groupIndex);
            geom.render(context, data, updateProps, element);  // --> render init + update props
            //Apply style props
            applyGeomStyle(context, data, updateProps, element);
            //Register on hover events
            if (typeof props.render.hover === "object" && props.render.hover !== null) {
                //Register enter event listener --> apply hover props
                element.on("mouseenter", function (event) {
                    if (hasGeomRenderProps(props.render.hover, geom) === true) {
                        geom.render(context, data, hoverProps, element); //Redraw this element
                    }
                    //Apply style props
                    applyGeomStyle(context, data, props.render.hover, element);
                });
                //Check for update props provided
                if (typeof props.render.update === "object" && props.render.update !== null) {
                    //Register on leave event listener --> apply update props to this element
                    element.on("mouseleave", function (event) {
                        if (hasGeomRenderProps(props.render.update, geom) === true) {
                            geom.render(context, data, updateProps, element); //Redraw this element
                        }
                        //Apply style props
                        applyGeomStyle(context, data, props.render.update, element);
                    });
                }
            }
            //Register additional event listening
            each(props.on, function (eventIndex, eventProps) {
                return setEvent(element, eventProps.type, function (event) {
                    //Check for signal update event
                    if (isString(eventProps.state) && isString(eventProps.value)) {
                        //Register an action to update this state
                        let stateNode = context.state[eventProps.state];
                        if (typeof stateNode !== "undefined") {
                            context.addAction(stateNode, context.expression(eventProps.value, {
                                "datum": data,
                                "event": event //TODO: process event values
                            }));
                            //Trigger the update action
                            context.render();
                        }
                    }
                    //Check for fire this event to the api
                    if (isString(eventProps.fire)) {
                        return context.events.dispatchEvent(eventProps.fire, event, data);
                    }
                });
            });
            //Register tooltip handlers
            if (typeof props.tooltip === "object" && props.tooltip !== null) {
                setTooltipEvents(context, element, data, props.tooltip);
            }
        });
    });
}

<|endoftext|>


<commit_before>namespace('Sy');

/**
 * Wrapper to set/retrieve key/value pairs
 *
 * @package Sy
 * @class
 * @implements {Sy.ConfiguratorInterface}
 */

Sy.Configurator = function () {

    this.name = '';
    this.config = {};

};

Sy.Configurator.prototype = Object.create(Sy.ConfiguratorInterface.prototype, {

    /**
     * @inheritDoc
     */

    set: {
        value: function (key, value) {

            if (key instanceof Object && value === undefined) {
                this.config = _.extend(this.config, key);
            } else {
                objectSetter.call(this.config, key, value);
            }

            return this;

        }
    },

    /**
     * @inheritDoc
     */

    get: {
        value: function (key) {

            var value;

            if (key === undefined) {
                value = this.config;
            } else if (this.has(key)) {
                value = objectGetter.call(this.config, key);
            }

            return value;

        }
    },

    /**
     * @inheritDoc
     */

    has: {
        value: function (key) {

            try {

                objectGetter.call(this.config, key);

                return true;

            } catch (error) {

                if (error instanceof ReferenceError) {
                    return false;
                }

            }

        }
    },

    /**
     * @inheritDoc
     */

    setName: {
        value: function (name) {

            this.name = name;

            return this;

        }
    },

    /**
     * @inheritDoc
     */

    getName: {
        value: function () {

            return this.name;

        }
    }

});<commit_msg>fix a falsy true in the configurator<commit_after>namespace('Sy');

/**
 * Wrapper to set/retrieve key/value pairs
 *
 * @package Sy
 * @class
 * @implements {Sy.ConfiguratorInterface}
 */

Sy.Configurator = function () {

    this.name = '';
    this.config = {};

};

Sy.Configurator.prototype = Object.create(Sy.ConfiguratorInterface.prototype, {

    /**
     * @inheritDoc
     */

    set: {
        value: function (key, value) {

            if (key instanceof Object && value === undefined) {
                this.config = _.extend(this.config, key);
            } else {
                objectSetter.call(this.config, key, value);
            }

            return this;

        }
    },

    /**
     * @inheritDoc
     */

    get: {
        value: function (key) {

            var value;

            if (key === undefined) {
                value = this.config;
            } else if (this.has(key)) {
                value = objectGetter.call(this.config, key);
            }

            return value;

        }
    },

    /**
     * @inheritDoc
     */

    has: {
        value: function (key) {

            try {

                objectGetter.call(this.config, key);

                if (key.split('.').length === 1 && !this.config.hasOwnProperty(key)) {
                    return false;
                }

                return true;

            } catch (error) {

                if (error instanceof ReferenceError) {
                    return false;
                }

            }

        }
    },

    /**
     * @inheritDoc
     */

    setName: {
        value: function (name) {

            this.name = name;

            return this;

        }
    },

    /**
     * @inheritDoc
     */

    getName: {
        value: function () {

            return this.name;

        }
    }

});<|endoftext|>