Adapt JS to new REST API

This commit is contained in:
Alejandro Avilés 2014-10-27 14:16:55 +01:00
parent ff40cfc06e
commit 4d6222c72b
3 changed files with 38 additions and 22 deletions

View File

@ -1,5 +1,5 @@
from indico.core import signals
from indico.core.plugins import IndicoPlugin, IndicoPluginBlueprint
from indico.core.plugins import IndicoPlugin, IndicoPluginBlueprint, plugin_url_rule_to_js
from MaKaC.webinterface.pages.conferences import WPConfModifScheduleGraphic
from .controllers import RHDataImport, RHGetImporters
@ -25,11 +25,15 @@ class ImporterPlugin(IndicoPlugin):
def get_timetable_buttons(self, *args, **kwargs):
yield ('Importer', 'createImporterDialog')
def get_vars_js(self):
return {'urls': {'import_data': plugin_url_rule_to_js('importer.import_data'),
'importers': plugin_url_rule_to_js('importer.importers')}}
def register_assets(self):
self.register_js_bundle('importer_js', 'js/importer.js')
self.register_css_bundle('importer_css', 'css/importer.css')
blueprint = IndicoPluginBlueprint('importer', __name__)
blueprint.add_url_rule('/import/<importer_name>', 'import', RHDataImport, methods=('GET', 'POST'))
blueprint.add_url_rule('/import/<importer_name>', 'import_data', RHDataImport, methods=('GET', 'POST'))
blueprint.add_url_rule('/importers', 'importers', RHGetImporters, methods=('GET', 'POST'))

View File

@ -15,7 +15,7 @@ class RHDataImport(RHProtected):
def process(self, params):
importer = current_plugin.importers.get(params['importer_name'])
if not importer:
return 'No such importer available'
return jsonify(dict(success=False))
query = params.get('query')
size = params.get('size', 10)
return importer.import_data(query, size)

View File

@ -205,11 +205,17 @@ type("ImportDialog", ["ExclusivePopupWithButtons", "PreLoadHandler"], {
/** Loads a list of importers from the server */
function(hook) {
var self = this;
indicoRequest('importer.getImporters', {}, function(result, error) {
if (!error) {
self.importers = result;
$.ajax({
url: build_url(ImporterPlugin.urls.importers, {}),
type: 'POST',
dataType: 'json',
success: function(data) {
if (handleAjaxError(data)) {
return;
}
self.importers = data;
hook.set(true);
}
hook.set(true);
});
}
],
@ -636,21 +642,27 @@ type("ImporterListWidget", ["SelectableListWidget"], {
_searchBase: function(query, importer, size, successFunc, callbacks) {
var self = this;
var killProgress = IndicoUI.Dialogs.Util.progress();
indicoRequest("importer.import",
{'importer': importer,
'query': query,
// One more entry is fetched to be able to check if it's possible to fetch
// more entries in case of further requests.
'size': size + 1},
function(result, error) {
if (!error && result && successFunc) {
successFunc(result);
}
each(callbacks, function(callback) {
callback();
});
killProgress();
});
$.ajax({
// One more entry is fetched to be able to check if it's possible to fetch
// more entries in case of further requests.
url: build_url(ImporterPlugin.urls.import_data, {'importer_name': importer,
'query': query,
'size': size + 1}),
type: 'POST',
dataType: 'json',
success: function(data) {
if (handleAjaxError(data)) {
return;
}
if (data.success) {
successFunc(data.result);
}
each(callbacks, function(callback) {
callback();
});
killProgress();
}
});
//Saves last request data
this.lastSearchImporter = importer;
this.lastSearchQuery = query;