PageRenderTime 85ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/client/galaxy/scripts/galaxy.tools.js

https://bitbucket.org/remy_d1/galaxy-central-manageapi
JavaScript | 158 lines | 140 code | 12 blank | 6 comment | 15 complexity | b691f27b14a89fe366589e58ac0d93de MD5 | raw file
Possible License(s): CC-BY-3.0
  1. // dependencies
  2. define([ "libs/underscore", "mvc/tools" ], function( _, Tools ) {
  3. var checkUncheckAll = function( name, check ) {
  4. $("input[name='" + name + "'][type='checkbox']").attr('checked', !!check);
  5. }
  6. $(".tool-share-link").each( function() {
  7. var href = $(this).attr("href");
  8. var href = $(this).attr("data-link");
  9. $(this).click(function() {
  10. window.prompt("Copy to clipboard: Ctrl+C, Enter", href);
  11. });
  12. });
  13. // Inserts the Select All / Unselect All buttons for checkboxes
  14. $("div.checkUncheckAllPlaceholder").each( function() {
  15. var check_name = $(this).attr("checkbox_name");
  16. select_link = $("<a class='action-button'></a>").text("Select All").click(function() {
  17. checkUncheckAll(check_name, true);
  18. });
  19. unselect_link = $("<a class='action-button'></a>").text("Unselect All").click(function() {
  20. checkUncheckAll(check_name, false);
  21. });
  22. $(this).append(select_link).append(" ").append(unselect_link);
  23. });
  24. var SELECTION_TYPE = {
  25. 'select_single': {
  26. 'icon_class': 'fa-file-o',
  27. 'select_by': 'Run tool on single input',
  28. 'allow_remap': true
  29. },
  30. 'select_multiple': {
  31. 'icon_class': 'fa-files-o',
  32. 'select_by': 'Run tool in parallel across multiple datasets',
  33. 'allow_remap': false,
  34. 'min_option_count': 2 // Don't show multiple select switch if only
  35. // one dataset available.
  36. },
  37. 'select_collection': {
  38. 'icon_class': 'fa-folder-o',
  39. 'select_by': 'Run tool in parallel across dataset collection',
  40. 'allow_remap': false
  41. },
  42. 'multiselect_single': {
  43. 'icon_class': 'fa-list-alt',
  44. 'select_by': 'Run tool over multiple datasets',
  45. 'allow_remap': true
  46. },
  47. 'multiselect_collection': {
  48. 'icon_class': 'fa-folder-o',
  49. 'select_by': 'Run tool over dataset collection',
  50. 'allow_remap': false,
  51. },
  52. 'select_single_collection': {
  53. 'icon_class': 'fa-file-o',
  54. 'select_by': 'Run tool on single collection',
  55. 'allow_remap': true
  56. },
  57. 'select_map_over_collections': {
  58. 'icon_class': 'fa-folder-o',
  59. 'select_by': 'Map tool over compontents of nested collection',
  60. 'allow_remap': false,
  61. }
  62. };
  63. var SwitchSelectView = Backbone.View.extend({
  64. initialize: function( data ) {
  65. var defaultOption = data.default_option;
  66. var defaultIndex = null;
  67. var switchOptions = data.switch_options;
  68. this.switchOptions = switchOptions;
  69. this.prefix = data.prefix;
  70. var el = this.$el;
  71. var view = this;
  72. var index = 0;
  73. var visibleCount = 0;
  74. _.each( this.switchOptions, function( option, onValue ) {
  75. var numValues = _.size( option.options );
  76. var selectionType = SELECTION_TYPE[ onValue ];
  77. var iIndex = index++;
  78. var hidden = false;
  79. if( defaultOption == onValue ) {
  80. defaultIndex = iIndex;
  81. } else if( numValues < ( selectionType.min_option_count || 1 ) ) {
  82. hidden = true;
  83. }
  84. if( ! hidden ) {
  85. visibleCount++;
  86. var button = $('<i class="fa ' + selectionType['icon_class'] + ' runOptionIcon" style="padding-left: 5px; padding-right: 2px;"></i>').click(function() {
  87. view.enableSelectBy( iIndex, onValue );
  88. }).attr(
  89. 'title',
  90. selectionType['select_by']
  91. ).data( "index", iIndex );
  92. view.formRow().find( "label" ).append( button );
  93. }
  94. });
  95. if( visibleCount < 2 ) {
  96. // Don't show buttons to switch options...
  97. view.formRow().find("i.runOptionIcon").hide();
  98. }
  99. if( defaultIndex != null) {
  100. view.enableSelectBy( defaultIndex, defaultOption );
  101. }
  102. },
  103. formRow: function() {
  104. return this.$el.closest( ".form-row" );
  105. },
  106. render: function() {
  107. },
  108. enableSelectBy: function( enableIndex, onValue ) {
  109. var selectionType = SELECTION_TYPE[onValue];
  110. if(selectionType["allow_remap"]) {
  111. $("div#remap-row").css("display", "inherit");
  112. } else {
  113. $("div#remap-row").css("display", "none");
  114. }
  115. this.formRow().find( "i" ).each(function(_, iElement) {
  116. var $iElement = $(iElement);
  117. var index = $iElement.data("index");
  118. if(index == enableIndex) {
  119. $iElement.css('color', 'black');
  120. } else {
  121. $iElement.css('color', 'Gray');
  122. }
  123. });
  124. var $select = this.$( "select" );
  125. var options = this.switchOptions[ onValue ];
  126. $select.attr( "name", this.prefix + options.name );
  127. $select.attr( "multiple", options.multiple );
  128. // Replace options regardless.
  129. var select2ed = this.$(".select2-container").length > 0;
  130. $select.html(""); // clear out select list
  131. _.each( options.options, function( option ) {
  132. var text = option[0];
  133. var value = option[1];
  134. var selected = option[2];
  135. $select.append($("<option />", {text: text, val: value, selected: selected}));
  136. });
  137. if( select2ed ) {
  138. // Without this select2 does not update options.
  139. $select.select2();
  140. }
  141. }
  142. });
  143. return {
  144. SwitchSelectView: SwitchSelectView
  145. };
  146. });