Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset disabled buttons when app is deactivated #574

Merged
merged 2 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 69 additions & 48 deletions app/controller/sdl/KeyboardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,47 @@ SDL.KeyboardController = Em.Object.create({
*/
unsupportedKeyboardSymbols: [ '^' ],

/**
* Id of app that initiated keyboard interaction
*/
appID: null,

/**
* Model of app that initiated keyboard interaction
*/
appModel: null,

/**
* @description Closes keyboard view and cancels active interaction request
*/
closeKeyboardView: function() {
if (SDL.SDLController.model &&
SDL.SDLController.model.activeRequests.uiPerformInteraction &&
if (this.appModel &&
this.appModel.activeRequests.uiPerformInteraction &&
!SDL.InteractionChoicesView.active) {
FFW.UI.OnKeyboardInput('', 'ENTRY_CANCELLED');
SDL.InteractionChoicesView.deactivate('ABORTED');
}
SDL.Keyboard.deactivate();
},

updateModel: function() {
if (this.appID === null) {
this.appModel = SDL.SDLController.model;
} else {
this.appModel = SDL.SDLController.getApplicationModel(this.appID);
}
}.observes(
'this.appID'
),

/**
* @description Inputs the information depending on key pressed
* @param {Object} element key that was pressed by user
*/
inputChanges: function(element) {
if (SDL.SDLController.model &&
SDL.SDLController.model.activeRequests.uiPerformInteraction) {
if (this.appModel && this.appModel.activeRequests.uiPerformInteraction) {
SDL.SDLController.onResetTimeout(
SDL.SDLController.model.appID, 'UI.PerformInteraction'
this.appModel.appID, 'UI.PerformInteraction'
);
}

Expand Down Expand Up @@ -128,10 +147,9 @@ SDL.KeyboardController = Em.Object.create({
SDL.SDLController.onKeyboardChanges();
}

if (SDL.SDLController.model &&
SDL.SDLController.model.activeRequests.uiPerformInteraction) {
if (this.appModel && this.appModel.activeRequests.uiPerformInteraction) {
SDL.SDLController.onResetTimeout(
SDL.SDLController.model.appID, 'UI.PerformInteraction'
this.appModel.appID, 'UI.PerformInteraction'
);
}
},
Expand All @@ -140,36 +158,36 @@ SDL.KeyboardController = Em.Object.create({
* @description Disables or enables characters depending on global properties
*/
disableButtons: function() {
if (SDL.SDLController.model) {
if (!SDL.SDLController.model.globalProperties.keyboardProperties) {
return;
}
var list = SDL.SDLController.model.globalProperties.keyboardProperties.limitedCharacterList ?
SDL.SDLController.model.globalProperties.keyboardProperties.limitedCharacterList :
[];
for (var i = 0; i < list.length; i++) {
list[i] = list[i].toLowerCase();
}
var list = [];
if (this.appModel && this.appModel.globalProperties.keyboardProperties &&
this.appModel.globalProperties.keyboardProperties.limitedCharacterList) {
list = this.appModel.globalProperties.keyboardProperties.limitedCharacterList;
}

let disable_layout_buttons = (layout, list) => {
for (var i = 0; i < layout._childViews.length; ++i) {
let button = layout._childViews[i];
for (var i = 0; i < list.length; i++) {
list[i] = list[i].toLowerCase();
}

if (list.length == 0) {
button.set('disabled', false);
continue;
}
let disable_layout_buttons = (layout, list) => {
for (var i = 0; i < layout._childViews.length; ++i) {
let button = layout._childViews[i];

let button_text = button.text;
if (button.customKeyIndex != null) {
button_text = this.getCustomKey(button.customKeyIndex, button.defaultText);
}
if (list.length == 0) {
button.set('disabled', false);
continue;
}

const is_disabled = list.indexOf(button_text) < 0;
button.set('disabled', is_disabled);
let button_text = button.text;
if (button.customKeyIndex != null) {
button_text = this.getCustomKey(button.customKeyIndex, button.defaultText);
}
};

const is_disabled = list.indexOf(button_text) < 0;
button.set('disabled', is_disabled);
}
};

if (SDL.Keyboard) {
const layouts = [
SDL.Keyboard.buttonsAreaQWERTY,
SDL.Keyboard.buttonsAreaQWERTZ,
Expand All @@ -182,7 +200,9 @@ SDL.KeyboardController = Em.Object.create({
});
}
}.observes(
'SDL.SDLController.model.globalProperties.keyboardProperties.limitedCharacterList.@each'
'SDL.SDLController.model.globalProperties.keyboardProperties.limitedCharacterList.@each',
'this.appModel.globalProperties.keyboardProperties.limitedCharacterList.@each',
'this.appID'
),

/**
Expand All @@ -193,13 +213,13 @@ SDL.KeyboardController = Em.Object.create({
isLayoutActive: function(layout) {
const default_layout = "QWERTY";

if (SDL.SDLController.model == null && layout == default_layout) {
if (this.appModel == null && layout == default_layout) {
return true;
}

return SDL.SDLController.model &&
SDL.SDLController.model.globalProperties.keyboardProperties ?
SDL.SDLController.model.globalProperties.keyboardProperties.keyboardLayout == layout :
return this.appModel &&
this.appModel.globalProperties.keyboardProperties ?
this.appModel.globalProperties.keyboardProperties.keyboardLayout == layout :
false;
},

Expand All @@ -209,9 +229,8 @@ SDL.KeyboardController = Em.Object.create({
*/
maskInputCharacters: function() {
let value = 'DISABLE_INPUT_KEY_MASK';
if (SDL.SDLController.model &&
SDL.SDLController.model.globalProperties.keyboardProperties) {
value = SDL.SDLController.model.globalProperties.keyboardProperties.maskInputCharacters;
if (this.appModel && this.appModel.globalProperties.keyboardProperties) {
value = this.appModel.globalProperties.keyboardProperties.maskInputCharacters;
}

let is_mask_characters = false;
Expand All @@ -228,7 +247,7 @@ SDL.KeyboardController = Em.Object.create({
case 'USER_CHOICE_INPUT_KEY_MASK': {
Em.Logger.log('Showing user button for masking');
is_show_mask_button = true;
is_mask_characters = SDL.SDLController.model.maskInputCharactersUserChoice;
is_mask_characters = this.appModel.maskInputCharactersUserChoice;
break;
}

Expand All @@ -246,7 +265,9 @@ SDL.KeyboardController = Em.Object.create({
this.updateInputMasking();

}.observes(
'SDL.SDLController.model.globalProperties.keyboardProperties.maskInputCharacters'
'SDL.SDLController.model.globalProperties.keyboardProperties.maskInputCharacters',
'this.appModel.globalProperties.keyboardProperties.maskInputCharacters',
'this.appID'
),

/**
Expand All @@ -256,15 +277,15 @@ SDL.KeyboardController = Em.Object.create({
* @returns customized key according to global properties
*/
getCustomKey: function(index, defaultKey) {
if (SDL.SDLController.model == null) {
if (this.appModel == null) {
return defaultKey;
}

if (SDL.SDLController.model.globalProperties.keyboardProperties.customKeys == null) {
if (this.appModel.globalProperties.keyboardProperties.customKeys == null) {
return defaultKey;
}

const keys = SDL.SDLController.model.globalProperties.keyboardProperties.customKeys;
const keys = this.appModel.globalProperties.keyboardProperties.customKeys;
if (keys.length >= index + 1) {
const customSymbol = keys[index];
if (this.unsupportedKeyboardSymbols.includes(customSymbol)) {
Expand Down Expand Up @@ -317,9 +338,9 @@ SDL.KeyboardController = Em.Object.create({
* of internal controller flags
*/
updateInputMasking: function() {
if (SDL.SDLController.model) {
SDL.SDLController.model.set('maskInputCharactersUserChoice', SDL.KeyboardController.maskCharacters);
SDL.KeyboardController.sendInputKeyMaskNotification(SDL.SDLController.model.appID);
if (this.appModel) {
this.appModel.set('maskInputCharactersUserChoice', SDL.KeyboardController.maskCharacters);
SDL.KeyboardController.sendInputKeyMaskNotification(this.appModel.appID);
}
if (SDL.Keyboard) {
if (SDL.KeyboardController.maskCharacters) {
Expand Down
26 changes: 21 additions & 5 deletions app/view/sdl/shared/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
/**
* @name SDL.Keyboard
* @desc Slider visual representation
* @desc Keyboard visual representation
* @category View
* @filesource app/view/sdl/shared/keyboard.js
* @version 1.0
Expand Down Expand Up @@ -60,6 +60,12 @@ SDL.Keyboard = SDL.SDLAbstractView.create(
this.set('active', true);
SDL.KeyboardController.set('target', element);
}
if (SDL.InteractionChoicesView.appID) {
SDL.KeyboardController.set('appID', SDL.InteractionChoicesView.appID);
} else {
SDL.KeyboardController.set('appID', null);
SDL.KeyboardController.set('appModel', SDL.SDLController.model);
}
},
/**
* Extend deactivate method send SUCCESS response on deactivate with current
Expand All @@ -68,6 +74,8 @@ SDL.Keyboard = SDL.SDLAbstractView.create(
deactivate: function() {
this._super();
SDL.SDLModel.set('data.keyboardInputValue', '');
SDL.KeyboardController.set('appID', null);
SDL.KeyboardController.set('appModel', SDL.SDLController.model);
SDL.KeyboardController.set('target', null);
},

Expand Down Expand Up @@ -147,7 +155,9 @@ SDL.Keyboard = SDL.SDLAbstractView.create(
isEnabled: function() {
return SDL.KeyboardController.isLayoutActive("QWERTY");
}.property(
'SDL.SDLController.model.globalProperties.keyboardProperties.keyboardLayout'
'SDL.SDLController.model.globalProperties.keyboardProperties.keyboardLayout',
'SDL.KeyboardController.appModel.globalProperties.keyboardProperties.keyboardLayout',
'SDL.KeyboardController.appID'
)
}
),
Expand All @@ -157,7 +167,9 @@ SDL.Keyboard = SDL.SDLAbstractView.create(
isEnabled: function() {
return SDL.KeyboardController.isLayoutActive("QWERTZ");
}.property(
'SDL.SDLController.model.globalProperties.keyboardProperties.keyboardLayout'
'SDL.SDLController.model.globalProperties.keyboardProperties.keyboardLayout',
'SDL.KeyboardController.appModel.globalProperties.keyboardProperties.keyboardLayout',
'SDL.KeyboardController.appID'
)
}
),
Expand All @@ -167,7 +179,9 @@ SDL.Keyboard = SDL.SDLAbstractView.create(
isEnabled: function() {
return SDL.KeyboardController.isLayoutActive("AZERTY");
}.property(
'SDL.SDLController.model.globalProperties.keyboardProperties.keyboardLayout'
'SDL.SDLController.model.globalProperties.keyboardProperties.keyboardLayout',
'SDL.KeyboardController.appModel.globalProperties.keyboardProperties.keyboardLayout',
'SDL.KeyboardController.appID'
)
}
),
Expand All @@ -177,7 +191,9 @@ SDL.Keyboard = SDL.SDLAbstractView.create(
isEnabled: function() {
return SDL.KeyboardController.isLayoutActive("NUMERIC");
}.property(
'SDL.SDLController.model.globalProperties.keyboardProperties.keyboardLayout'
'SDL.SDLController.model.globalProperties.keyboardProperties.keyboardLayout',
'SDL.KeyboardController.appModel.globalProperties.keyboardProperties.keyboardLayout',
'SDL.KeyboardController.appID'
)
}
)
Expand Down