Skip to content

Commit

Permalink
Fixes on the dialog feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
feuzeu committed Jun 9, 2024
1 parent 11472bb commit ed35730
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
11 changes: 6 additions & 5 deletions src/dialog/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,27 @@
* @param {object} oMessage The message in the command
* @param {string} oMessage.lib The dialog library to use for the message
* @param {string} oMessage.type The message type
* @param {object} oMessage.title The message title
* @param {string} sMessage The message text
* @param {string} oMessage.text The message text
* @param {string=} oMessage.title The message title
*
* @returns {void}
*/
self.alert = ({ lib: sLibName, type: sType, title: sTitle }, sMessage) =>
self.alert = ({ lib: sLibName, type: sType, title: sTitle = '', text: sMessage }) =>
self.get(sLibName).alert(sType, sMessage, sTitle);

/**
* Call a function after user confirmation.
*
* @param {object} oQuestion The question in the command
* @param {string} oQuestion.lib The dialog library to use for the question
* @param {string} sQuestion The question text
* @param {string} oQuestion.text The question text
* @param {string=} oQuestion.title The question title
* @param {function} fYesCb The function to call if the question is confirmed
* @param {function} fNoCb The function to call if the question is not confirmed
*
* @returns {void}
*/
self.confirm = ({ lib: sLibName, title: sTitle }, sQuestion, fYesCb, fNoCb) =>
self.confirm = ({ lib: sLibName, title: sTitle = '', text: sQuestion }, fYesCb, fNoCb) =>
self.get(sLibName).confirm(sQuestion, sTitle, fYesCb, fNoCb);

/**
Expand Down
10 changes: 10 additions & 0 deletions src/jaxon.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ jaxon.jq = jaxon.parser.query.jq;
*/
jaxon.exec = jaxon.parser.call.execExpr;

/**
* Shortcut to <jaxon.dialog.lib.confirm>.
*/
jaxon.confirm = jaxon.dialog.lib.confirm;

/**
* Shortcut to <jaxon.dialog.lib.alert>.
*/
jaxon.alert = jaxon.dialog.lib.alert;

/**
* Shortcut to <jaxon.utils.dom.ready>.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/parser/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
* @returns {void}
*/
const showMessage = (message) => !!message &&
dialog.alert(message, self.makePhrase(message.phrase));
dialog.alert({ ...message, text: self.makePhrase(message.phrase) });

/**
* @param {object} question The confirmation question
Expand All @@ -196,7 +196,7 @@
* @returns {boolean}
*/
const execWithConfirmation = (question, message, aCalls, oCallContext) =>
dialog.confirm(question, self.makePhrase(question.phrase),
dialog.confirm({ ...question, text: self.makePhrase(question.phrase) },
() => execCalls(aCalls, oCallContext), () => showMessage(message));

/**
Expand All @@ -220,7 +220,7 @@
* @param {object} xExpression
* @param {object} oCallContext The context to execute calls in.
*
* @returns {void}
* @returns {mixed}
*/
const execExpression = (xExpression, oCallContext) => {
const { calls, question, condition, message } = xExpression;
Expand All @@ -232,7 +232,7 @@
execWithCondition(condition, message, calls, oCallContext);
return;
}
execCalls(calls, oCallContext);
return execCalls(calls, oCallContext);
};

/**
Expand Down
34 changes: 17 additions & 17 deletions tests/call.json.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const $ = require('jquery');
const {
call: { json, query },
parser: { call, query },
} = require('../dist/jaxon.module');

// Set jQuery in the DOM util.
Expand All @@ -10,7 +10,7 @@ test('Read str value from the DOM', () => {
document.body.innerHTML = `<div id="wrapper"><span id="integer">1024</span></div>`;

// Javascript code: const strValue = $('#integer')->text()
const strValue = json.execExpr({
const strValue = call.execExpr({
calls: [{
_type: 'select',
_name: '#integer',
Expand All @@ -27,7 +27,7 @@ test('Read str value from the DOM', () => {
document.body.innerHTML = `<div id="wrapper"><span id="integer">1024</span></div>`;

// Javascript code: const strValue = $('#integer')->html()
const strValue = json.execExpr({
const strValue = call.execExpr({
calls: [{
_type: 'select',
_name: '#integer',
Expand All @@ -44,7 +44,7 @@ test('Read int value from the DOM', () => {
document.body.innerHTML = `<div id="wrapper"><span id="integer">1024</span></div>`;

// Javascript code: const intValue = parseInt($('#integer')->text())
const intValue = json.execExpr({
const intValue = call.execExpr({
calls: [{
_type: 'func',
_name: 'parseInt',
Expand All @@ -68,7 +68,7 @@ test('Read int value from the DOM, with the toInt() "method"', () => {
document.body.innerHTML = `<div id="wrapper"><span id="integer">1024</span></div>`;

// Javascript code: const intValue = parseInt($('#integer')->text())
const intValue = json.execExpr({
const intValue = call.execExpr({
calls: [{
_type: 'select',
_name: '#integer',
Expand All @@ -88,7 +88,7 @@ test('Assign element inner html', () => {
document.body.innerHTML = `<div id="wrapper"><span id="username"></span></div>`;

// Javascript code: $('#username')->html('Mister Johnson')
json.execExpr({
call.execExpr({
calls: [{
_type: 'select',
_name: '#username',
Expand All @@ -106,7 +106,7 @@ test('Assign element outer html', () => {
document.body.innerHTML = `<div id="wrapper"><span id="username">Feuzeu</span></div>`;

// Javascript code: $('#username')->prop('outerHTML', 'Mister Johnson')
json.execExpr({
call.execExpr({
calls: [{
_type: 'select',
_name: '#username',
Expand All @@ -125,7 +125,7 @@ test('Set an event handler', () => {

// Set an event handler
// Javascript code: $('#username')->on('click', () => $('#username')->html('Mister Johnson'))
json.execExpr({
call.execExpr({
calls: [{
_type: 'select',
_name: '#username',
Expand Down Expand Up @@ -159,7 +159,7 @@ test('Use "this" in an event handler', () => {

// Set an event handler
// Javascript code: $('.username')->on('click', () => $(this)->html('Mister Johnson'))
json.execExpr({
call.execExpr({
calls: [{
_type: 'select',
_name: '.username',
Expand Down Expand Up @@ -192,7 +192,7 @@ test('Access to undefined vars', () => {
expect(window.defValue).toBe(undefined);

// Javascript code: const undefValue1 = window.defValue
const undefValue1 = json.execExpr({
const undefValue1 = call.execExpr({
calls: [{
_type: 'attr',
_name: 'defValue',
Expand All @@ -202,7 +202,7 @@ test('Access to undefined vars', () => {
expect(undefValue1).toBe(undefined);

// Javascript code: window.defValue = '1024'
json.execExpr({
call.execExpr({
calls: [{
_type: 'attr',
_name: 'defValue',
Expand All @@ -213,7 +213,7 @@ test('Access to undefined vars', () => {
expect(window.defValue).toBe('1024');

// Javascript code: const defValue = window.defValue
const defValue = json.execExpr({
const defValue = call.execExpr({
calls: [{
_type: 'attr',
_name: 'defValue',
Expand All @@ -223,7 +223,7 @@ test('Access to undefined vars', () => {
expect(defValue).toBe('1024');

// Javascript code: const undefValue2 = window.defValue.intValue
const undefValue2 = json.execExpr({
const undefValue2 = call.execExpr({
calls: [{
_type: 'attr',
_name: 'defValue',
Expand All @@ -236,7 +236,7 @@ test('Access to undefined vars', () => {
expect(undefValue2).toBe(undefined);

// Javascript code: const undefValue3 = window.intValue.defValue
const undefValue3 = json.execExpr({
const undefValue3 = call.execExpr({
calls: [{
_type: 'attr',
_name: 'intValue',
Expand All @@ -253,7 +253,7 @@ test('Access to "global" vars', () => {
expect(window.strValue).toBe(undefined);

// Javascript code: window.strValue = '1024'
json.execExpr({
call.execExpr({
calls: [{
_type: 'attr',
_name: 'strValue',
Expand All @@ -264,7 +264,7 @@ test('Access to "global" vars', () => {
expect(window.strValue).toBe('1024');

// Javascript code: const strValue = window.strValue
const strValue = json.execExpr({
const strValue = call.execExpr({
calls: [{
_type: 'attr',
_name: 'strValue',
Expand All @@ -274,7 +274,7 @@ test('Access to "global" vars', () => {
expect(strValue).toBe('1024');

// Javascript code: const intValue = parseInt(window.strValue)
const intValue = json.execExpr({
const intValue = call.execExpr({
calls: [{
_type: 'func',
_name: 'parseInt',
Expand Down

0 comments on commit ed35730

Please sign in to comment.