PageRenderTime 33ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/static/scripts/mvc/library/library-folderrow-view.js

https://bitbucket.org/remy_d1/galaxy-central-manageapi
JavaScript | 150 lines | 127 code | 20 blank | 3 comment | 12 complexity | 1d7499aa3ad96257883821844387acb7 MD5 | raw file
Possible License(s): CC-BY-3.0
  1. define([
  2. "galaxy.masthead",
  3. "utils/utils",
  4. "libs/toastr",
  5. "mvc/library/library-model",
  6. "mvc/library/library-dataset-view"],
  7. function(mod_masthead,
  8. mod_utils,
  9. mod_toastr,
  10. mod_library_model,
  11. mod_library_dataset_view) {
  12. var FolderRowView = Backbone.View.extend({
  13. lastSelectedHistory: '',
  14. events: {
  15. 'click .undelete_dataset_btn' : 'undelete_dataset'
  16. },
  17. options: {
  18. type: null
  19. },
  20. initialize : function(folder_item){
  21. this.model = folder_item;
  22. this.render(folder_item);
  23. },
  24. render: function(folder_item){
  25. var template = null;
  26. if (folder_item.get('type') === 'folder'){
  27. this.options.type = 'folder';
  28. template = this.templateRowFolder();
  29. } else {
  30. this.options.type = 'file';
  31. if (folder_item.get('deleted')){
  32. template = this.templateRowDeletedFile();
  33. } else {
  34. template = this.templateRowFile();
  35. }
  36. }
  37. this.setElement(template({content_item:folder_item}));
  38. this.$el.show();
  39. return this;
  40. },
  41. showDatasetDetails : function(){
  42. Galaxy.libraries.datasetView = new mod_library_dataset_view.LibraryDatasetView({id: this.id});
  43. },
  44. /**
  45. * Undeletes the dataset on server and renders the row again.
  46. */
  47. undelete_dataset : function(event){
  48. $(".tooltip").hide();
  49. var that = this;
  50. var dataset_id = $(event.target).closest('tr')[0].id;
  51. var dataset = Galaxy.libraries.folderListView.collection.get(dataset_id);
  52. dataset.url = dataset.urlRoot + dataset.id + '?undelete=true';
  53. dataset.destroy({
  54. success : function(model, response){
  55. Galaxy.libraries.folderListView.collection.remove(dataset_id);
  56. var updated_dataset = new mod_library_model.Item(response);
  57. Galaxy.libraries.folderListView.collection.add(updated_dataset);
  58. mod_toastr.success('Dataset undeleted. Click this to see it.', '', {onclick: function() {
  59. var folder_id = that.model.get('folder_id');
  60. window.location='#folders/' + folder_id + '/datasets/' + that.id;
  61. }});
  62. },
  63. error : function(model, response){
  64. if (typeof response.responseJSON !== "undefined"){
  65. mod_toastr.error('Dataset was not undeleted. ' + response.responseJSON.err_msg);
  66. } else {
  67. mod_toastr.error('An error occured! Dataset was not undeleted. Please try again.');
  68. }
  69. }
  70. });
  71. },
  72. templateRowFolder: function() {
  73. tmpl_array = [];
  74. tmpl_array.push('<tr class="folder_row light library-row" id="<%- content_item.id %>">');
  75. tmpl_array.push(' <td>');
  76. tmpl_array.push(' <span title="Folder" class="fa fa-folder-o"></span>');
  77. tmpl_array.push(' </td>');
  78. tmpl_array.push(' <td></td>');
  79. tmpl_array.push(' <td>');
  80. tmpl_array.push(' <a href="#folders/<%- content_item.id %>"><%- content_item.get("name") %></a>');
  81. tmpl_array.push(' </td>');
  82. tmpl_array.push(' <td>folder</td>');
  83. tmpl_array.push(' <td></td>');
  84. tmpl_array.push(' <td><%= _.escape(content_item.get("update_time")) %></td>'); // time updated
  85. tmpl_array.push(' <td>');
  86. tmpl_array.push(' <% if (content_item.get("can_manage")) { %><a href="#/folders/<%- content_item.id %>/permissions"><button data-toggle="tooltip" data-placement="top" class="primary-button btn-xs permissions-folder-btn show_on_hover" title="Manage permissions" style="display:none;"><span class="fa fa-group"></span></button></a><% } %>');
  87. tmpl_array.push(' </td>');
  88. tmpl_array.push('</tr>');
  89. return _.template(tmpl_array.join(''));
  90. },
  91. templateRowFile: function(){
  92. tmpl_array = [];
  93. tmpl_array.push('<tr class="dataset_row light library-row" id="<%- content_item.id %>">');
  94. tmpl_array.push(' <td>');
  95. tmpl_array.push(' <span title="Dataset" class="fa fa-file-o"></span>');
  96. tmpl_array.push(' </td>');
  97. tmpl_array.push(' <td style="text-align: center; "><input style="margin: 0;" type="checkbox"></td>');
  98. tmpl_array.push(' <td><a href="#folders/<%- content_item.get("folder_id") %>/datasets/<%- content_item.id %>" class="library-dataset"><%- content_item.get("name") %><a></td>'); // dataset
  99. tmpl_array.push(' <td><%= _.escape(content_item.get("file_ext")) %></td>'); // data type
  100. tmpl_array.push(' <td><%= _.escape(content_item.get("file_size")) %></td>'); // size
  101. tmpl_array.push(' <td><%= _.escape(content_item.get("update_time")) %></td>'); // time updated
  102. tmpl_array.push(' <td>');
  103. tmpl_array.push(' <% if (content_item.get("is_unrestricted")) { %><span data-toggle="tooltip" data-placement="top" title="Unrestricted dataset" style="color:grey;" class="fa fa-globe fa-lg"></span><% } %>');
  104. tmpl_array.push(' <% if (content_item.get("is_private")) { %><span data-toggle="tooltip" data-placement="top" title="Private dataset" style="color:grey;" class="fa fa-key fa-lg"></span><% } %>');
  105. tmpl_array.push(' <% if ((content_item.get("is_unrestricted") === false) && (content_item.get("is_private") === false)) { %><span data-toggle="tooltip" data-placement="top" title="Restricted dataset" style="color:grey;" class="fa fa-shield fa-lg"></span><% } %>');
  106. tmpl_array.push(' <% if (content_item.get("can_manage")) { %><a href="#folders/<%- content_item.get("folder_id") %>/datasets/<%- content_item.id %>/permissions"><button data-toggle="tooltip" data-placement="top" class="primary-button btn-xs permissions-dataset-btn show_on_hover" title="Manage permissions" style="display:none;"><span class="fa fa-group"></span></button></a><% } %>');
  107. tmpl_array.push(' </td>');
  108. tmpl_array.push('</tr>');
  109. return _.template(tmpl_array.join(''));
  110. },
  111. templateRowDeletedFile: function(){
  112. tmpl_array = [];
  113. tmpl_array.push('<tr class="active deleted_dataset library-row" id="<%- content_item.id %>">');
  114. tmpl_array.push(' <td>');
  115. tmpl_array.push(' <span title="Dataset" class="fa fa-file-o"></span>');
  116. tmpl_array.push(' </td>');
  117. tmpl_array.push(' <td></td>');
  118. tmpl_array.push(' <td style="color:grey;"><%- content_item.get("name") %></td>'); // dataset
  119. tmpl_array.push(' <td><%= _.escape(content_item.get("file_ext")) %></td>'); // data type
  120. tmpl_array.push(' <td><%= _.escape(content_item.get("file_size")) %></td>'); // size
  121. tmpl_array.push(' <td><%= _.escape(content_item.get("update_time")) %></td>'); // time updated
  122. tmpl_array.push(' <td><span data-toggle="tooltip" data-placement="top" title="Marked deleted" style="color:grey;" class="fa fa-ban fa-lg"> </span><button data-toggle="tooltip" data-placement="top" title="Undelete <%- content_item.get("name") %>" class="primary-button btn-xs undelete_dataset_btn show_on_hover" type="button" style="display:none; margin-left:1em;"><span class="fa fa-unlock"> Undelete</span></button></td>');
  123. tmpl_array.push('</tr>');
  124. return _.template(tmpl_array.join(''));
  125. }
  126. });
  127. return {
  128. FolderRowView: FolderRowView
  129. };
  130. });