blob: eef0b4d9d4e4d27b47ece11adc3e87bbddd8e0a7 [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 );
22 $("#repository_table").tablesorter( {
23 headers: {
24 1: { sorter: false }
25 },
26 sortList: [[0,0]],
27 } );
28 $("#feature_table").tablesorter( {
29 headers: {
30 3: { sorter: false }
31 },
32 sortList: [[0,0]],
33 } );
34 } );
35}
36
37function renderView() {
38 renderStatusLine();
39 renderTable( "Feature Repositories", "repository_table", ["URL", "Actions"] );
40 var txt = "<form method='post'><div class='table'><table class='tablelayout'><tbody><tr>" +
41 "<input type='hidden' name='action' value='addRepository'/>" +
42 "<td><input id='url' type='text' name='url' style='width:100%'/></td>" +
43 "<td class='col_Actions'><input type='button' value='Add URL' onclick='addRepositoryUrl()'/></td>" +
44 "</tr></tbody></table></div></form><br/>";
45 $("#plugin_content").append( txt );
46 renderTable( "Features", "feature_table", ["Name", "Version", "Status", "Actions"] );
47 renderStatusLine();
48}
49
50function addRepositoryUrl() {
51 var url = document.getElementById( "url" ).value;
52 changeRepositoryState( "addRepository", url );
53}
54
55function renderStatusLine() {
56 $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" );
57}
58
59function renderTable( /* String */ title, /* String */ id, /* array of Strings */ columns ) {
60 var txt = "<div class='table'><table class='tablelayout'><tbody><tr>" +
61 "<td style='color:#6181A9;background-color:#e6eeee'>" +
62 title + "</td></tr></tbody></table>" +
63 "<table id='" + id + "' class='tablelayout'><thead><tr>";
64 for ( var name in columns ) {
65 txt = txt + "<th class='col_" + columns[name] + "' style='border-top:#e6eeee'>" + columns[name] + "</th>";
66 }
67 txt = txt + "</tr></thead><tbody></tbody></table></div>";
68 $("#plugin_content").append( txt );
69}
70
71function renderData( /* Object */ data ) {
72 renderStatusData( data.status );
73 renderRepositoryTableData( data.repositories );
74 renderFeatureTableData( data.features );
75}
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 ) {
86 trElement = tr( null, { id: "repository-" + idx } );
87 renderRepositoryData( trElement, repositories[idx] );
88 $("#repository_table > tbody").append( trElement );
89 }
90 $("#repository_table").trigger( "update" );
91}
92
93function renderRepositoryData( /* Element */ parent, /* Object */ repository ) {
94 parent.appendChild( td( null, null, [text( repository.url )] ) );
95
96 var actionsTd = td( null, null );
97 var div = createElement( "div", null, {
98 style: { "text-align": "left"}
99 } );
100 actionsTd.appendChild( div );
101
102 for ( var a in repository.actions ) {
103 repositoryButton( div, repository.url, repository.actions[a] );
104 }
105 parent.appendChild( actionsTd );
106}
107
108function repositoryButton( /* Element */ parent, /* String */ url, /* Obj */ action ) {
109 if ( !action.enabled ) {
110 return;
111 }
112
113 var input = createElement( "input", null, {
114 type: 'image',
115 style: {"margin-left": "10px"},
116 title: action.title,
117 alt: action.title,
118 src: imgRoot + '/bundle_' + action.image + '.png'
119 } );
120 $(input).click( function() {changeRepositoryState( action.op, url )} );
121
122 if ( !action.enabled ) {
123 $(input).attr( "disabled", true );
124 }
125 parent.appendChild( input );
126}
127
128function changeRepositoryState( /* String */ action, /* String */ url ) {
129 $.post( pluginRoot, {"action": action, "url": url}, function( data ) {
130 renderData( data );
131 }, "json" );
132}
133
134function renderFeatureTableData( /* array of Objects */ features ) {
135 $("#feature_table > tbody > tr").remove();
136 for ( var idx in features ) {
137 var trElement = tr( null, { id: "feature-" + idx } );
138 renderFeatureData( trElement, features[idx] );
139 $("#feature_table > tbody").append( trElement );
140 }
141 $("#feature_table").trigger( "update" );
142}
143
144function renderFeatureData( /* Element */ parent, /* Object */ feature ) {
145 parent.appendChild( td( null, null, [ text( feature.name ) ] ) );
146 parent.appendChild( td( null, null, [ text( feature.version ) ] ) );
147 parent.appendChild( td( null, null, [ text( feature.state ) ] ) );
148 var actionsTd = td( null, null );
149 var div = createElement( "div", null, {
150 style: { "text-align": "left"}
151 } );
152 actionsTd.appendChild( div );
153
154 for ( var a in feature.actions ) {
155 featureButton( div, feature.name, feature.version, feature.actions[a] );
156 }
157 parent.appendChild( actionsTd );
158}
159
160function featureButton( /* Element */ parent, /* String */ name, /* String */ version, /* Obj */ action ) {
161 if ( !action.enabled ) {
162 return;
163 }
164
165 var input = createElement( "input", null, {
166 type: 'image',
167 style: {"margin-left": "10px"},
168 title: action.title,
169 alt: action.title,
170 src: imgRoot + '/bundle_' + action.image + '.png'
171 } );
172 $(input).click( function() {changeFeatureState( action.op, name, version )} );
173
174 if ( !action.enabled ) {
175 $(input).attr( "disabled", true );
176 }
177 parent.appendChild( input );
178}
179
180function changeFeatureState( /* String */ action, /* String */ feature, /* String */ version ) {
181 $.post( pluginRoot, {"action": action, "feature": feature, "version": version}, function( data ) {
182 renderData( data );
183 }, "json" );
184}