diff --git a/importer/indico_importer/__init__.py b/importer/indico_importer/__init__.py index ed18340..f898e9a 100644 --- a/importer/indico_importer/__init__.py +++ b/importer/indico_importer/__init__.py @@ -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/', 'import', RHDataImport, methods=('GET', 'POST')) +blueprint.add_url_rule('/import/', 'import_data', RHDataImport, methods=('GET', 'POST')) blueprint.add_url_rule('/importers', 'importers', RHGetImporters, methods=('GET', 'POST')) diff --git a/importer/indico_importer/controllers.py b/importer/indico_importer/controllers.py index 86db73a..0a42a74 100644 --- a/importer/indico_importer/controllers.py +++ b/importer/indico_importer/controllers.py @@ -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) diff --git a/importer/indico_importer/static/js/importer.js b/importer/indico_importer/static/js/importer.js index 55207eb..c09de80 100644 --- a/importer/indico_importer/static/js/importer.js +++ b/importer/indico_importer/static/js/importer.js @@ -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;