Gert Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | function renderFeatures( data ) { |
| 19 | $(document).ready( function() { |
| 20 | renderView(); |
| 21 | renderData( data ); |
Gert Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 22 | } ); |
| 23 | } |
| 24 | |
| 25 | function renderView() { |
| 26 | renderStatusLine(); |
Guillaume Nodet | b1a6025 | 2009-08-11 20:10:59 +0000 | [diff] [blame] | 27 | renderTable( "Feature Repositories", "repository_table", ["Name", "URL", "Actions"] ); |
Gert Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 28 | 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 Nodet | b1a6025 | 2009-08-11 20:10:59 +0000 | [diff] [blame] | 31 | "<td class='col_Actions'><input type='button' value='Add URL' onclick='addRepositoryUrl()' colspan='2'/></td>" + |
Gert Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 32 | "</tr></tbody></table></div></form><br/>"; |
| 33 | $("#plugin_content").append( txt ); |
Guillaume Nodet | b1a6025 | 2009-08-11 20:10:59 +0000 | [diff] [blame] | 34 | renderTable( "Features", "feature_table", ["Name", "Version", "Repository", "Status", "Actions"] ); |
Gert Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 35 | renderStatusLine(); |
| 36 | } |
| 37 | |
| 38 | function addRepositoryUrl() { |
| 39 | var url = document.getElementById( "url" ).value; |
| 40 | changeRepositoryState( "addRepository", url ); |
| 41 | } |
| 42 | |
| 43 | function renderStatusLine() { |
| 44 | $("#plugin_content").append( "<div class='fullwidth'><div class='statusline'/></div>" ); |
| 45 | } |
| 46 | |
| 47 | function 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 | |
| 59 | function renderData( /* Object */ data ) { |
| 60 | renderStatusData( data.status ); |
| 61 | renderRepositoryTableData( data.repositories ); |
| 62 | renderFeatureTableData( data.features ); |
Guillaume Nodet | b1a6025 | 2009-08-11 20:10:59 +0000 | [diff] [blame] | 63 | $("#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 Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | function renderStatusData( /* String */ status ) { |
| 78 | $(".statusline").empty().append( status ); |
| 79 | } |
| 80 | |
| 81 | function renderRepositoryTableData( /* array of Objects */ repositories ) { |
| 82 | var trElement; |
| 83 | var input; |
| 84 | $("#repository_table > tbody > tr").remove(); |
| 85 | for ( var idx in repositories ) { |
Guillaume Nodet | b1a6025 | 2009-08-11 20:10:59 +0000 | [diff] [blame] | 86 | trElement = tr( null, { id: "repository-" + repositories[idx].name } ); |
Gert Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 87 | renderRepositoryData( trElement, repositories[idx] ); |
| 88 | $("#repository_table > tbody").append( trElement ); |
| 89 | } |
| 90 | $("#repository_table").trigger( "update" ); |
| 91 | } |
| 92 | |
| 93 | function renderRepositoryData( /* Element */ parent, /* Object */ repository ) { |
Guillaume Nodet | b1a6025 | 2009-08-11 20:10:59 +0000 | [diff] [blame] | 94 | parent.appendChild( td( null, null, [text( repository.name )] ) ); |
Gert Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 95 | 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 | |
| 109 | function 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 | |
| 129 | function changeRepositoryState( /* String */ action, /* String */ url ) { |
| 130 | $.post( pluginRoot, {"action": action, "url": url}, function( data ) { |
| 131 | renderData( data ); |
| 132 | }, "json" ); |
| 133 | } |
| 134 | |
| 135 | function renderFeatureTableData( /* array of Objects */ features ) { |
| 136 | $("#feature_table > tbody > tr").remove(); |
| 137 | for ( var idx in features ) { |
Guillaume Nodet | b1a6025 | 2009-08-11 20:10:59 +0000 | [diff] [blame] | 138 | var trElement = tr( null, { id: "feature-" + features[idx].id } ); |
Gert Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 139 | renderFeatureData( trElement, features[idx] ); |
| 140 | $("#feature_table > tbody").append( trElement ); |
| 141 | } |
| 142 | $("#feature_table").trigger( "update" ); |
| 143 | } |
| 144 | |
| 145 | function renderFeatureData( /* Element */ parent, /* Object */ feature ) { |
| 146 | parent.appendChild( td( null, null, [ text( feature.name ) ] ) ); |
| 147 | parent.appendChild( td( null, null, [ text( feature.version ) ] ) ); |
Guillaume Nodet | b1a6025 | 2009-08-11 20:10:59 +0000 | [diff] [blame] | 148 | parent.appendChild( td( null, null, [ text( feature.repository ) ] ) ); |
Gert Vanthienen | 3b48560 | 2009-07-03 14:05:00 +0000 | [diff] [blame] | 149 | 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 | |
| 162 | function 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 | |
| 182 | function changeFeatureState( /* String */ action, /* String */ feature, /* String */ version ) { |
| 183 | $.post( pluginRoot, {"action": action, "feature": feature, "version": version}, function( data ) { |
| 184 | renderData( data ); |
| 185 | }, "json" ); |
| 186 | } |