blob: 3bfc2e499cda5c36f85d8a7a0cbfc572e19b2cf4 [file] [log] [blame]
Gert Vanthienen3b485602009-07-03 14:05:00 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18function renderFeatures( data ) {
19 $(document).ready( function() {
20 renderView();
21 renderData( data );
Gert Vanthienen3b485602009-07-03 14:05:00 +000022 } );
23}
24
25function renderView() {
26 renderStatusLine();
Guillaume Nodetb1a60252009-08-11 20:10:59 +000027 renderTable( "Feature Repositories", "repository_table", ["Name", "URL", "Actions"] );
Guillaume Nodet429d0492009-08-12 14:14:30 +000028 var txt = "<form method='post'><div class='table'><table id='repository_table_footer' class='tablelayout'><tbody>" +
29 "<tr><input type='hidden' name='action' value='addRepository'/>" +
30 "<td><input id='url' type='text' name='url' style='width:100%' colspan='2'/></td>" +
31 "<td class='col_Actions'><input type='button' value='Add URL' onclick='addRepositoryUrl()'/></td>" +
Gert Vanthienen3b485602009-07-03 14:05:00 +000032 "</tr></tbody></table></div></form><br/>";
33 $("#plugin_content").append( txt );
Guillaume Nodetb1a60252009-08-11 20:10:59 +000034 renderTable( "Features", "feature_table", ["Name", "Version", "Repository", "Status", "Actions"] );
Gert Vanthienen3b485602009-07-03 14:05:00 +000035 renderStatusLine();
36}
37
38function addRepositoryUrl() {
39 var url = document.getElementById( "url" ).value;
40 changeRepositoryState( "addRepository", url );
41}
42
43function renderStatusLine() {
44 $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" );
45}
46
47function renderTable( /* String */ title, /* String */ id, /* array of Strings */ columns ) {
48 var txt = "<div class='table'><table class='tablelayout'><tbody><tr>" +
49 "<td style='color:#6181A9;background-color:#e6eeee'>" +
50 title + "</td></tr></tbody></table>" +
51 "<table id='" + id + "' class='tablelayout'><thead><tr>";
52 for ( var name in columns ) {
53 txt = txt + "<th class='col_" + columns[name] + "' style='border-top:#e6eeee'>" + columns[name] + "</th>";
54 }
55 txt = txt + "</tr></thead><tbody></tbody></table></div>";
56 $("#plugin_content").append( txt );
57}
58
59function renderData( /* Object */ data ) {
60 renderStatusData( data.status );
61 renderRepositoryTableData( data.repositories );
62 renderFeatureTableData( data.features );
Guillaume Nodetb1a60252009-08-11 20:10:59 +000063 $("#repository_table").tablesorter( {
64 headers: {
65 2: { sorter: false }
66 },
67 sortList: [[0,0]],
68 } );
69 $("#feature_table").tablesorter( {
70 headers: {
71 4: { sorter: false }
72 },
73 sortList: [[0,0]],
74 } );
Gert Vanthienen3b485602009-07-03 14:05:00 +000075}
76
77function renderStatusData( /* String */ status ) {
78 $(".statusline").empty().append( status );
79}
80
81function renderRepositoryTableData( /* array of Objects */ repositories ) {
82 var trElement;
83 var input;
Guillaume Nodet429d0492009-08-12 14:14:30 +000084 var needsLegend = false;
Gert Vanthienen3b485602009-07-03 14:05:00 +000085 $("#repository_table > tbody > tr").remove();
86 for ( var idx in repositories ) {
Guillaume Nodet429d0492009-08-12 14:14:30 +000087 var name = repositories[idx].name;
88 trElement = tr( null, { id: "repository-" + name } );
Gert Vanthienen3b485602009-07-03 14:05:00 +000089 renderRepositoryData( trElement, repositories[idx] );
Guillaume Nodet429d0492009-08-12 14:14:30 +000090 $("#repository_table > tbody").append( trElement );
91 if ( name[ name.length - 1 ] == "*" ) {
92 needsLegend = true;
93 }
Gert Vanthienen3b485602009-07-03 14:05:00 +000094 }
95 $("#repository_table").trigger( "update" );
Guillaume Nodet429d0492009-08-12 14:14:30 +000096 if ( needsLegend ) {
97 trElement = tr( null, null ) ;
98 trElement.appendChild( td( null, { colspan: 3 },
99 [ text( "* Installed via deploy directory" ) ] ) );
100 $("#repository_table_footer > tbody").prepend( trElement );
101 }
102 $("#repository_table_footer").trigger( "update" );
Gert Vanthienen3b485602009-07-03 14:05:00 +0000103}
104
105function renderRepositoryData( /* Element */ parent, /* Object */ repository ) {
Guillaume Nodet429d0492009-08-12 14:14:30 +0000106 parent.appendChild( td( null, null, [ text( repository.name ) ] ) );
107 parent.appendChild( td( null, null, [ text( repository.url ) ] ) );
Gert Vanthienen3b485602009-07-03 14:05:00 +0000108
109 var actionsTd = td( null, null );
110 var div = createElement( "div", null, {
111 style: { "text-align": "left"}
112 } );
113 actionsTd.appendChild( div );
114
115 for ( var a in repository.actions ) {
116 repositoryButton( div, repository.url, repository.actions[a] );
117 }
118 parent.appendChild( actionsTd );
119}
120
121function repositoryButton( /* Element */ parent, /* String */ url, /* Obj */ action ) {
122 if ( !action.enabled ) {
123 return;
124 }
125
126 var input = createElement( "input", null, {
127 type: 'image',
128 style: {"margin-left": "10px"},
129 title: action.title,
130 alt: action.title,
131 src: imgRoot + '/bundle_' + action.image + '.png'
132 } );
133 $(input).click( function() {changeRepositoryState( action.op, url )} );
134
135 if ( !action.enabled ) {
136 $(input).attr( "disabled", true );
137 }
138 parent.appendChild( input );
139}
140
141function changeRepositoryState( /* String */ action, /* String */ url ) {
142 $.post( pluginRoot, {"action": action, "url": url}, function( data ) {
143 renderData( data );
144 }, "json" );
145}
146
147function renderFeatureTableData( /* array of Objects */ features ) {
148 $("#feature_table > tbody > tr").remove();
149 for ( var idx in features ) {
Guillaume Nodetb1a60252009-08-11 20:10:59 +0000150 var trElement = tr( null, { id: "feature-" + features[idx].id } );
Gert Vanthienen3b485602009-07-03 14:05:00 +0000151 renderFeatureData( trElement, features[idx] );
152 $("#feature_table > tbody").append( trElement );
153 }
154 $("#feature_table").trigger( "update" );
155}
156
157function renderFeatureData( /* Element */ parent, /* Object */ feature ) {
158 parent.appendChild( td( null, null, [ text( feature.name ) ] ) );
159 parent.appendChild( td( null, null, [ text( feature.version ) ] ) );
Guillaume Nodetb1a60252009-08-11 20:10:59 +0000160 parent.appendChild( td( null, null, [ text( feature.repository ) ] ) );
Gert Vanthienen3b485602009-07-03 14:05:00 +0000161 parent.appendChild( td( null, null, [ text( feature.state ) ] ) );
162 var actionsTd = td( null, null );
163 var div = createElement( "div", null, {
164 style: { "text-align": "left"}
165 } );
166 actionsTd.appendChild( div );
167
168 for ( var a in feature.actions ) {
169 featureButton( div, feature.name, feature.version, feature.actions[a] );
170 }
171 parent.appendChild( actionsTd );
172}
173
174function featureButton( /* Element */ parent, /* String */ name, /* String */ version, /* Obj */ action ) {
175 if ( !action.enabled ) {
176 return;
177 }
178
179 var input = createElement( "input", null, {
180 type: 'image',
181 style: {"margin-left": "10px"},
182 title: action.title,
183 alt: action.title,
184 src: imgRoot + '/bundle_' + action.image + '.png'
185 } );
186 $(input).click( function() {changeFeatureState( action.op, name, version )} );
187
188 if ( !action.enabled ) {
189 $(input).attr( "disabled", true );
190 }
191 parent.appendChild( input );
192}
193
194function changeFeatureState( /* String */ action, /* String */ feature, /* String */ version ) {
195 $.post( pluginRoot, {"action": action, "feature": feature, "version": version}, function( data ) {
196 renderData( data );
197 }, "json" );
198}