From: Loic Baron <loic.baron@lip6.fr>
Date: Thu, 23 Apr 2015 16:58:06 +0000 (+0200)
Subject: Validate Requests: spinner while validating
X-Git-Tag: myslice-1.3~14
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=5826fa4ed4a6e48975387a5ffc469cb60ba194cc;p=myslice.git

Validate Requests: spinner while validating
---

diff --git a/portal/static/js/requests.js b/portal/static/js/requests.js
new file mode 100644
index 00000000..09535a7a
--- /dev/null
+++ b/portal/static/js/requests.js
@@ -0,0 +1,105 @@
+function unspin_all_status(){
+    $('.portal__validate__checkbox').each(function (index) {
+        if(this.checked){
+            t_id = this.id.split('__');
+            status_id = t_id[t_id.length-2]+'__'+t_id[t_id.length-1]+'-status-loading';
+            $('#'+status_id).css('display','none');    
+        }
+    });
+}
+function spin_all_status(){
+    $('.portal__validate__checkbox').each(function (index) {
+        if(this.checked){
+            t_id = this.id.split('__');
+            status_id = t_id[t_id.length-2]+'__'+t_id[t_id.length-1]+'-status-loading';
+            $('#'+status_id).css('display','inline');
+        }
+    });
+}
+	$(document).ready(function() {
+		$("li#nav-request").addClass("active");
+		$('table.requests').dataTable({
+		    "sDom": "frtiS",
+            "bScrollCollapse": true,
+            "bStateSave": true,
+            "bPaginate": false,
+            "bLengthChange": false,
+            "bFilter": false,
+            "bSort": true,
+            "bInfo": false,
+            "bAutoWidth": true,
+            "bAutoHeight": false,
+		});
+	});
+	function on_click_event() {
+		var ids = []; 
+		$('.portal__validate__checkbox').each(function(i, el) {
+			if ($(el).prop('checked')) {
+				// portal__validate__checkbox__slice__2
+				var id_array = $(el).attr('id').split('__');
+				// push(slice__2)
+				ids.push(id_array[3] + '__' + id_array[4]);
+			}
+		});
+		if (ids.length > 0) {
+            spin_all_status();
+			var id_str = ids.join('/');
+
+			// XXX spinner
+			$.getJSON('/portal/validate_action/' + id_str, function(status) {
+				$.each(status, function(request_type__id, request_status) {
+					// request_status: NAME -> dict (status, description)
+					var status_str = '';
+					$.each(request_status, function(name, result) {
+						if (status_str != '')
+							status_str += ' -- ';
+
+						if (result.status) {
+							status_str += '<font color="green">OK</font>';
+							$('#portal__validate__checkbox__' + request_type__id).hide();
+						} else {
+							status_str += '<font color="red">ERROR: ' + result.description + '</font>';
+						}
+					});
+					$('#portal__status__' + request_type__id).html(status_str);
+				});
+                unspin_all_status();
+			});
+		}
+	}
+	function on_click_reject() {
+		var ids = []; 
+		$('.portal__validate__checkbox').each(function(i, el) {
+			if ($(el).prop('checked')) {
+				// portal__validate__checkbox__slice__2
+				var id_array = $(el).attr('id').split('__');
+				// push(slice__2)
+				ids.push(id_array[3] + '__' + id_array[4]);
+			}
+		});
+		if (ids.length > 0) {
+            spin_all_status();
+			var id_str = ids.join('/');
+
+			// XXX spinner
+			$.getJSON('/portal/reject_action/' + id_str, function(status) {
+				$.each(status, function(request_type__id, request_status) {
+					// request_status: NAME -> dict (status, description)
+					var status_str = '';
+					$.each(request_status, function(name, result) {
+						if (status_str != '')
+							status_str += ' -- ';
+
+						if (result.status) {
+							status_str += '<font color="green">Rejected</font>';
+							$('#portal__validate__checkbox__' + request_type__id).hide();
+						} else {
+							status_str += '<font color="red">ERROR: ' + result.description + '</font>';
+						}
+					});
+					$('#portal__status__' + request_type__id).html(status_str);
+				});
+                unspin_all_status();
+			});
+		}
+	}
diff --git a/portal/templates/fed4fire/fed4fire_institution.html b/portal/templates/fed4fire/fed4fire_institution.html
index f9a272ef..facc1180 100644
--- a/portal/templates/fed4fire/fed4fire_institution.html
+++ b/portal/templates/fed4fire/fed4fire_institution.html
@@ -2,6 +2,7 @@
 
 {% block head %} 
 <script type="text/javascript" src="{{STATIC_URL}}/js/institution.js"></script>
+<script type="text/javascript" src="{{STATIC_URL}}js/requests.js"></script>
 {% endblock head %}
 
 {% block content %}
diff --git a/portal/templates/management-tab-requests.html b/portal/templates/management-tab-requests.html
index 0b9b8f80..eea48461 100644
--- a/portal/templates/management-tab-requests.html
+++ b/portal/templates/management-tab-requests.html
@@ -1,100 +1,3 @@
-
-<script type="text/javascript">
-	$(document).ready(function() {
-		$("li#nav-request").addClass("active");
-		$('table.requests').dataTable({
-		    "sDom": "frtiS",
-            "bScrollCollapse": true,
-            "bStateSave": true,
-            "bPaginate": false,
-            "bLengthChange": false,
-            "bFilter": false,
-            "bSort": true,
-            "bInfo": false,
-            "bAutoWidth": true,
-            "bAutoHeight": false,
-		});
-	});
-	function on_click_event() {
-		var ids = []; 
-		$('.portal__validate__checkbox').each(function(i, el) {
-			if ($(el).prop('checked')) {
-				// portal__validate__checkbox__slice__2
-				var id_array = $(el).attr('id').split('__');
-				// push(slice__2)
-				ids.push(id_array[3] + '__' + id_array[4]);
-			}
-		});
-		if (ids.length > 0) {
-			var id_str = ids.join('/');
-
-			// XXX spinner
-
-			$.getJSON('/portal/validate_action/' + id_str,
-				function(status) {
-					$.each(status, function(request_type__id, request_status) {
-						// request_status: NAME -> dict (status, description)
-						var status_str = '';
-						$.each(request_status, function(name, result) {
-							if (status_str != '')
-								status_str += ' -- ';
-
-							if (result.status) {
-								status_str += '<font color="green">OK</font>';
-								$('#portal__validate__checkbox__' + request_type__id).hide();
-							} else {
-								status_str += '<font color="red">ERROR: ' + result.description + '</font>';
-							}
-						});
-						$('#portal__status__' + request_type__id).html(status_str);
-
-
-					});
-				}
-			);
-		}
-	}
-	function on_click_reject() {
-		var ids = []; 
-		$('.portal__validate__checkbox').each(function(i, el) {
-			if ($(el).prop('checked')) {
-				// portal__validate__checkbox__slice__2
-				var id_array = $(el).attr('id').split('__');
-				// push(slice__2)
-				ids.push(id_array[3] + '__' + id_array[4]);
-			}
-		});
-		if (ids.length > 0) {
-			var id_str = ids.join('/');
-
-			// XXX spinner
-
-			$.getJSON('/portal/reject_action/' + id_str,
-				function(status) {
-					$.each(status, function(request_type__id, request_status) {
-						// request_status: NAME -> dict (status, description)
-						var status_str = '';
-						$.each(request_status, function(name, result) {
-							if (status_str != '')
-								status_str += ' -- ';
-
-							if (result.status) {
-								status_str += '<font color="green">Rejected</font>';
-								$('#portal__validate__checkbox__' + request_type__id).hide();
-							} else {
-								status_str += '<font color="red">ERROR: ' + result.description + '</font>';
-							}
-						});
-						$('#portal__status__' + request_type__id).html(status_str);
-
-
-					});
-				}
-			);
-		}
-	}
-</script>
-
 <div class="container-fluid">
 <div class="col-md-12">
 	<h2>From your authorities</h2>
@@ -150,7 +53,10 @@
     		</td>
     		<td>{{ request.timestamp }}</td>
     		
-    		<td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
+    		<td>
+            <span id='portal__status__{{request.type}}__{{request.id}}'></span>
+            <div id='{{request.type}}__{{request.id}}-status-loading' style="display:none;"><img src="{{ STATIC_URL }}img/loading.gif"></div>
+            </td>
     
         <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
     	  </tr>
@@ -167,121 +73,6 @@
 	</div>
 {% endif %}
 </div>
-
-{% if sub_authorities %}
-<br />
-<div class="col-md-12">
-	<h2>From your sub-authorities</h2>
-</div>
-
-	{% for authority, requests in sub_authorities.items %}
-	<div class="col-md-12">
-	<h3>{{authority}}</h3>
-	    <table class="table">
-	      <th>
-	        <td>Type</td>
-	        <td>Id</td>
-	        <td>Details</td>
-	        <td>Timestamp</td>
-	        <td>Status</td>
-	      </th>
-	    {% for request in requests %}
-		  <tr>
-			<td>
-			{% if request.allowed == 'allowed' %}
-			<input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
-			{% else %}
-				{% if request.allowed == 'expired' %}
-					expired
-				{% else %} {# denied #}
-					denied
-				{% endif %}
-			{% endif %}
-			</td>
-			<td>{{ request.type }}</td>
-			<td>{{ request.id }}</td>
-			<td>
-	        {% if request.type == 'user' %}
-	        Login: {{request.login}} -- First name: {{request.first_name}} -- Last name: {{request.last_name}} -- Email: {{request.email}}
-	        {% else %}
-	            {% if request.type == 'slice' %}
-	        Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
-	           {% elif request.type == 'project' %}
-            <b>{{request.project_name}}</b>  -- {{ request.user_hrn }} -- Purpose: {{request.purpose}}
-	           {% elif request.type == 'join' %}
-            <b>{{request.user_hrn}}</b> --  to join {{ request.authority_hrn }}
-	            {% else %} {# authority #}
-	        Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
-	            {% endif %}
-	        {% endif %}
-			</td>
-			<td>{{ request.timestamp }}</td>
-			
-			<td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
-	
-	    <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
-		  </tr>
-	    {% endfor %}
-	    </table>
-	</div>
-	{% endfor %}
-{% endif %}
-{% if delegation_authorities %}
-<br />
-<div class="col-md-12">
-	<h2>From your authorities with delegation</h2>
-</div>
-
-	{% for authority, requests in delegation_authorities.items %}
-	<div class="col-md-12">
-		<h3>{{authority}}</h3>
-		    <table class="table">
-		      <th>
-		        <td>Type</td>
-		        <td>Id</td>
-		        <td>Details</td>
-		        <td>Timestamp</td>
-		        <td>Status</td>
-		      </th>
-		    {% for request in requests %}
-			  <tr>
-				<td>
-				{% if request.allowed == 'allowed' %}
-				<input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
-				{% else %}
-					{% if request.allowed == 'expired' %}
-						expired
-					{% else %} {# denied #}
-						denied
-					{% endif %}
-				{% endif %}
-				</td>
-				<td>{{ request.type }}</td>
-				<td>{{ request.id }}</td>
-				<td>
-		        {% if request.type == 'user' %}
-		        Login: {{request.login}} -- First name: {{request.first_name}} -- Last name: {{request.last_name}} -- Email: {{request.email}}
-		        {% else %}
-		            {% if request.type == 'slice' %}
-		        Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
-		            {% elif request.type == 'project' %}
-                    <b>{{request.project_name}}</b>  -- {{ request.user_hrn }} -- Purpose: {{request.purpose}}
-		            {% else %} {# authority #}
-		        Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
-		            {% endif %}
-		       {% endif %}
-				</td>
-				<td>{{ request.timestamp }}</td>
-				
-				<td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
-		
-		    <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
-			  </tr>
-		    {% endfor %}
-		    </table>
-		</div>
-		{% endfor %}
-{% endif %}
 <br />
 <div class="col-md-12">
 	<button class="btn btn-onelab" type="button" id="portal__validate" onclick="on_click_event();"><span class="glyphicon glyphicon-ok"></span> Validate</button>