diff options
author | Michael Wood <michael.g.wood@intel.com> | 2014-11-11 16:23:58 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-11-21 11:49:23 +0000 |
commit | fa9206e42710772b8aac918b7aba01e126e993ce (patch) | |
tree | 28b0fdae74e59d5e692d53c122a115a1dfb50226 /bitbake | |
parent | 0b6859cdf3a4b66bb8b94361681a5b6b362f93ae (diff) | |
download | poky-fa9206e42710772b8aac918b7aba01e126e993ce.tar.gz |
bitbake: toaster: Create libtoaster.js with some utility functions
Replace main.js with libtoaster. This can be a place for common
functionality for toaster. Calling it lib... makes it more obvious as
well as helps with code readability due to the namespacing.
(Bitbake rev: cdf6178ae3675b40afca9f08d491ca1b7e45914e)
Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/libtoaster.js | 237 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/main.js | 111 | ||||
-rw-r--r-- | bitbake/lib/toaster/toastergui/templates/base.html | 29 |
3 files changed, 239 insertions, 138 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js new file mode 100644 index 0000000000..b899b8de4d --- /dev/null +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js | |||
@@ -0,0 +1,237 @@ | |||
1 | |||
2 | /* All shared functionality to go in libtoaster object. | ||
3 | * This object really just helps readability since we can then have | ||
4 | * a traceable namespace. | ||
5 | */ | ||
6 | var libtoaster = (function (){ | ||
7 | |||
8 | /* makeTypeahead parameters | ||
9 | * elementSelector: JQuery elementSelector string | ||
10 | * xhrUrl: the url to get the JSON from expects JSON in the form: | ||
11 | * { "list": [ { "name": "test", "detail" : "a test thing" }, .... ] } | ||
12 | * xhrParams: the data/parameters to pass to the getJSON url e.g. | ||
13 | * { 'type' : 'projects' } the text typed will be passed as 'value'. | ||
14 | * selectedCB: function to call once an item has been selected one | ||
15 | * arg of the item. | ||
16 | */ | ||
17 | function _makeTypeahead (jQElement, xhrUrl, xhrParams, selectedCB) { | ||
18 | |||
19 | jQElement.typeahead({ | ||
20 | source: function(query, process){ | ||
21 | xhrParams.value = query; | ||
22 | $.getJSON(xhrUrl, this.options.xhrParams, function(data){ | ||
23 | return process (data.list); | ||
24 | }); | ||
25 | }, | ||
26 | updater: function(item) { | ||
27 | var itemObj = this.$menu.find('.active').data('itemObject'); | ||
28 | selectedCB(itemObj); | ||
29 | return item; | ||
30 | }, | ||
31 | matcher: function(item) { return ~item.name.toLowerCase().indexOf(this.query.toLowerCase()); }, | ||
32 | highlighter: function (item) { | ||
33 | if (item.hasOwnProperty('detail')) | ||
34 | /* Use jquery to escape the value as text into a span */ | ||
35 | return $('<span></span>').text(item.name+' '+item.detail).get(0); | ||
36 | return $('<span></span>').text(item.name).get(0); | ||
37 | }, | ||
38 | sorter: function (items) { return items; }, | ||
39 | xhrUrl: xhrUrl, | ||
40 | xhrParams: xhrParams, | ||
41 | }); | ||
42 | |||
43 | |||
44 | /* Copy of bootstrap's render func but sets selectedObject value */ | ||
45 | function customRenderFunc (items) { | ||
46 | var that = this; | ||
47 | |||
48 | items = $(items).map(function (i, item) { | ||
49 | i = $(that.options.item).attr('data-value', item.name).data('itemObject', item); | ||
50 | i.find('a').html(that.highlighter(item)); | ||
51 | return i[0]; | ||
52 | }); | ||
53 | |||
54 | items.first().addClass('active'); | ||
55 | this.$menu.html(items); | ||
56 | return this; | ||
57 | } | ||
58 | |||
59 | jQElement.data('typeahead').render = customRenderFunc; | ||
60 | }; | ||
61 | |||
62 | /* | ||
63 | * url - the url of the xhr build */ | ||
64 | function _startABuild (url, project_id, targets, onsuccess, onfail) { | ||
65 | var data; | ||
66 | |||
67 | if (project_id) | ||
68 | data = 'project_id='+project_id+'&targets='+targets; | ||
69 | else | ||
70 | data = 'targets='+targets; | ||
71 | |||
72 | $.ajax( { | ||
73 | type: "POST", | ||
74 | url: url, | ||
75 | data: data, | ||
76 | headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, | ||
77 | success: function (_data) { | ||
78 | if (_data.error != "ok") { | ||
79 | console.log(_data.error); | ||
80 | } else { | ||
81 | if (onsuccess != undefined) onsuccess(_data); | ||
82 | } | ||
83 | }, | ||
84 | error: function (_data) { | ||
85 | console.log("Call failed"); | ||
86 | console.log(_data); | ||
87 | if (onfail) onfail(data); | ||
88 | } }); | ||
89 | }; | ||
90 | |||
91 | return { | ||
92 | reload_params : reload_params, | ||
93 | startABuild : _startABuild, | ||
94 | makeTypeahead : _makeTypeahead, | ||
95 | } | ||
96 | })(); | ||
97 | |||
98 | /* keep this in the global scope for compatability */ | ||
99 | function reload_params(params) { | ||
100 | uri = window.location.href; | ||
101 | splitlist = uri.split("?"); | ||
102 | url = splitlist[0], parameters=splitlist[1]; | ||
103 | // deserialize the call parameters | ||
104 | if(parameters){ | ||
105 | cparams = parameters.split("&"); | ||
106 | }else{ | ||
107 | cparams = [] | ||
108 | } | ||
109 | nparams = {} | ||
110 | for (i = 0; i < cparams.length; i++) { | ||
111 | temp = cparams[i].split("="); | ||
112 | nparams[temp[0]] = temp[1]; | ||
113 | } | ||
114 | // update parameter values | ||
115 | for (i in params) { | ||
116 | nparams[encodeURIComponent(i)] = encodeURIComponent(params[i]); | ||
117 | } | ||
118 | // serialize the structure | ||
119 | callparams = [] | ||
120 | for (i in nparams) { | ||
121 | callparams.push(i+"="+nparams[i]); | ||
122 | } | ||
123 | window.location.href = url+"?"+callparams.join('&'); | ||
124 | } | ||
125 | |||
126 | |||
127 | /* Things that happen for all pages */ | ||
128 | $(document).ready(function() { | ||
129 | |||
130 | /* | ||
131 | * PrettyPrint plugin. | ||
132 | * | ||
133 | */ | ||
134 | // Init | ||
135 | prettyPrint(); | ||
136 | |||
137 | // Prevent invalid links from jumping page scroll | ||
138 | $('a[href=#]').click(function() { | ||
139 | return false; | ||
140 | }); | ||
141 | |||
142 | |||
143 | /* Belen's additions */ | ||
144 | |||
145 | // turn Edit columns dropdown into a multiselect menu | ||
146 | $('.dropdown-menu input, .dropdown-menu label').click(function(e) { | ||
147 | e.stopPropagation(); | ||
148 | }); | ||
149 | |||
150 | // enable popovers in any table cells that contain an anchor with the | ||
151 | // .btn class applied, and make sure popovers work on click, are mutually | ||
152 | // exclusive and they close when your click outside their area | ||
153 | |||
154 | $('html').click(function(e){ | ||
155 | $('td > a.btn').popover('hide'); | ||
156 | }); | ||
157 | |||
158 | $('td > a.btn').popover({ | ||
159 | html:true, | ||
160 | placement:'left', | ||
161 | container:'body', | ||
162 | trigger:'manual' | ||
163 | }).click(function(e){ | ||
164 | $('td > a.btn').not(this).popover('hide'); | ||
165 | // ideally we would use 'toggle' here | ||
166 | // but it seems buggy in our Bootstrap version | ||
167 | $(this).popover('show'); | ||
168 | e.stopPropagation(); | ||
169 | }); | ||
170 | |||
171 | // enable tooltips for applied filters | ||
172 | $('th a.btn-primary').tooltip({container:'body', html:true, placement:'bottom', delay:{hide:1500}}); | ||
173 | |||
174 | // hide applied filter tooltip when you click on the filter button | ||
175 | $('th a.btn-primary').click(function () { | ||
176 | $('.tooltip').hide(); | ||
177 | }); | ||
178 | |||
179 | // enable help information tooltip | ||
180 | $(".get-help").tooltip({container:'body', html:true, delay:{show:300}}); | ||
181 | |||
182 | // show help bubble only on hover inside tables | ||
183 | $(".hover-help").css("visibility","hidden"); | ||
184 | $("th, td").hover(function () { | ||
185 | $(this).find(".hover-help").css("visibility","visible"); | ||
186 | }); | ||
187 | $("th, td").mouseleave(function () { | ||
188 | $(this).find(".hover-help").css("visibility","hidden"); | ||
189 | }); | ||
190 | |||
191 | // show task type and outcome in task details pages | ||
192 | $(".task-info").tooltip({ container: 'body', html: true, delay: {show: 200}, placement: 'right' }); | ||
193 | |||
194 | // linking directly to tabs | ||
195 | $(function(){ | ||
196 | var hash = window.location.hash; | ||
197 | hash && $('ul.nav a[href="' + hash + '"]').tab('show'); | ||
198 | |||
199 | $('.nav-tabs a').click(function (e) { | ||
200 | $(this).tab('show'); | ||
201 | $('body').scrollTop(); | ||
202 | }); | ||
203 | }); | ||
204 | |||
205 | // toggle for long content (variables, python stack trace, etc) | ||
206 | $('.full, .full-hide').hide(); | ||
207 | $('.full-show').click(function(){ | ||
208 | $('.full').slideDown(function(){ | ||
209 | $('.full-hide').show(); | ||
210 | }); | ||
211 | $(this).hide(); | ||
212 | }); | ||
213 | $('.full-hide').click(function(){ | ||
214 | $(this).hide(); | ||
215 | $('.full').slideUp(function(){ | ||
216 | $('.full-show').show(); | ||
217 | }); | ||
218 | }); | ||
219 | |||
220 | //toggle the errors and warnings sections | ||
221 | $('.show-errors').click(function() { | ||
222 | $('#collapse-errors').addClass('in'); | ||
223 | }); | ||
224 | $('.toggle-errors').click(function() { | ||
225 | $('#collapse-errors').toggleClass('in'); | ||
226 | }); | ||
227 | $('.show-warnings').click(function() { | ||
228 | $('#collapse-warnings').addClass('in'); | ||
229 | }); | ||
230 | $('.toggle-warnings').click(function() { | ||
231 | $('#collapse-warnings').toggleClass('in'); | ||
232 | }); | ||
233 | //show warnings section when requested from the previous page | ||
234 | if (location.href.search('#warnings') > -1) { | ||
235 | $('#collapse-warnings').addClass('in'); | ||
236 | } | ||
237 | }); | ||
diff --git a/bitbake/lib/toaster/toastergui/static/js/main.js b/bitbake/lib/toaster/toastergui/static/js/main.js deleted file mode 100644 index eef6b468f4..0000000000 --- a/bitbake/lib/toaster/toastergui/static/js/main.js +++ /dev/null | |||
@@ -1,111 +0,0 @@ | |||
1 | $(document).ready(function() { | ||
2 | |||
3 | /* | ||
4 | * PrettyPrint plugin. | ||
5 | * | ||
6 | */ | ||
7 | // Init | ||
8 | prettyPrint(); | ||
9 | |||
10 | // Prevent invalid links from jumping page scroll | ||
11 | $('a[href=#]').click(function() { | ||
12 | return false; | ||
13 | }); | ||
14 | |||
15 | |||
16 | /* Belen's additions */ | ||
17 | |||
18 | // turn Edit columns dropdown into a multiselect menu | ||
19 | $('.dropdown-menu input, .dropdown-menu label').click(function(e) { | ||
20 | e.stopPropagation(); | ||
21 | }); | ||
22 | |||
23 | // enable popovers in any table cells that contain an anchor with the | ||
24 | // .btn class applied, and make sure popovers work on click, are mutually | ||
25 | // exclusive and they close when your click outside their area | ||
26 | |||
27 | $('html').click(function(e){ | ||
28 | $('td > a.btn').popover('hide'); | ||
29 | }); | ||
30 | |||
31 | $('td > a.btn').popover({ | ||
32 | html:true, | ||
33 | placement:'left', | ||
34 | container:'body', | ||
35 | trigger:'manual' | ||
36 | }).click(function(e){ | ||
37 | $('td > a.btn').not(this).popover('hide'); | ||
38 | // ideally we would use 'toggle' here | ||
39 | // but it seems buggy in our Bootstrap version | ||
40 | $(this).popover('show'); | ||
41 | e.stopPropagation(); | ||
42 | }); | ||
43 | |||
44 | // enable tooltips for applied filters | ||
45 | $('th a.btn-primary').tooltip({container:'body', html:true, placement:'bottom', delay:{hide:1500}}); | ||
46 | |||
47 | // hide applied filter tooltip when you click on the filter button | ||
48 | $('th a.btn-primary').click(function () { | ||
49 | $('.tooltip').hide(); | ||
50 | }); | ||
51 | |||
52 | // enable help information tooltip | ||
53 | $(".get-help").tooltip({container:'body', html:true, delay:{show:300}}); | ||
54 | |||
55 | // show help bubble only on hover inside tables | ||
56 | $(".hover-help").css("visibility","hidden"); | ||
57 | $("th, td").hover(function () { | ||
58 | $(this).find(".hover-help").css("visibility","visible"); | ||
59 | }); | ||
60 | $("th, td").mouseleave(function () { | ||
61 | $(this).find(".hover-help").css("visibility","hidden"); | ||
62 | }); | ||
63 | |||
64 | // show task type and outcome in task details pages | ||
65 | $(".task-info").tooltip({ container: 'body', html: true, delay: {show: 200}, placement: 'right' }); | ||
66 | |||
67 | // linking directly to tabs | ||
68 | $(function(){ | ||
69 | var hash = window.location.hash; | ||
70 | hash && $('ul.nav a[href="' + hash + '"]').tab('show'); | ||
71 | |||
72 | $('.nav-tabs a').click(function (e) { | ||
73 | $(this).tab('show'); | ||
74 | $('body').scrollTop(); | ||
75 | }); | ||
76 | }); | ||
77 | |||
78 | // toggle for long content (variables, python stack trace, etc) | ||
79 | $('.full, .full-hide').hide(); | ||
80 | $('.full-show').click(function(){ | ||
81 | $('.full').slideDown(function(){ | ||
82 | $('.full-hide').show(); | ||
83 | }); | ||
84 | $(this).hide(); | ||
85 | }); | ||
86 | $('.full-hide').click(function(){ | ||
87 | $(this).hide(); | ||
88 | $('.full').slideUp(function(){ | ||
89 | $('.full-show').show(); | ||
90 | }); | ||
91 | }); | ||
92 | |||
93 | //toggle the errors and warnings sections | ||
94 | $('.show-errors').click(function() { | ||
95 | $('#collapse-errors').addClass('in'); | ||
96 | }); | ||
97 | $('.toggle-errors').click(function() { | ||
98 | $('#collapse-errors').toggleClass('in'); | ||
99 | }); | ||
100 | $('.show-warnings').click(function() { | ||
101 | $('#collapse-warnings').addClass('in'); | ||
102 | }); | ||
103 | $('.toggle-warnings').click(function() { | ||
104 | $('#collapse-warnings').toggleClass('in'); | ||
105 | }); | ||
106 | //show warnings section when requested from the previous page | ||
107 | if (location.href.search('#warnings') > -1) { | ||
108 | $('#collapse-warnings').addClass('in'); | ||
109 | } | ||
110 | |||
111 | }); | ||
diff --git a/bitbake/lib/toaster/toastergui/templates/base.html b/bitbake/lib/toaster/toastergui/templates/base.html index f377081849..1b9edfd7b7 100644 --- a/bitbake/lib/toaster/toastergui/templates/base.html +++ b/bitbake/lib/toaster/toastergui/templates/base.html | |||
@@ -18,36 +18,11 @@ | |||
18 | </script> | 18 | </script> |
19 | <script src="{% static 'js/prettify.js' %}"> | 19 | <script src="{% static 'js/prettify.js' %}"> |
20 | </script> | 20 | </script> |
21 | <script src="{% static 'js/main.js' %}"> | 21 | <script src="{% static 'js/libtoaster.js' %}"> |
22 | </script> | ||
22 | </script> | 23 | </script> |
23 | <script> | 24 | <script> |
24 | function reload_params(params) { | ||
25 | uri = window.location.href; | ||
26 | splitlist = uri.split("?"); | ||
27 | url = splitlist[0], parameters=splitlist[1]; | ||
28 | // deserialize the call parameters | ||
29 | if(parameters){ | ||
30 | cparams = parameters.split("&"); | ||
31 | }else{ | ||
32 | cparams = [] | ||
33 | } | ||
34 | nparams = {} | ||
35 | for (i = 0; i < cparams.length; i++) { | ||
36 | temp = cparams[i].split("="); | ||
37 | nparams[temp[0]] = temp[1]; | ||
38 | } | ||
39 | // update parameter values | ||
40 | for (i in params) { | ||
41 | nparams[encodeURIComponent(i)] = encodeURIComponent(params[i]); | ||
42 | } | ||
43 | // serialize the structure | ||
44 | callparams = [] | ||
45 | for (i in nparams) { | ||
46 | callparams.push(i+"="+nparams[i]); | ||
47 | } | ||
48 | window.location.href = url+"?"+callparams.join('&'); | ||
49 | 25 | ||
50 | } | ||
51 | </script> | 26 | </script> |
52 | 27 | ||
53 | {% block extraheadcontent %} | 28 | {% block extraheadcontent %} |