Browse Source

Updates to API

pull/1177/head
jlukic 10 years ago
parent
commit
40b11b85a2
1 changed files with 42 additions and 35 deletions
  1. 77
      src/definitions/behaviors/api.js

77
src/definitions/behaviors/api.js

@ -124,7 +124,7 @@ $.api = $.fn.api = function(parameters) {
} }
// Add form content // Add form content
if(settings.serializeForm !== false || $module.is('form')) {
if(settings.serializeForm !== false || $context.is('form')) {
if(settings.serializeForm == 'json') { if(settings.serializeForm == 'json') {
$.extend(true, settings.data, module.get.formData()); $.extend(true, settings.data, module.get.formData());
} }
@ -401,10 +401,10 @@ $.api = $.fn.api = function(parameters) {
setTimeout(module.remove.error, settings.errorDuration); setTimeout(module.remove.error, settings.errorDuration);
} }
module.debug('API Request error:', errorMessage); module.debug('API Request error:', errorMessage);
$.proxy(settings.onFailure, context)(errorMessage, $module);
$.proxy(settings.onError, context)(errorMessage, context);
} }
else { else {
$.proxy(settings.onAbort, context)(errorMessage, $module);
$.proxy(settings.onAbort, context)(errorMessage, context);
module.debug('Request Aborted (Most likely caused by page change or CORS Policy)', status, httpMessage); module.debug('Request Aborted (Most likely caused by page change or CORS Policy)', status, httpMessage);
} }
} }
@ -463,22 +463,30 @@ $.api = $.fn.api = function(parameters) {
runSettings runSettings
; ;
runSettings = $.proxy(settings.beforeSend, $module)(settings); runSettings = $.proxy(settings.beforeSend, $module)(settings);
if(runSettings.success !== undefined) {
module.debug('Legacy success callback detected', runSettings);
module.error(error.legacyParameters);
runSettings.onSuccess = runSettings.success;
}
if(runSettings.failure !== undefined) {
module.debug('Legacy failure callback detected', runSettings);
module.error(error.legacyParameters);
runSettings.onFailure = runSettings.failure;
if(runSettings) {
if(runSettings.success !== undefined) {
module.debug('Legacy success callback detected', runSettings);
module.error(error.legacyParameters);
runSettings.onSuccess = runSettings.success;
}
if(runSettings.failure !== undefined) {
module.debug('Legacy failure callback detected', runSettings);
module.error(error.legacyParameters);
runSettings.onFailure = runSettings.failure;
}
if(runSettings.complete !== undefined) {
module.debug('Legacy complete callback detected', runSettings);
module.error(error.legacyParameters);
runSettings.onComplete = runSettings.complete;
}
} }
if(runSettings.complete !== undefined) {
module.debug('Legacy complete callback detected', runSettings);
module.error(error.legacyParameters);
runSettings.onComplete = runSettings.complete;
if(runSettings === undefined) {
module.error(error.noReturnedValue);
} }
return runSettings;
return (runSettings !== undefined)
? runSettings
: settings
;
}, },
defaultData: function() { defaultData: function() {
var var
@ -526,17 +534,14 @@ $.api = $.fn.api = function(parameters) {
var var
formData formData
; ;
if(settings.serializeForm == 'json') {
if($(this).toJSON === undefined ) {
module.error(error.missingSerialize);
return;
}
formData = $form.toJSON();
if($(this).serializeObject() !== undefined) {
formData = $form.serializeObject();
} }
else { else {
module.error(error.missingSerialize);
formData = $form.serialize(); formData = $form.serialize();
} }
module.debug('Retrieving form data', formData);
module.debug('Retrieved form data', formData);
return formData; return formData;
}, },
templateURL: function(action) { templateURL: function(action) {
@ -628,7 +633,7 @@ $.api = $.fn.api = function(parameters) {
performance.push({ performance.push({
'Name' : message[0], 'Name' : message[0],
'Arguments' : [].slice.call(message, 1) || '', 'Arguments' : [].slice.call(message, 1) || '',
'Element' : element,
//'Element' : element,
'Execution Time' : executionTime 'Execution Time' : executionTime
}); });
} }
@ -755,6 +760,10 @@ $.api.settings = {
filter : '.disabled', filter : '.disabled',
stateContext : false, stateContext : false,
// state
loadingDuration : 0,
errorDuration : 2000,
// templating // templating
action : false, action : false,
url : false, url : false,
@ -767,15 +776,6 @@ $.api.settings = {
serializeForm : false, serializeForm : false,
throttle : 0, throttle : 0,
// state
loadingDuration : 0,
errorDuration : 2000,
regExp : {
required: /\{\$*[A-z0-9]+\}/g,
optional: /\{\/\$*[A-z0-9]+\}/g,
},
// jQ ajax // jQ ajax
method : 'get', method : 'get',
data : {}, data : {},
@ -788,6 +788,7 @@ $.api.settings = {
onSuccess : function(response, $module) {}, onSuccess : function(response, $module) {},
onComplete : function(response, $module) {}, onComplete : function(response, $module) {},
onFailure : function(errorMessage, $module) {}, onFailure : function(errorMessage, $module) {},
onError : function(errorMessage, $module) {},
onAbort : function(errorMessage, $module) {}, onAbort : function(errorMessage, $module) {},
successTest : false, successTest : false,
@ -800,14 +801,20 @@ $.api.settings = {
JSONParse : 'JSON could not be parsed during error handling', JSONParse : 'JSON could not be parsed during error handling',
legacyParameters : 'You are using legacy API success callback names', legacyParameters : 'You are using legacy API success callback names',
missingAction : 'API action used but no url was defined', missingAction : 'API action used but no url was defined',
missingSerialize : 'Serializing a Form requires toJSON to be included',
missingSerialize : 'Required dependency jquery-serialize-object missing, using basic serialize',
missingURL : 'No URL specified for api event', missingURL : 'No URL specified for api event',
noReturnedValue : 'The beforeSend callback must return a settings object, beforeSend ignored.',
parseError : 'There was an error parsing your request', parseError : 'There was an error parsing your request',
requiredParameter : 'Missing a required URL parameter: ', requiredParameter : 'Missing a required URL parameter: ',
statusMessage : 'Server gave an error: ', statusMessage : 'Server gave an error: ',
timeout : 'Your request timed out' timeout : 'Your request timed out'
}, },
regExp : {
required: /\{\$*[A-z0-9]+\}/g,
optional: /\{\/\$*[A-z0-9]+\}/g,
},
className: { className: {
loading : 'loading', loading : 'loading',
error : 'error' error : 'error'

Loading…
Cancel
Save