Skip to content

Commit

Permalink
Add support for validation feedback.
Browse files Browse the repository at this point in the history
Model and property validation results are now passed on to the AdminAction feedback system.

Changes:
- Added ‘AbstractSaveAction’ which holds all common methods and features between ‘SaveAction’ (Create) and ‘UpdateAction’;
- Revamped XHR request in form.js and quickform.js to better handle errors and processing of feedback;
- Improved output of feedback in dialog;
  • Loading branch information
mcaskill committed Sep 20, 2016
1 parent fb1c44e commit 1202886
Show file tree
Hide file tree
Showing 15 changed files with 895 additions and 470 deletions.
482 changes: 335 additions & 147 deletions assets/dist/scripts/charcoal.admin.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions assets/dist/scripts/charcoal.admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/dist/scripts/charcoal.admin.vendors.min.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion assets/dist/styles/charcoal.admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ a:focus {
width: 24px;
margin-right: -6px; }

.bootstrap-dialog .bootstrap-dialog-message .alert:last-child {
.bootstrap-dialog .bootstrap-dialog-message :last-child {
margin-bottom: 0; }

.bootstrap-dialog .modal-body .nav-tabs {
Expand Down Expand Up @@ -1771,3 +1771,27 @@ a:focus {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis; }

.u-spin {
-webkit-animation: spin 1.5s infinite linear;
animation: spin 1.5s infinite linear; }
.u-spin.glyphicon-refresh {
-webkit-transform-origin: 50% 42%;
-ms-transform-origin: 50% 42%;
transform-origin: 50% 42%; }

@-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg); }
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg); } }

@keyframes spin {
from {
-webkit-transform: rotate(0deg);
transform: rotate(0deg); }
to {
-webkit-transform: rotate(360deg);
transform: rotate(360deg); } }
52 changes: 52 additions & 0 deletions assets/src/scripts/charcoal/admin/charcoal.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,58 @@ Charcoal.Admin = (function ()
return this.cachePool[key];
};

/**
* Resolves the context of parameters for the "complete" callback option.
*
* (`jqXHR.always(function( data|jqXHR, textStatus, jqXHR|errorThrown ) {})`).
*
* @param {...} Successful or failed argument list.
* @return {mixed[]} Standardized argument list.
*/
Admin.parseJqXhrArgs = function ()
{
var args = {
failed: true,
jqXHR: null,
textStatus: '',
errorThrown: '',
response: null
};

// If the third argument is a string, the request failed
// and the value is an error message: errorThrown;
// otherwise it's probably the XML HTTP Request Object.
if (arguments[2] && $.type(arguments[2]) === 'string') {
args.jqXHR = arguments[0] || null;
args.textStatus = arguments[1] || null;
args.errorThrown = arguments[2] || null;
args.response = arguments[3] || args.jqXHR.responseJSON || null;

if ($.type(args.response) === 'object') {
args.failed = !args.response.success;
} else {
args.failed = true;
}
} else {
args.response = arguments[0] || null;
args.textStatus = arguments[1] || null;
args.jqXHR = arguments[2] || null;
args.errorThrown = null;

if (args.response === null) {
args.response = args.jqXHR.responseJSON;
}

if ($.type(args.response) === 'object') {
args.failed = !args.response.success;
} else {
args.failed = false;
}
}

return args;
};

return Admin;

}());
32 changes: 30 additions & 2 deletions assets/src/scripts/charcoal/admin/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Charcoal.Admin.Feedback = function ()
title: 'Succès!',
type: BootstrapDialog.TYPE_SUCCESS
},
info: {
title: 'Information!',
type: BootstrapDialog.TYPE_INFO,
alias: ['notice']
},
warning: {
title: 'Attention!',
type: BootstrapDialog.TYPE_WARNING
Expand All @@ -32,6 +37,11 @@ Charcoal.Admin.Feedback = function ()
type: BootstrapDialog.TYPE_DANGER
}
};

this.context_aliases = {
notice: 'info'
};

return this;
};

Expand Down Expand Up @@ -115,6 +125,20 @@ Charcoal.Admin.Feedback.prototype.add_context = function (context) {
return this;
};

/**
* A an alias to an existing context
* @return this
*/
Charcoal.Admin.Feedback.prototype.add_context_alias = function (alias, context) {
if (!alias || !context || !this.context_definitions[ context ]) {
return this;
}

this.context_aliases[ alias ] = context;

return this;
};

/**
* Actions in the dialog box
*/
Expand Down Expand Up @@ -150,6 +174,10 @@ Charcoal.Admin.Feedback.prototype.call = function ()
}

for (var level in ret) {
if (typeof this.context_aliases[ level ] === 'string') {
level = this.context_aliases[ level ];
}

if (typeof this.context_definitions[ level ] === 'undefined') {
continue;
}
Expand All @@ -162,15 +190,15 @@ Charcoal.Admin.Feedback.prototype.call = function ()
for (; k < count; k++) {
var action = this.actions[ k ];
buttons.push({
label: action.label,
label: action.label,
action: action.callback
});
}
}

BootstrapDialog.show({
title: this.context_definitions[ level ].title,
message: ret[ level ].join('<br/>'),
message: '<p>' + ret[ level ].join('</p><p>') + '</p>',
type: this.context_definitions[ level ].type,
buttons: buttons
});
Expand Down
Loading

0 comments on commit 1202886

Please sign in to comment.