read.js | |
---|---|
/*global Ply */
/*jshint eqeqeq: true, curly: true, white: true */ | |
The Read module is an abstraction on top of Ajax for loading particular views, or named URLs. | |
By convention, every view defined has a read method created for it on | |
This module also exists as a namespace for user-defined read functions that are created
outside of the automatic view instantiation process. The intention is to avoid explicitly
using | |
Note that this module makes no assumption about REST, and does not handle requests for any other HTTP verbs. An extension for handling POST and UPDATE requests may come in the future, but has not yet been deemed useful. | |
Public Methods | |
Define the | Ply.read = (function () {
return { |
AddThis function is used by clients as well as the UI module to
create new read functions. Usage is to pass in a | add: function (name, url) { |
Check if the first argument is an object. | if (typeof name === 'object') { |
If so, iterate over all own properties. | for (var n in name) {
if (name.hasOwnProperty(n)) { |
Call the add method again with the name/url pair. | Ply.read.add(n, name[n]);
}
}
return;
} |
Create a method on | this[name] = function (data, success, failure) { |
Return the result of calling Ply.ajax.request, so the XHR object gets returned to the user. Allows them to call methods of the XHR. | return Ply.ajax.request({
url: url,
type: 'GET',
data: data
}, success, failure);
};
}
};
})(); |
↪ UI | |