From: Ciro Scognamiglio <ciro.scognamiglio@cslash.net>
Date: Mon, 3 Mar 2014 18:56:38 +0000 (+0100)
Subject: selection of resources (pending), localstorage js enabled class
X-Git-Tag: myslice-1.1~248
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=d51b8b29076dc24a77385bd5b5f1d74959e6af6d;p=unfold.git

selection of resources (pending), localstorage js enabled class
---

diff --git a/portal/static/css/onelab.css b/portal/static/css/onelab.css
index 8147e1c9..300fa933 100644
--- a/portal/static/css/onelab.css
+++ b/portal/static/css/onelab.css
@@ -387,3 +387,6 @@ a.list-group-item p.list-group-item-text {
 }
 .slice-pending button.clear {
 }
+tr.active, tr.active td {
+    background-color:#FFFFCC !important;
+}
diff --git a/portal/static/js/myslice-ui.js b/portal/static/js/myslice-ui.js
index 9522a94d..7f740d39 100644
--- a/portal/static/js/myslice-ui.js
+++ b/portal/static/js/myslice-ui.js
@@ -4,7 +4,6 @@ $(document).ready(function() {
 	
 	var platformParameters = {};
 	
-	var oTable = $("#objectList");
 		
 	$.get("/rest/platform", function(data) {
 		var list = '<div class="list-group-item sl-platfrom"><span class="list-group-item-heading">Testbeds</span></div>';
@@ -13,29 +12,17 @@ $(document).ready(function() {
 		}
 		$('#select-platform').html(list);
 	}).done(function() {
-		// $('a.sl-platfrom').click(function() {
-			// console.log($(this).data('platform'));
-			// platformParameters = { "platform" : $(this).data('platform') };
-			// $('a.sl-platfrom').removeClass('active');
-			// $(this).addClass('active');
-// 			
-			// oTable.load("/list/resource", platformParameters, function(data) {
-				// oTable.fnDraw();
-			// });
-// 			
-			// $('body').data('filters',platformParameters);
-		// });
+		
 	});
 	
 	/* Testbeds list */
-	$('div#testbed-list').ready(function() {
-		$('table#testbedList').load("/table/network/",{'fields' : ['platform'], 'options': ['checkbox']}, function() {
+	$("div#testbed-list").ready(function() {
+		$("table#testbedList").load("/table/network/", { "fields" : ["platform"], "options": ["checkbox"] }, function() {
 			
 		});
 	});
 	
-	//{'columns' : ['hostname','country','type'], 'filters' : { 'country' : 'France' } }
-	oTable.load("/table/resource/", {'fields' : ['hostname','hrn','country','type'], 'options': ['checkbox'] }, function(data) {
+	$("#objectList").load("/table/resource/", {"fields" : ["hostname","hrn","country","type"], "options": ["checkbox"] }, function(data) {
 		$(this).dataTable( {
 			"sScrollY": window.innerHeight - 275,
 			"sDom": "frtiS",
@@ -47,14 +34,41 @@ $(document).ready(function() {
 	        "bSort": true,
 	        "bInfo": false,
 	        "bAutoWidth": true,
-	        "bAutoHeight": false
+	        "bAutoHeight": false,
+	        "fnInitComplete": function(oSettings, json) {
+				for(var i = 0; i < myslice.pending.length; i++) {
+					$('*[data-key="'+myslice.pending[i]+'"]').addClass("active");
+				}
+		    }
 		} );
+		
+		
+		$("input[type=checkbox]").live('click',function() {
+			var cnt = 0;
+			var id = $(this).val();
+			var row = $(this).parent().parent()
+			if (row.hasClass("active")) {
+				row.removeClass("active");
+				myslice.del(id);
+				cnt = myslice.count();
+				$('#badge-pending').text(cnt);
+				if (cnt <= 0) {
+					$('#badge-pending').hide();
+				}
+			} else {
+				row.addClass("active");
+				myslice.add(id);
+				cnt = myslice.count();
+				$('#badge-pending').text(cnt);
+				if (cnt > 0) {
+					$('#badge-pending').show();
+				}
+			}
+		});
 	});
-} );
-
-function drawTable(data) {
 	
-}
+	
+});
 
 //http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
 //make sure to expose csrf in our outcoming ajax/post requests
diff --git a/portal/templates/onelab/onelab_slice-resource-view.html b/portal/templates/onelab/onelab_slice-resource-view.html
index a2971d18..2483b050 100644
--- a/portal/templates/onelab/onelab_slice-resource-view.html
+++ b/portal/templates/onelab/onelab_slice-resource-view.html
@@ -26,7 +26,7 @@
 			<ul class="nav nav-pills">
 				<li><a href="">Unreserved</a></li>
 				<li><a href="">Reserved</a></li>
-				<li><a href="">Pending<span class="badge">42</span></a></li>
+				<li><a href="">Pending<span class="badge" id="badge-pending" style="display:none;"></span></a></li>
 				<li>
 					<button type="button" class="btn btn-primary apply">Apply</button>
 					<button type="button" class="btn btn-default clear">Clear</button>
diff --git a/rest/__init__.py b/rest/__init__.py
index 39235b07..80438a22 100644
--- a/rest/__init__.py
+++ b/rest/__init__.py
@@ -134,7 +134,7 @@ class ObjectRequest(object):
             for p in self.fields :
                 d.append(r[p])
             response_data['data'].append(d)
-         
+        
         return HttpResponse(json.dumps(response_data, cls=DecimalEncoder, default=DateEncoder), content_type="application/json")
 
 def error(msg):
diff --git a/rest/templates/table-default.html b/rest/templates/table-default.html
index 18a943f0..d9713060 100644
--- a/rest/templates/table-default.html
+++ b/rest/templates/table-default.html
@@ -7,8 +7,8 @@
 </thead>
 <tbody>
 {% for d in data %}
-<tr id="{{ d|key:id }}">
-	{% if "checkbox" in options %}<td class="checkbox"><input type="checkbox" name="{{ id }}" value="{{ d|key:id }}" /></td>{% endif %}
+<tr data-key="{{ d|key:id }}">
+	{% if "checkbox" in options %}<td><input type="checkbox" name="{{ id }}" value="{{ d|key:id }}" /></td>{% endif %}
 	{% for f in fields %}<td><div class="line1">{{ d|key:f }}</div></td>{% endfor %}
 </tr>
 {% endfor %}
diff --git a/ui/templates/base.html b/ui/templates/base.html
index 8b4e8271..97326533 100644
--- a/ui/templates/base.html
+++ b/ui/templates/base.html
@@ -8,6 +8,7 @@
 <script type="text/javascript"> {# raw js code - use {% insert prelude_js %} ... {% endinsert %} #} {% container prelude_js %}</script>
 <script src="{{ STATIC_URL }}js/jquery.dataTables.min.js"></script>
 <script src="{{ STATIC_URL }}js/bootstrap.datatables.js"></script>
+<script src="{{ STATIC_URL }}js/myslice.js"></script>
 <script src="{{ STATIC_URL }}js/myslice-ui.js"></script>
 <style type="text/css">{# In case we need to add raw css code #}{% container prelude_css %}</style>
 {{ header_prelude }}