Commit c764e380ea6f43962ea643aab33bb1f94d6c43da

Authored by Fabio Teixeira
Committed by Luciano Prestes
1 parent 6ee955f9

Put catalog component behavior into a lib file

lib/software_communities_plugin.rb
... ... @@ -119,6 +119,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin
119 119 lib/select-element.js
120 120 lib/select-field-choices
121 121 lib/auto-complete.js
  122 + lib/software-catalog-component.js
122 123 views/control-panel.js
123 124 views/edit-software.js
124 125 views/new-software.js
... ...
public/initializer.js
... ... @@ -10,7 +10,7 @@
10 10 'CompleteRegistration',
11 11 'SearchSoftwareCatalog',
12 12 'SoftwareDownload',
13   - "ProfileTabsSoftware"
  13 + 'ProfileTabsSoftware'
14 14 ];
15 15  
16 16  
... ...
public/lib/software-catalog-component.js 0 → 100644
... ... @@ -0,0 +1,83 @@
  1 +modulejs.define('SoftwareCatalogComponent', ['jquery'], function($) {
  2 + 'use strict';
  3 +
  4 + var dispatch_ajax_function;
  5 +
  6 +
  7 + function show_head_message() {
  8 + if ($("#filter-categories-select-catalog").text().length === 0){
  9 + $("#filter-categories-select-catalog").hide();
  10 + $("#filter-option-catalog-software").show();
  11 + }else{
  12 + $("#filter-categories-select-catalog").show();
  13 + $("#filter-option-catalog-software").hide();
  14 + }
  15 + }
  16 +
  17 +
  18 + function slideDowsCategoriesOptionAndHideOptionCatalog() {
  19 + $("#filter-categories-option").slideDown();
  20 + $("#filter-option-catalog-software").hide();
  21 + }
  22 +
  23 +
  24 + function slideDownCategoriesOptionAndHideCategoriesSelect() {
  25 + $("#filter-categories-option").slideDown();
  26 + $("#filter-categories-select-catalog").hide();
  27 + }
  28 +
  29 +
  30 + function slideUpCategoriesAndShowHeadMessage() {
  31 + $("#filter-categories-option").slideUp();
  32 + show_head_message();
  33 + }
  34 +
  35 +
  36 + function clearCatalogCheckbox() {
  37 + $("#filter-categories-option").slideUp();
  38 + $("#filter-option-catalog-software").show();
  39 + $("#group-categories input:checked").each(function() {
  40 + $(this).prop('checked', false);
  41 + });
  42 +
  43 + dispatch_ajax_function(true);
  44 + }
  45 +
  46 +
  47 + function selectCheckboxCategory(dispatch_ajax) {
  48 + $("#filter-categories-option").slideUp();
  49 + $("#filter-categories-select-catalog").show();
  50 + $("#filter-option-catalog-software").hide();
  51 +
  52 + dispatch_ajax_function(true);
  53 + }
  54 +
  55 +
  56 + function selectProjectSoftwareCheckbox() {
  57 + $("#filter-categories-option").slideUp();
  58 + $("#filter-categories-select-catalog").show();
  59 + $("#filter-option-catalog-software").hide();
  60 +
  61 + dispatch_ajax_function(true);
  62 + show_head_message();
  63 + }
  64 +
  65 +
  66 + function set_events() {
  67 + $("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog);
  68 + $("#filter-categories-select-catalog").click(slideDownCategoriesOptionAndHideCategoriesSelect);
  69 + $("#close-filter-catalog").click(slideUpCategoriesAndShowHeadMessage);
  70 + $("#cleanup-filter-catalg").click(clearCatalogCheckbox);
  71 + $(".categories-catalog").click(selectCheckboxCategory);
  72 + $(".project-software").click(selectProjectSoftwareCheckbox);
  73 + }
  74 +
  75 +
  76 + return {
  77 + init: function(dispatch_ajax) {
  78 + dispatch_ajax_function = dispatch_ajax;
  79 + set_events();
  80 + show_head_message();
  81 + },
  82 + }
  83 +});
... ...
public/views/search-software-catalog.js
1   -modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($, NoosferoRoot) {
  1 +modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot', 'SoftwareCatalogComponent'], function($, NoosferoRoot, SoftwareCatalogComponent) {
2 2 'use strict';
3 3  
4 4 var AJAX_URL = {
... ... @@ -7,56 +7,7 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($,
7 7 };
8 8  
9 9  
10   - function show_head_message() {
11   - if ($("#filter-categories-select-catalog").text().length === 0){
12   - $("#filter-categories-select-catalog").hide();
13   - $("#filter-option-catalog-software").show();
14   - }else{
15   - $("#filter-categories-select-catalog").show();
16   - $("#filter-option-catalog-software").hide();
17   - }
18   - }
19   -
20   -
21   - function slideDowsCategoriesOptionAndHideOptionCatalog() {
22   - $("#filter-categories-option").slideDown();
23   - $("#filter-option-catalog-software").hide();
24   - }
25   -
26   -
27   - function slideDownCategoriesOptionAndHideCategoriesSelect() {
28   - $("#filter-categories-option").slideDown();
29   - $("#filter-categories-select-catalog").hide();
30   - }
31   -
32   -
33   - function slideUpCategoriesAndShowHeadMessage() {
34   - $("#filter-categories-option").slideUp();
35   - show_head_message();
36   - }
37   -
38   -
39   - function clearCatalogCheckbox(){
40   - $("#filter-categories-option").slideUp();
41   - $("#filter-option-catalog-software").show();
42   - $("#group-categories input:checked").each(function() {
43   - $(this).prop('checked', false);
44   - });
45   -
46   - dispatch_search_ajax(update_search_page_on_ajax, true);
47   - }
48   -
49   -
50   - function selectCheckboxCategory() {
51   - $("#filter-categories-option").slideUp();
52   - $("#filter-categories-select-catalog").show();
53   - $("#filter-option-catalog-software").hide();
54   -
55   - dispatch_search_ajax(update_search_page_on_ajax, true);
56   - }
57   -
58   -
59   - function dispatch_search_ajax(callback, enable_load) {
  10 + function dispatch_search_ajax(enable_load) {
60 11 var search_params = get_search_params();
61 12  
62 13 if(enable_load) {
... ... @@ -67,7 +18,7 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($,
67 18 url: AJAX_URL.software_infos,
68 19 type: "GET",
69 20 data: search_params,
70   - success: callback,
  21 + success: update_search_page_on_ajax,
71 22 error: function(){
72 23 close_loading();
73 24 }
... ... @@ -130,7 +81,6 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($,
130 81 selected_categories_field.html(result_categories);
131 82 pagination.html(result_pagination);
132 83 software_count.html(result_software_count);
133   - show_head_message();
134 84 highlight_searched_terms();
135 85 catalog_message();
136 86  
... ... @@ -141,7 +91,7 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($,
141 91 function hide_load_after_ajax() {
142 92 if ($("#overlay_loading_modal").is(":visible")) {
143 93 close_loading();
144   - setTimeout(hide_load_after_ajax, 2000);
  94 + setTimeout(hide_load_after_ajax, 1500);
145 95 }
146 96 }
147 97  
... ... @@ -168,16 +118,6 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($,
168 118 }
169 119  
170 120  
171   - function selectProjectSoftwareCheckbox() {
172   - $("#filter-categories-option").slideUp();
173   - $("#filter-categories-select-catalog").show();
174   - $("#filter-option-catalog-software").hide();
175   -
176   - dispatch_search_ajax(update_search_page_on_ajax, true);
177   - show_head_message();
178   - }
179   -
180   -
181 121 function update_page_by_ajax_on_select_change() {
182 122 dispatch_search_ajax(update_search_page_on_ajax, true);
183 123 }
... ... @@ -200,12 +140,6 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($,
200 140  
201 141  
202 142 function set_events() {
203   - $("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog);
204   - $("#filter-categories-select-catalog").click(slideDownCategoriesOptionAndHideCategoriesSelect);
205   - $("#close-filter-catalog").click(slideUpCategoriesAndShowHeadMessage);
206   - $("#cleanup-filter-catalg").click(clearCatalogCheckbox);
207   - $(".categories-catalog").click(selectCheckboxCategory);
208   - $(".project-software").click(selectProjectSoftwareCheckbox);
209 143 $("#software_display").change(update_page_by_ajax_on_select_change);
210 144 $("#sort").change(update_page_by_ajax_on_select_change);
211 145  
... ... @@ -222,9 +156,10 @@ modulejs.define('SearchSoftwareCatalog', ['jquery', 'NoosferoRoot'], function($,
222 156 init: function() {
223 157 set_events();
224 158 catalog_message();
225   - show_head_message();
226 159  
227 160 $("#filter-categories-option").hide();
  161 +
  162 + SoftwareCatalogComponent.init(dispatch_search_ajax);
228 163 }
229 164 }
230 165 });
231 166 \ No newline at end of file
... ...