blob: 7fcf4a85ebcb7f1ca99d0a115d37a500087c2d3f [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"] );
Gert Vanthienen3b485602009-07-03 14:05:00 +000028 var txt = "<form method='post'><div class='table'><table class='tablelayout'><tbody><tr>" +
29 "<input type='hidden' name='action' value='addRepository'/>" +
30 "<td><input id='url' type='text' name='url' style='width:100%'/></td>" +
Guillaume Nodetb1a60252009-08-11 20:10:59 +000031 "<td class='col_Actions'><input type='button' value='Add URL' onclick='addRepositoryUrl()' colspan='2'/></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;
84 $("#repository_table > tbody > tr").remove();
85 for ( var idx in repositories ) {
Guillaume Nodetb1a60252009-08-11 20:10:59 +000086 trElement = tr( null, { id: "repository-" + repositories[idx].name } );
Gert Vanthienen3b485602009-07-03 14:05:00 +000087 renderRepositoryData( trElement, repositories[idx] );
88 $("#repository_table > tbody").append( trElement );
89 }
90 $("#repository_table").trigger( "update" );
91}
92
93function renderRepositoryData( /* Element */ parent, /* Object */ repository ) {
Guillaume Nodetb1a60252009-08-11 20:10:59 +000094 parent.appendChild( td( null, null, [text( repository.name )] ) );
Gert Vanthienen3b485602009-07-03 14:05:00 +000095 parent.appendChild( td( null, null, [text( repository.url )] ) );
96
97 var actionsTd = td( null, null );
98 var div = createElement( "div", null, {
99 style: { "text-align": "left"}
100 } );
101 actionsTd.appendChild( div );
102
103 for ( var a in repository.actions ) {
104 repositoryButton( div, repository.url, repository.actions[a] );
105 }
106 parent.appendChild( actionsTd );
107}
108
109function repositoryButton( /* Element */ parent, /* String */ url, /* Obj */ action ) {
110 if ( !action.enabled ) {
111 return;
112 }
113
114 var input = createElement( "input", null, {
115 type: 'image',
116 style: {"margin-left": "10px"},
117 title: action.title,
118 alt: action.title,
119 src: imgRoot + '/bundle_' + action.image + '.png'
120 } );
121 $(input).click( function() {changeRepositoryState( action.op, url )} );
122
123 if ( !action.enabled ) {
124 $(input).attr( "disabled", true );
125 }
126 parent.appendChild( input );
127}
128
129function changeRepositoryState( /* String */ action, /* String */ url ) {
130 $.post( pluginRoot, {"action": action, "url": url}, function( data ) {
131 renderData( data );
132 }, "json" );
133}
134
135function renderFeatureTableData( /* array of Objects */ features ) {
136 $("#feature_table > tbody > tr").remove();
137 for ( var idx in features ) {
Guillaume Nodetb1a60252009-08-11 20:10:59 +0000138 var trElement = tr( null, { id: "feature-" + features[idx].id } );
Gert Vanthienen3b485602009-07-03 14:05:00 +0000139 renderFeatureData( trElement, features[idx] );
140 $("#feature_table > tbody").append( trElement );
141 }
142 $("#feature_table").trigger( "update" );
143}
144
145function renderFeatureData( /* Element */ parent, /* Object */ feature ) {
146 parent.appendChild( td( null, null, [ text( feature.name ) ] ) );
147 parent.appendChild( td( null, null, [ text( feature.version ) ] ) );
Guillaume Nodetb1a60252009-08-11 20:10:59 +0000148 parent.appendChild( td( null, null, [ text( feature.repository ) ] ) );
Gert Vanthienen3b485602009-07-03 14:05:00 +0000149 parent.appendChild( td( null, null, [ text( feature.state ) ] ) );
150 var actionsTd = td( null, null );
151 var div = createElement( "div", null, {
152 style: { "text-align": "left"}
153 } );
154 actionsTd.appendChild( div );
155
156 for ( var a in feature.actions ) {
157 featureButton( div, feature.name, feature.version, feature.actions[a] );
158 }
159 parent.appendChild( actionsTd );
160}
161
162function featureButton( /* Element */ parent, /* String */ name, /* String */ version, /* Obj */ action ) {
163 if ( !action.enabled ) {
164 return;
165 }
166
167 var input = createElement( "input", null, {
168 type: 'image',
169 style: {"margin-left": "10px"},
170 title: action.title,
171 alt: action.title,
172 src: imgRoot + '/bundle_' + action.image + '.png'
173 } );
174 $(input).click( function() {changeFeatureState( action.op, name, version )} );
175
176 if ( !action.enabled ) {
177 $(input).attr( "disabled", true );
178 }
179 parent.appendChild( input );
180}
181
182function changeFeatureState( /* String */ action, /* String */ feature, /* String */ version ) {
183 $.post( pluginRoot, {"action": action, "feature": feature, "version": version}, function( data ) {
184 renderData( data );
185 }, "json" );
186}