new-software.js
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
modulejs.define('NewSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete', 'NewCommunity'], function($, NoosferoRoot, AutoComplete, Community) {
'use strict';
var AJAX_URL = {
get_license_data:
NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_license_data")
};
function replace_domain_and_repository_link(){
var community_name = $("#community_name_id").val();
var domain = 'https://';
domain = domain.concat($("#software-hostname").text());
var slug_name = community_name.replace(/\s+/g, '-').toLowerCase();
var custom_domain = domain.concat('<your-repository>');
custom_domain = custom_domain.concat('/');
custom_domain = custom_domain.concat(slug_name);
$("#community-identifier").val(slug_name);
$("#software-info-repository-link").val(custom_domain);
}
function show_another_license_on_page_load() {
$("#license_info_id").trigger("change");
}
function display_another_license_fields(selected) {
if( selected === "Another" ) {
$("#another_license").removeClass("hide-field");
$("#version_link").addClass("hide-field");
} else {
$("#another_license").addClass("hide-field");
$("#version_link").removeClass("hide-field");
}
}
function display_license_link_on_autocomplete(selected) {
var link = $("#version_" + selected.item.id).val();
$("#version_link").attr("href", link);
display_another_license_fields(selected.item.label);
}
function license_info_autocomplete() {
AutoComplete.enable(
"license_info", ".license_info_id", ".license_info_version",
AJAX_URL.get_license_data, display_license_link_on_autocomplete
);
}
return {
isCurrentPage: function() {
return $('#new-software-page').length === 1;
},
init: function() {
license_info_autocomplete();
Community.init();
$("#community_name_id").blur(replace_domain_and_repository_link);
}
}
});