cobalt.taxonomy.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. (function($) {
  2. $(document).bind('cobalt-load', function(evt, cobalt) {
  3. var plugin = {
  4. 'version': 0,
  5. 'catalogs': {},
  6. 'handlers': []
  7. };
  8. plugin['catalogs']['vocabularies'] = {
  9. 'update': function(last_update, callback) {
  10. $.getJSON(Drupal.settings.basePath + 'cobalt/data/taxonomy_json', {}, function (data) {
  11. cobalt.emptyCatalog('vocabularies');
  12. var access = data.access ? 'w' : '';
  13. for (var id in data.vocabularies) {
  14. cobalt.addEntry({id:id, name:data.vocabularies[id], information:access, catalog:'vocabularies', classname:'vocabulary'});
  15. }
  16. cobalt.emptyCatalog('terms');
  17. for (var id in data.terms) {
  18. cobalt.addEntry({id:id, name:data.terms[id][0], information:{'perm': access, 'vid': data.terms[id][1]}, catalog:'terms', classname:'term'});
  19. }
  20. callback(false);
  21. });
  22. },
  23. 'install': function() {
  24. },
  25. 'uninstall': function() {
  26. },
  27. 'update_rate': 60000
  28. };
  29. // Insert empty catalog, the update function is handled for both catalogs in
  30. // the vocabularies catalog.
  31. plugin['catalogs']['terms'] = {};
  32. // Register handlers
  33. plugin['handlers'].push({
  34. 'id': 'vocabulary_list',
  35. 'name': Drupal.t('List terms'),
  36. 'data_class': 'vocabulary',
  37. 'applicable': function(text, item) {
  38. return item.information == 'w';
  39. },
  40. 'handler': function(text, item) {
  41. window.location.href = Drupal.settings.basePath + 'admin/structure/taxonomy/' + item.id + '/list';
  42. }
  43. });
  44. plugin['handlers'].push({
  45. 'id': 'vocabulary_edit',
  46. 'name': Drupal.t('Edit'),
  47. 'data_class': 'vocabulary',
  48. 'applicable': function(text, item) {
  49. return item.information == 'w';
  50. },
  51. 'handler': function(text, item) {
  52. window.location.href = Drupal.settings.basePath + 'admin/structure/taxonomy/edit/vocabulary/' + item.id + '?destination=' + Drupal.settings.cobalt.path;
  53. }
  54. });
  55. plugin['handlers'].push({
  56. 'id': 'vocabulary_add',
  57. 'name': Drupal.t('Add terms'),
  58. 'data_class': 'vocabulary',
  59. 'applicable': function(text, item) {
  60. return item.information == 'w';
  61. },
  62. 'handler': function(text, item) {
  63. window.location.href = Drupal.settings.basePath + 'admin/structure/taxonomy/' + item.id + '/list/add';
  64. }
  65. });
  66. plugin['handlers'].push({
  67. 'id': 'term_view',
  68. 'name': Drupal.t('View'),
  69. 'data_class': 'term',
  70. 'handler': function(text, item) {
  71. window.location.href = Drupal.settings.basePath + 'taxonomy/term/' + item.id;
  72. }
  73. });
  74. plugin['handlers'].push({
  75. 'id': 'term_edit',
  76. 'name': Drupal.t('Edit'),
  77. 'data_class': 'term',
  78. 'applicable': function(text, item) {
  79. return item.information.perm == 'w';
  80. },
  81. 'handler': function(text, item) {
  82. window.location.href = Drupal.settings.basePath + 'taxonomy/term/' + item.id + '/edit?destination=' + Drupal.settings.cobalt.path;
  83. }
  84. });
  85. cobalt.registerPlugin('cobalttaxonomy', plugin);
  86. });
  87. })(jQuery);