PageRenderTime 54ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/static/scripts/mvc/citation/citation-model.js

https://bitbucket.org/hbc/galaxy-central-hbc/
JavaScript | 73 lines | 46 code | 6 blank | 21 comment | 1 complexity | fe664eefb29bf36d1d345e42cedd2f77 MD5 | raw file
Possible License(s): CC-BY-3.0
  1. define([
  2. "mvc/base-mvc",
  3. "utils/localization"
  4. ], function( baseMVC, _l ){
  5. /* global Backbone */
  6. //==============================================================================
  7. /** @class model for tool citations.
  8. * @name Citation
  9. *
  10. * @augments Backbone.Model
  11. * @borrows LoggableMixin#logger as #logger
  12. * @borrows LoggableMixin#log as #log
  13. * @constructs
  14. */
  15. var Citation = Backbone.Model.extend( baseMVC.LoggableMixin ).extend( {
  16. initialize: function( ) {
  17. var bibtex = this.attributes.content;
  18. var entry = new BibtexParser(bibtex).entries[0];
  19. this.entry = entry;
  20. this._fields = {};
  21. var rawFields = entry.Fields;
  22. for(key in rawFields) {
  23. var value = rawFields[ key ];
  24. var lowerKey = key.toLowerCase();
  25. this._fields[ lowerKey ] = value;
  26. }
  27. },
  28. entryType: function() {
  29. return this.entry.EntryType;
  30. },
  31. fields: function() {
  32. return this._fields;
  33. }
  34. } );
  35. //==============================================================================
  36. /** @class Backbone collection of citations.
  37. *
  38. * @borrows LoggableMixin#logger as #logger
  39. * @borrows LoggableMixin#log as #log
  40. * @constructs
  41. */
  42. var BaseCitationCollection = Backbone.Collection.extend( baseMVC.LoggableMixin ).extend( {
  43. /** root api url */
  44. urlRoot : galaxy_config.root + 'api',
  45. partial : true, // Assume some tools in history/workflow may not be properly annotated yet.
  46. model : Citation,
  47. } );
  48. var HistoryCitationCollection = BaseCitationCollection.extend( {
  49. /** complete api url */
  50. url : function() {
  51. return this.urlRoot + '/histories/' + this.history_id + '/citations';
  52. }
  53. } );
  54. var ToolCitationCollection = BaseCitationCollection.extend( {
  55. /** complete api url */
  56. url : function() {
  57. return this.urlRoot + '/tools/' + this.tool_id + '/citations';
  58. },
  59. partial : false, // If a tool has citations, assume they are complete.
  60. } );
  61. //==============================================================================
  62. return {
  63. Citation : Citation,
  64. HistoryCitationCollection : HistoryCitationCollection,
  65. ToolCitationCollection: ToolCitationCollection
  66. };
  67. });