new-software.js
1.28 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
modulejs.define('NewSoftware', ['jquery', 'NoosferoRoot', 'AutoComplete'], function($, NoosferoRoot, AutoComplete) {
'use strict';
var AJAX_URL = {
get_license_data:
NoosferoRoot.urlWithSubDirectory("/plugin/software_communities/get_license_data")
};
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();
}
}
});