Files
galaxy/static/scripts/mvc/library/library-libraryrow-view.js
T
2018-05-23 15:37:14 -04:00

1 line
7.9 KiB
JavaScript

define("mvc/library/library-libraryrow-view",["exports","libs/toastr"],function(e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var i=function(e){return e&&e.__esModule?e:{default:e}}(t),r=Backbone.View.extend({events:{"click .edit_library_btn":"edit_button_clicked","click .cancel_library_btn":"cancel_library_modification","click .save_library_btn":"save_library_modification","click .delete_library_btn":"delete_library","click .undelete_library_btn":"undelete_library"},edit_mode:!1,element_visibility_config:{upload_library_btn:!1,edit_library_btn:!1,permission_library_btn:!1,save_library_btn:!1,cancel_library_btn:!1,delete_library_btn:!1,undelete_library_btn:!1},initialize:function(e){this.render(e)},render:function(e){void 0===e&&(e=Galaxy.libraries.libraryListView.collection.get(this.$el.data("id")),console.log(e)),this.prepareButtons(e);var t=this.templateRow();return this.setElement(t({library:e,button_config:this.element_visibility_config,edit_mode:this.edit_mode})),this.$el.show(),this},repaint:function(e){this.$el.find('[data-toggle="tooltip"]').tooltip("dispose");var t=this.$el;this.render(),t.replaceWith(this.$el),this.$el.find('[data-toggle="tooltip"]').tooltip({trigger:"hover"})},prepareButtons:function(e){var t=this.element_visibility_config;!1===this.edit_mode?(t.save_library_btn=!1,t.cancel_library_btn=!1,t.delete_library_btn=!1,!0===e.get("deleted")?(t.undelete_library_btn=!0,t.upload_library_btn=!1,t.edit_library_btn=!1,t.permission_library_btn=!1):!1===e.get("deleted")&&(t.save_library_btn=!1,t.cancel_library_btn=!1,t.undelete_library_btn=!1,!0===e.get("can_user_add")&&(t.upload_library_btn=!0),!0===e.get("can_user_modify")&&(t.edit_library_btn=!0),!0===e.get("can_user_manage")&&(t.permission_library_btn=!0))):!0===this.edit_mode&&(t.upload_library_btn=!1,t.edit_library_btn=!1,t.permission_library_btn=!1,t.save_library_btn=!0,t.cancel_library_btn=!0,t.delete_library_btn=!0,t.undelete_library_btn=!1),this.element_visibility_config=t},edit_button_clicked:function(){this.edit_mode=!0,this.repaint()},cancel_library_modification:function(){this.edit_mode=!1,this.repaint()},save_library_modification:function(){var e=Galaxy.libraries.libraryListView.collection.get(this.$el.data("id")),t=!1,r=this.$el.find(".input_library_name").val();if(void 0!==r&&r!==e.get("name")){if(!(r.length>2))return void i.default.warning("Library name has to be at least 3 characters long.");e.set("name",r),t=!0}var a=this.$el.find(".input_library_description").val();void 0!==a&&a!==e.get("description")&&(e.set("description",a),t=!0);var l=this.$el.find(".input_library_synopsis").val();if(void 0!==l&&l!==e.get("synopsis")&&(e.set("synopsis",l),t=!0),t){var n=this;e.save(null,{patch:!0,success:function(e){n.edit_mode=!1,n.repaint(e),i.default.success("Changes to library saved.")},error:function(e,t){void 0!==t.responseJSON?i.default.error(t.responseJSON.err_msg):i.default.error("An error occured while attempting to update the library.")}})}else this.edit_mode=!1,this.repaint(e),i.default.info("Nothing has changed.")},delete_library:function(){var e=this;Galaxy.libraries.libraryListView.collection.get(this.$el.data("id")).destroy({success:function(t){t.set("deleted",!0),Galaxy.libraries.libraryListView.collection.add(t),e.edit_mode=!1,!1===Galaxy.libraries.preferences.get("with_deleted")?($(".tooltip").hide(),e.repaint(t),e.$el.remove()):!0===Galaxy.libraries.preferences.get("with_deleted")&&e.repaint(t),i.default.success("Library has been marked deleted.")},error:function(e,t){void 0!==t.responseJSON?i.default.error(t.responseJSON.err_msg):i.default.error("An error occured during deleting the library.")}})},undelete_library:function(){var e=Galaxy.libraries.libraryListView.collection.get(this.$el.data("id")),t=this;e.url=e.urlRoot+e.id+"?undelete=true",e.destroy({success:function(e){e.set("deleted",!1),Galaxy.libraries.libraryListView.collection.add(e),t.edit_mode=!1,t.repaint(e),i.default.success("Library has been undeleted.")},error:function(e,t){void 0!==t.responseJSON?i.default.error(t.responseJSON.err_msg):i.default.error("An error occured while undeleting the library.")}})},templateRow:function(){return _.template(['<tr class="<% if(library.get("deleted") === true) { print("active") } %>" style="display:none;" data-id="<%- library.get("id") %>">',"<% if(!edit_mode) { %>",'<% if(library.get("deleted")) { %>','<td style="color:grey;"><%- library.get("name") %></td>',"<% } else { %>",'<td><a href="#folders/<%- library.get("root_folder_id") %>"><%- library.get("name") %></a></td>',"<% } %>",'<% if(library.get("description")) { %>','<% if( (library.get("description")).length> 80 ) { %>','<td data-toggle="tooltip" data-placement="bottom" title="<%= _.escape(library.get("description")) %>"><%= _.escape(library.get("description")).substring(0, 80) + "..." %></td>',"<% } else { %>",'<td><%= _.escape(library.get("description"))%></td>',"<% } %>","<% } else { %>","<td></td>","<% } %>",'<% if(library.get("synopsis")) { %>','<% if( (library.get("synopsis")).length> 120 ) { %>','<td data-toggle="tooltip" data-placement="bottom" title="<%= _.escape(library.get("synopsis")) %>"><%= _.escape(library.get("synopsis")).substring(0, 120) + "..." %></td>',"<% } else { %>",'<td><%= _.escape(library.get("synopsis"))%></td>',"<% } %>","<% } else { %>","<td></td>","<% } %>","<% } else if(edit_mode){ %>",'<td><textarea rows="4" class="form-control input_library_name" placeholder="name" ><%- library.get("name") %></textarea></td>','<td><textarea rows="4" class="form-control input_library_description" placeholder="description" ><%- library.get("description") %></textarea></td>','<td><textarea rows="4" class="form-control input_library_synopsis" placeholder="synopsis" ><%- library.get("synopsis") %></textarea></td>',"<% } %>",'<td class="right-center">','<% if( (library.get("public")) && (library.get("deleted") === false) ) { %>','<span data-toggle="tooltip" data-placement="left" title="Unrestricted library" style="color:grey;" class="fa fa-globe fa-lg"> </span>',"<% }%>",'<button data-toggle="tooltip" data-placement="left" title="Modify \'<%- library.get("name") %>\'" class="btn btn-sm edit_library_btn" type="button" style="<% if(button_config.edit_library_btn === false) { print("display:none;") } %>"><span class="fa fa-pencil"></span> Edit</button>','<a data-toggle="tooltip" data-placement="left" title="Permissions of \'<%- library.get("name") %>\'" href="#library/<%- library.get("id") %>/permissions"><button class="btn btn-sm permission_library_btn" type="button" style="<% if(button_config.permission_library_btn === false) { print("display:none;") } %>"><span class="fa fa-group"></span> Manage</button></a>','<button data-toggle="tooltip" data-placement="left" title="Save changes" class="btn btn-sm save_library_btn" type="button" style="<% if(button_config.save_library_btn === false) { print("display:none;") } %>"><span class="fa fa-floppy-o"></span> Save</button>','<button data-toggle="tooltip" data-placement="left" title="Discard changes" class="btn btn-sm cancel_library_btn" type="button" style="<% if(button_config.cancel_library_btn === false) { print("display:none;") } %>"><span class="fa fa-times"></span> Cancel</button>','<button data-toggle="tooltip" data-placement="left" title="Delete \'<%- library.get("name") %>\'" class="btn btn-sm delete_library_btn" type="button" style="<% if(button_config.delete_library_btn === false) { print("display:none;") } %>"><span class="fa fa-trash-o"></span> Delete</button>','<span data-toggle="tooltip" data-placement="left" title="Marked deleted" style="color:grey; <% if(button_config.undelete_library_btn === false) { print("display:none;") } %>" class="fa fa-ban fa-lg"></span>','<button data-toggle="tooltip" data-placement="left" title="Undelete \'<%- library.get("name") %>\' " class="btn btn-sm undelete_library_btn" type="button" style="<% if(button_config.undelete_library_btn === false) { print("display:none;") } %>"><span class="fa fa-unlock"></span> Undelete</button>',"</td>","</tr>"].join(""))}});e.default={LibraryRowView:r}});