arkiwi.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*------------------------------------------------------------------------------------------------------------------------
  2. @package: arkiwiJsBoilerplate
  3. @author: cek
  4. @www: arkiwi.oeg
  5. @copyright: COPYRIGHT 18 cek
  6. @license: MIT
  7. =============================================================================
  8. Filename: arkiwi.js
  9. =============================================================================
  10. This file is the main entry point for js on the arkiwiJsBoilerplate app.
  11. --------------------------------------------------------------------------------------------------------------------- */
  12. var ARKIWI = ARKIWI || {};
  13. ARKIWI.Aggregator = function (aggregator, defaultParameters) {
  14. this.aggregator = aggregator;
  15. this.defaultParameters = defaultParameters || '';
  16. };
  17. ARKIWI.Aggregator.constructor = ARKIWI.Aggregator;
  18. /* Chiede all'aggregatore i metadati su una cartella o un file. */
  19. ARKIWI.Aggregator.prototype.path = function (path, callback, notBase64) {
  20. var pathType = notBase64 ? 'path' : 'path64';
  21. $.getJSON(this.aggregator + '/' + pathType + '/' + path + '/json/?' + this.defaultParameters, function (result) {
  22. if (callback != undefined)
  23. callback(result);
  24. }).fail(function (error) {
  25. throw 'Arkiwi.path(): status ' + status + ' error ' + error.responseText;
  26. });
  27. };
  28. ARKIWI.Aggregator.prototype.getRSS = function (path, callback, notBase64) {
  29. var pathType = notBase64 ? 'path' : 'path64';
  30. $.getJSON(this.aggregator + '/' + pathType + '/' + path + '/rss/?' + this.defaultParameters, function (result) {
  31. if (callback != undefined)
  32. callback(result);
  33. }).fail(function (error) {
  34. throw 'Arkiwi.getRSS(): status ' + status + ' error ' + error.responseText;
  35. });
  36. };
  37. ARKIWI.Aggregator.prototype.getJsonML = function (path, callback, notBase64) {
  38. var pathType = notBase64 ? 'path' : 'path64';
  39. $.getJSON(this.aggregator + '/' + pathType + '/' + path + '/jsonml/?' + this.defaultParameters, function (result) {
  40. if (callback != undefined)
  41. callback(result);
  42. }).fail(function (error) {
  43. throw 'Arkiwi.getJsonML(): status ' + status + ' error ' + error.responseText;
  44. });
  45. };
  46. /* Esegue un ricerca sull'aggregatore */
  47. ARKIWI.Aggregator.prototype.search = function (query, callback, jailFolder) {
  48. var sanitizedQuery = query;
  49. if (jailFolder) {
  50. //FIXME non c'è controllo sul contenuto di jailFolder
  51. sanitizedQuery = '+file:' + jailFolder + '* AND ' + query;
  52. }
  53. sanitizedQuery = window.btoa(sanitizedQuery); //convert to Base64
  54. $.getJSON(this.aggregator + '/search64/' + sanitizedQuery + '/json/?' + this.defaultParameters, function (result) {
  55. if (callback != undefined)
  56. callback(result);
  57. }).fail(function (error) {
  58. throw 'Arkiwi.search(): status ' + status + ' error ' + error.responseText;
  59. });
  60. };