From 4a081f65f754c79a437d983ee1a22c60f97ee784 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Mon, 14 Apr 2014 16:34:09 +0200 Subject: [PATCH] editor: handle undefined action state --- src/editor/modules/documentToolbar/actionView.js | 7 +++++++ src/editor/modules/statusBar/statusBar.js | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/editor/modules/documentToolbar/actionView.js b/src/editor/modules/documentToolbar/actionView.js index ddef396..114eb32 100644 --- a/src/editor/modules/documentToolbar/actionView.js +++ b/src/editor/modules/documentToolbar/actionView.js @@ -1,6 +1,7 @@ define(function(require) { 'use strict'; +/* globals gettext */ var $ = require('libs/jquery'), Backbone = require('libs/backbone'), @@ -44,6 +45,12 @@ var ActionView = Backbone.View.extend({ var actionState = this.action.getState(); + if(!actionState) { + this.$el.html(buttonTemplate({label: gettext('error :('), iconName:''})); + this._button().attr('disabled', true); + return; + } + var templateContext = { label: actionState.label || '?', iconName: (iconExists(actionState.icon)) ? actionState.icon : null, diff --git a/src/editor/modules/statusBar/statusBar.js b/src/editor/modules/statusBar/statusBar.js index 5ad7c6b..0f08c59 100644 --- a/src/editor/modules/statusBar/statusBar.js +++ b/src/editor/modules/statusBar/statusBar.js @@ -22,11 +22,19 @@ return function(sandbox){ }, showAction: function(action) { var state = action.getState(), + description; + + if(!state) { + description = gettext('error :('); + logger.error('Got undefined action state: ' + action.name); + } else { description = state.description; - if(!description) { - description = state.allowed ? gettext('Undescribed action') : gettext('Action not allowed'); - logger.info('Undescribed action: ' + action.name); + if(!description) { + description = state.allowed ? gettext('Undescribed action') : gettext('Action not allowed'); + logger.info('Undescribed action: ' + action.name); + } } + view.text(description); if(!state.allowed) { view.prepend('!'); -- 2.20.1