From 05fc8a5c58579bfb4f27939c5a24b95bc08c3ff2 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Mon, 2 Mar 2015 20:00:30 -0300 Subject: [PATCH] Create an initializer and load ControlPanel --- lib/software_communities_plugin.rb | 7 +++++-- public/initializer.js | 23 +++++++++++++++++++++++ public/lib/noosfero-root.js | 9 +++++++++ public/lib/select-element.js | 32 ++++++++++++++++++++++++++++++++ public/mpog-software.js | 42 ------------------------------------------ public/software-catalog.js | 2 +- public/spb-utils.js | 37 ------------------------------------- public/vendor/jquery.js | 3 +++ public/views/control-panel.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 126 insertions(+), 82 deletions(-) create mode 100644 public/initializer.js create mode 100644 public/lib/noosfero-root.js create mode 100644 public/lib/select-element.js delete mode 100644 public/mpog-software.js delete mode 100644 public/spb-utils.js create mode 100644 public/vendor/jquery.js create mode 100644 public/views/control-panel.js diff --git a/lib/software_communities_plugin.rb b/lib/software_communities_plugin.rb index 4918a6a..fbb5bbf 100644 --- a/lib/software_communities_plugin.rb +++ b/lib/software_communities_plugin.rb @@ -122,8 +122,11 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin %w( vendor/jquery.maskedinput.min.js vendor/modulejs-1.5.0.min.js - spb-utils.js - mpog-software.js + vendor/jquery.js + lib/noosfero-root.js + lib/select-element.js + views/control-panel.js + initializer.js mpog-software-validations.js mpog-user-validations.js mpog-institution-validations.js diff --git a/public/initializer.js b/public/initializer.js new file mode 100644 index 0000000..49f38dc --- /dev/null +++ b/public/initializer.js @@ -0,0 +1,23 @@ +var dependencies = [ + 'ControlPanel' +]; + + +modulejs.define('Initializer', dependencies, function(cp) { + if( cp.isControlPanel() ) { + cp.init(); + } +}); + + +(function() { + 'use strict'; + + var $ = modulejs.require('jquery'); + Initializer = modulejs.require('Initializer'); + + + $(document).ready(function() { + Initializer(); + }); +})(); \ No newline at end of file diff --git a/public/lib/noosfero-root.js b/public/lib/noosfero-root.js new file mode 100644 index 0000000..80eb793 --- /dev/null +++ b/public/lib/noosfero-root.js @@ -0,0 +1,9 @@ +modulejs.define('NoosferoRoot', function() { + function url_with_subdirectory(url) { + return noosfero_root() + url; + } + + return { + urlWithSubDirectory: url_with_subdirectory + } +}); diff --git a/public/lib/select-element.js b/public/lib/select-element.js new file mode 100644 index 0000000..8f0691a --- /dev/null +++ b/public/lib/select-element.js @@ -0,0 +1,32 @@ +modulejs.define('SelectElement', function() { + function SelectElement(name, id) { + this.select = document.createElement("select"); + } + + + SelectElement.prototype.setAttr = function(attr, value) { + return this.select.setAttribute(attr, value); + }; + + + SelectElement.prototype.addOption = function(option) { + return this.select.add(option); + }; + + + SelectElement.prototype.getSelect = function() { + return this.select; + }; + + + SelectElement.generateOption = function(value, text) { + var option; + option = document.createElement("option"); + option.setAttribute("value", value); + option.text = text; + return option; + }; + + + return SelectElement; +}); diff --git a/public/mpog-software.js b/public/mpog-software.js deleted file mode 100644 index 13722fc..0000000 --- a/public/mpog-software.js +++ /dev/null @@ -1,42 +0,0 @@ -(function(){ - function hide_infos(){ - jQuery(".language-info").hide(); - jQuery(".database-info").hide(); - jQuery(".libraries-info").hide(); - jQuery(".operating-system-info").hide(); - jQuery(".language-button-hide").hide(); - jQuery(".database-button-hide").hide(); - jQuery(".libraries-button-hide").hide(); - jQuery(".operating-system-button-hide").hide(); - } - - function add_software_on_control_panel(control_panel) { - var software_link = jQuery(".control-panel-software-link").remove(); - - if( software_link.size() > 0 ) { - control_panel.prepend(software_link); - } - } - - function add_institution_on_control_panel(control_panel) { - var institution_link = jQuery(".control-panel-instituton-link").remove(); - - if( institution_link.size() > 0 ) { - control_panel.prepend(institution_link); - } - } - - function add_itens_on_controla_panel() { - var control_panel = jQuery(".control-panel"); - - if( control_panel.size() > 0 ) { - add_software_on_control_panel(control_panel); - add_institution_on_control_panel(control_panel); - } - } - - jQuery(document).ready(function(){ - add_itens_on_controla_panel(); - hide_infos(); - }); -})(); \ No newline at end of file diff --git a/public/software-catalog.js b/public/software-catalog.js index 2b5e8d0..ce41301 100644 --- a/public/software-catalog.js +++ b/public/software-catalog.js @@ -8,7 +8,7 @@ function show_head_message() { - if ($("#filter-categories-select-catalog").text().blank()){ + if ($("#filter-categories-select-catalog").text()){ $("#filter-categories-select-catalog").hide(); $("#filter-option-catalog-software").show(); }else{ diff --git a/public/spb-utils.js b/public/spb-utils.js deleted file mode 100644 index 362a59d..0000000 --- a/public/spb-utils.js +++ /dev/null @@ -1,37 +0,0 @@ -/* -* "Class" for select and option html generation -*/ -var SelectElement = (function() { - function SelectElement(name, id) { - this.select = document.createElement("select"); - } - - SelectElement.prototype.setAttr = function(attr, value) { - return this.select.setAttribute(attr, value); - }; - - SelectElement.prototype.addOption = function(option) { - return this.select.add(option); - }; - - SelectElement.prototype.getSelect = function() { - return this.select; - }; - - SelectElement.generateOption = function(value, text) { - var option; - option = document.createElement("option"); - option.setAttribute("value", value); - option.text = text; - return option; - }; - - return SelectElement; -})(); - - -function url_with_subdirectory(url) { - var subdirectory = jQuery("meta[property='noosfero:root']").attr("content"); - - return subdirectory+url; -} \ No newline at end of file diff --git a/public/vendor/jquery.js b/public/vendor/jquery.js new file mode 100644 index 0000000..a3f4ebf --- /dev/null +++ b/public/vendor/jquery.js @@ -0,0 +1,3 @@ +modulejs.define('jquery', function() { + return jQuery; +}); diff --git a/public/views/control-panel.js b/public/views/control-panel.js new file mode 100644 index 0000000..dfec878 --- /dev/null +++ b/public/views/control-panel.js @@ -0,0 +1,53 @@ +modulejs.define('ControlPanel', ['jquery'], function($) { + function hide_infos(){ + $(".language-info").hide(); + $(".database-info").hide(); + $(".libraries-info").hide(); + $(".operating-system-info").hide(); + $(".language-button-hide").hide(); + $(".database-button-hide").hide(); + $(".libraries-button-hide").hide(); + $(".operating-system-button-hide").hide(); + } + + + function add_software_on_control_panel(control_panel) { + var software_link = $(".control-panel-software-link").remove(); + + if( software_link.size() > 0 ) { + control_panel.prepend(software_link); + } + } + + + function add_institution_on_control_panel(control_panel) { + var institution_link = $(".control-panel-instituton-link").remove(); + + if( institution_link.size() > 0 ) { + control_panel.prepend(institution_link); + } + } + + + function add_itens_on_controla_panel() { + var control_panel = $(".control-panel"); + + if( control_panel.size() > 0 ) { + add_software_on_control_panel(control_panel); + add_institution_on_control_panel(control_panel); + } + } + + + return { + isControlPanel: function() { + return $("#profile-editor-index").length == 1; + }, + + + init: function() { + add_itens_on_controla_panel(); + hide_infos(); + } + } +}); -- libgit2 0.21.2