FELIX-1988 Apply 20.obr_plugin.patch by Valentin Valchev (thanks) (fixed license header of BundleRepositoryRender)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@912369 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
index cac6186..48ea630 100644
--- a/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
+++ b/webconsole/src/main/resources/OSGI-INF/l10n/bundle.properties
@@ -40,6 +40,7 @@
 save=Save
 reset=Reset
 delete=Delete
+refresh=Refresh
 
 # VMStat plugin
 vmstat.stopped=Framework has been stopped.
@@ -171,4 +172,21 @@
 license.status.ok=The following bundles contains license files.
 license.status.none=No bundles with license files available
 license.resources=Bundle Resources: 
-license.resources.embedded=Embedded {0}: 
\ No newline at end of file
+license.resources.embedded=Embedded {0}: 
+
+# OBR Plugin
+obr.status.ok=The Apache Bundle Repository service is up and running.
+obr.status.no=The Apache Bundle Repository service is not available!
+obr.version.select=Select Version...
+obr.repo.title=Bundle Repositories
+obr.action.add=Add
+obr.action.search=Search
+obr.action.deploy=Deploy Selected
+obr.action.deploystart=Deploy and Start Selected
+obr.repo.name=Name
+obr.repo.url=URL
+obr.repo.lastModified=Last Modified
+obr.repo.actions=Actions
+obr.res.title=Available Resources
+obr.res.name=Resource Name
+obr.res.installedVer=Installed Version
diff --git a/webconsole/src/main/resources/res/lib/support.js b/webconsole/src/main/resources/res/lib/support.js
index 8b161c8..67078f0 100644
--- a/webconsole/src/main/resources/res/lib/support.js
+++ b/webconsole/src/main/resources/res/lib/support.js
@@ -70,11 +70,8 @@
 	);
 
 	// register global ajax error handler
-	$(document).ajaxError( function(event, XMLHttpRequest, ajaxOptions, thrownError) {
-		var pre = '<br/><pre>';
-		for (i in event) pre += i + '=' + event[i] + '\n'
-		pre += '</pre>';
-		Xalert('The request failed: ' + thrownError + pre, 'AJAX Error');
+	$(document).ajaxError( function(event, req) {
+		Xalert('The request failed: <br/><pre>' + req.statusText + '</pre>', 'AJAX Error');
 	});
 
 	initStaticWidgets();
@@ -127,6 +124,7 @@
 	Xdialog(text).dialog({
 		modal: true,
 		title: title,
+		width: '70%',
 		buttons: {
 			"Ok": function() {
 				$(this).dialog('close');
diff --git a/webconsole/src/main/resources/res/ui/obr.js b/webconsole/src/main/resources/res/ui/obr.js
new file mode 100644
index 0000000..53e532b
--- /dev/null
+++ b/webconsole/src/main/resources/res/ui/obr.js
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+var repoTable = false;
+var repoTableTemplate = false;
+var addRepoUri = false;
+var resTable = false;
+var searchField = false;
+
+/* displays a date in the user's local timezone */
+function localTm(time) {
+	return (time ? new Date(time) : new Date()).toLocaleString();
+}
+
+function doRepoAction(action, url) {
+	if ( !url ) {
+		Xalert('Invalid URI: ' + url, 'Error');
+	} else {
+		$.post(pluginRoot, {
+			'action' : action,
+			'url'    : url
+		}, renderData, 'json');
+	}
+}
+
+function renderResource(res) {
+	// aply filtering
+	var match = searchField.val();
+	if (match) {
+		match = new RegExp( match );
+		if ( !match.test(res.presentationname) ) return;
+	}
+	
+	// proceed with resource
+	var _id = res.symbolicname.replace(/\./g, '_');
+	var _tr = resTable.find('#' + _id);
+
+	if (_tr.length == 0) { // not created yet, create it
+		var _select = createElement('select', null, { name : 'bundle' }, [
+			createElement( 'option', null, { value : '-' }, [
+				text( i18n.selectVersion)
+			]),
+			createElement( 'option', null, { value : res.id }, [
+				text( res.version + (res.installed ? ' *' : '') )
+			])
+		]);
+		_tr = tr( null, { 'id' : _id } , [
+			td( null, null, [ _select ] ),
+			td( null, null, [ text(res.presentationname) ] ),
+			td( null, null, [ text(res.installed ? res.version : '') ] )
+		]);
+		resTable.append( _tr );
+	} else { // append the additional version
+		_tr.find( 'select' ).append (
+			createElement( 'option', null, { value : res.id }, [
+				text( res.version  + (res.installed ? ' *' : '') )
+			])
+		);
+		if (res.installed) _tr.find( 'td:eq(2)' ).text( res.version );
+	}
+}
+
+function renderRepository(repo) {
+	var _tr = repoTableTemplate.clone();
+	_tr.find('td:eq(0)').text( repo.name );
+	_tr.find('td:eq(1)').text( repo.url );
+	_tr.find('td:eq(2)').text( localTm(repo.lastModified) );
+	_tr.find('li:eq(0)').click(function() {
+		doRepoAction('refresh', repo.url);
+	});
+	_tr.find('li:eq(1)').click(function() {
+		doRepoAction('delete', repo.url);
+	});
+	repoTable.append(_tr);
+	
+	for(var i in repo.resources) {
+		renderResource( repo.resources[i] );
+	}
+}
+
+function renderData(data) {
+	obrData = data;
+	repoTable.empty();
+	resTable.empty();
+	if ( data.status ) {
+		$('.statline').html(i18n.status_ok);
+		for (var i in data.repositories ) {
+			renderRepository( data.repositories[i] );
+		}
+	} else {
+		$('.statline').html(i18n.status_no);
+	}
+}
+
+$(document).ready( function() {
+	repoTable = $('#repoTable tbody');
+	repoTableTemplate = repoTable.find('tr').clone();
+	addRepoUri = $('#addRepoUri');
+	resTable = $('#resTable tbody').empty();
+	searchField = $('#searchField');
+
+	$('#addRepoBtn').click(function() {
+		doRepoAction('add', addRepoUri.val());
+	});
+	$('#searchBtn').click(function() {
+		renderData(obrData);
+		return false;
+	});
+
+	renderData(obrData);
+});
\ No newline at end of file
diff --git a/webconsole/src/main/resources/templates/obr.html b/webconsole/src/main/resources/templates/obr.html
new file mode 100644
index 0000000..12eb3bf
--- /dev/null
+++ b/webconsole/src/main/resources/templates/obr.html
@@ -0,0 +1,68 @@
+<script type="text/javascript" src="res/ui/obr.js"></script>
+<script type="text/javascript">
+var i18n = {
+	status_ok : '${obr.status.ok}',
+	status_no : '${obr.status.no}',
+	selectVersion : '${obr.version.select}'
+}
+var obrData = ${__data__};
+</script>
+
+<p class="statline">${obr.status.ok}</p>
+
+<div class="ui-widget-header ui-corner-top buttonGroup">
+	<span style="float: left; margin-left: 1em">${obr.repo.title}</span>
+	<input style="width: 50%" type="text" id="addRepoUri" />
+	<button id="addRepoBtn">${obr.action.add}</button>
+</div>
+
+<table id="repoTable" class="nicetable">
+	<thead>
+		<tr>
+			<th class="col_Name">${obr.repo.name}</th>
+			<th class="col_URL">${obr.repo.url}</th>
+			<th class="col_lastMod">${obr.repo.lastModified}</th>
+			<th class="col_Actions">${obr.repo.actions}</th>
+		</tr>
+	</thead>
+	<tbody> <!-- template: will be replaced dynamically by JS -->
+		<tr>
+			<td>name</td>
+			<td>url</td>
+			<td>date</td>
+			<td>
+				<ul class="icons ui-widget">
+					<li class="dynhover" title="${refresh}"><span class="ui-icon ui-icon-refresh">&nbsp;</span></li>
+					<li class="dynhover" title="${delete}"><span class="ui-icon ui-icon-trash">&nbsp;</span></li>
+				</ul>
+			</td>
+		</tr>
+	</tbody>
+</table>
+
+<br/>
+
+<form id="installForm" method="post" action="">
+	<div class="ui-widget-header ui-corner-top buttonGroup">
+		<span style="float: left; margin-left: 1em">${obr.res.title}</span>
+		<input type="text" id="searchField" />
+		<button id="searchBtn">${obr.action.search}</button>
+		<input type="submit" name="deploy" value="${obr.action.deploy}" />
+		<input type="submit" name="deploystart" value="${obr.action.deploystart}" />
+	</div>
+
+	<table id="resTable" class="nicetable">
+		<thead>
+			<tr>
+				<th class="col_Version">${version}</th>
+				<th class="col_ResName">${obr.res.name}</th>
+				<th class="col_VersionInst">${obr.res.installedVer}</th>
+			</tr>
+		</thead>
+		<tbody>
+			<tr><td colspan="2">dummy</td></tr>
+		</tbody>
+	</table>
+</form>
+
+<br/>
\ No newline at end of file