Clean ipa.js and make it load plugin meta-data over JSON-RPC.

What it means?
Well, first I removed some development control variables from ipa.js.
Namely useSampleData and sizelimit. I moved useSampleData to the top
of index.xhtml. This way we won't forget about it when we don't need
it anymore. sizelimit has nothing to do in ipa.js and be hardcoded
for ALL commands! Some don't have this parameter and could fail.

Since ipa_init now loads meta-data over JSON-RPC, we need to wait for
it to finish its job. That's why I put a second parameter to ipa_init:
on_win. ipa_init will call on_win when all data is loaded properly and
we can start building the page.
This commit is contained in:
Pavel Zuna 2010-08-17 14:26:36 -04:00 committed by Adam Young
parent 2f4f9054aa
commit 6b63ab1c32
2 changed files with 46 additions and 34 deletions

View File

@ -7,6 +7,14 @@
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script> <script type="text/javascript" src="jquery.cookie.js"></script>
<script type="text/javascript">
/* the develop.js file that follows will set this to true.
that file should only exist in the source file system
and should not get deployed to the web server */
var useSampleData = false;
</script>
<script type="text/javascript" src="ipa.js" /> <script type="text/javascript" src="ipa.js" />
<script type="text/javascript" src="pageparams.js" /> <script type="text/javascript" src="pageparams.js" />
@ -25,7 +33,10 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function(){ $(document).ready(function(){
buildNavigation(); if (useSampleData)
ipa_init(sampleData, buildNavigation);
else
ipa_init(null, buildNavigation);
}); });
</script> </script>
@ -49,8 +60,8 @@
</div> </div>
<div id="search" style="visibility:hidden"> <div id="search" style="visibility:hidden">
<div id="searchControls" class="searchControls" > <div class="searchControls" >
<span id="filter" class="filter" > <span class="filter" >
<input id="queryFilter" type="text"/> <input id="queryFilter" type="text"/>
<input id="query" type="submit" value="find" /> <input id="query" type="submit" value="find" />
<input id="new" type="submit" value="new" /> <input id="new" type="submit" value="new" />

View File

@ -18,17 +18,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
//the develop.js file that follows will set this to true.
//that file should only exist in the source file system
//and should not get deployed to the web server
var useSampleData = false;
//Maximum number of records to return on any query.
var sizelimit=100;
/* IPA JSON-RPC helper */ /* IPA JSON-RPC helper */
/* JSON-RPC ID counter */ /* JSON-RPC ID counter */
@ -37,11 +26,35 @@ var ipa_jsonrpc_id = 0;
/* IPA objects data in JSON format */ /* IPA objects data in JSON format */
var ipa_objs = {}; var ipa_objs = {};
var _ipa_init_on_win_callback = null;
/* initialize the IPA JSON-RPC helper /* initialize the IPA JSON-RPC helper
* arguments: * arguments:
* url - JSON-RPC URL to use (optional) */ * url - JSON-RPC URL to use (optional) */
function ipa_init(url) function ipa_init(url, on_win)
{ {
if (!url)
url = '/ipa/json';
_ipa_init_on_win_callback = on_win;
var options = {
url: url,
type: 'POST',
contentType: 'application/json',
dataType: 'json',
processData: false,
};
$.ajaxSetup(options);
ipa_cmd('json_metadata', [], {}, _ipa_load_objs);
}
function _ipa_load_objs(data, textStatus, xhr)
{
ipa_objs = data.result.result;
if (_ipa_init_on_win_callback)
_ipa_init_on_win_callback(data, textStatus, xhr);
} }
/* call an IPA command over JSON-RPC /* call an IPA command over JSON-RPC
@ -58,31 +71,19 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname)
if (objname) if (objname)
name = objname + '_' + name; name = objname + '_' + name;
options.sizelimit = sizelimit;
var data = { var data = {
method: name, method: name,
params: [args, options], params: [args, options],
id: id, id: id,
}; };
var jsonUrl = '/ipa/json'; var request = {
if (useSampleData){
jsonUrl = sampleData;
}
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Accept","application/json");
},
type: "POST",
url: jsonUrl,
processData: false,
data: JSON.stringify(data), data: JSON.stringify(data),
dataType: "json",
success: win_callback, success: win_callback,
error: fail_callback, error: fail_callback,
}); };
$.ajax(request);
return (id); return (id);
} }