Create project, user authority pre-selected
[unfold.git] / portal / templates / fed4fire / fed4fire_projectrequest_view.html
index a4c433b..d002152 100644 (file)
@@ -2,6 +2,10 @@
 {% load i18n %}
 
 {% block content %}
+<script src="{{ STATIC_URL }}js/jquery-ui.js"></script>
+<script src="{{ STATIC_URL }}js/jquery-ui-combobox.js"></script>
+<link rel='stylesheet' type='text/css' href="{{ STATIC_URL }}css/jquery-ui.css">
+<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/jquery.ui.combobox.css">
 <br />
 <div class="row">
     <div class="col-md-12">
         </div>
         <div class="row">
             <div class="col-md-6">
-                <form role="form" method="post">
+                <form role="form" method="post" action="/portal/project_request">
                 {% csrf_token %}
-                <select id="projects"></select> <button type="submit" class="btn">Join</button>
+                <div id="project_loading" style="display:inline;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading projects" /></div> 
+                <select id="projects" name="project_name" style="display:none;"></select> <div style="display:none;" id="projects_button"><input type="submit" id="join" name="join" value="Join" class="btn"/></div>
                 </form>
             </div>
             <div class="col-md-6">
                     {% for pending in pending_projects %}
                     <tr><td>(PENDING) {{ pending.project_name }}</td><td>{{ pending.authority_hrn }}</td><td>{{ pending.created|date:"d/m/Y" }}</td></tr>
                     {% endfor %}
+                    {% for pending in pending_join_projects %}
+                    <tr><td>(PENDING JOIN) {{ pending.project_name }}</td><td>&nbsp;</td><td>{{ pending.created|date:"d/m/Y" }}</td></tr>
+                    {% endfor %}
+
                 </table>
             </div>
         </div>
                 <form role="form" method="post" action="/portal/project_request">
                 {% csrf_token %}
                   <div class="form-group">
-                    <input type="text" name="project_name" value="" placeholder="Name" required>
+                    <input type="text" name="project_name" value="" style="width:380px;" placeholder="Name" required>
                   </div>
                   <div class="form-group">
-                    <select id="org_name" name="authority_name" class="form-control" style="width:590px" value="{{ organization }}" required> 
+                    <select id="org_name" name="authority_name" class="form-control" style="width:380px" value="{{ organization }}" required> 
                     {% if authorities %}
                         {% for authority in authorities %}
                             {% if authority.name %}
-                                <option value="{{ authority.authority_hrn }}">{{authority.name}}</option>
+                                <option value="{{ authority.authority_hrn }}" {% if authority.authority_hrn == authority_hrn %}selected{% endif %}>{{authority.name}}</option>
                             {% else %}
-                                <option value="{{ authority.authority_hrn }}">{{authority.authority_hrn}}</option>
+                                <option value="{{ authority.authority_hrn }}" {% if authority.authority_hrn == authority_hrn %}selected{% endif %}>{{authority.authority_hrn}}</option>
                             {% endif %}
                         {% endfor %} 
                     {% endif %}
@@ -84,7 +93,7 @@
                   
                   
                   <div class="form-group">
-                    <textarea id="purpose" name="purpose" class="form-control" rows="6" placeholder="Description" style="width:300px" title="Purpose of your project (informative)" required="required"></textarea>
+                    <textarea id="purpose" name="purpose" class="form-control" rows="6" placeholder="Description" style="width:380px" title="Purpose of your project (informative)" required="required"></textarea>
                   </div>
                   <button type="submit" class="btn btn-onelab"><span class="glyphicon glyphicon-plus"></span> Send Request</button>
                 </form>
                
 <script>
 $(document).ready(function() {
-    var myprojects = localStorage.getItem('projects');
+    var myprojects = JSON.parse(localStorage.getItem('projects'));
     console.log(myprojects);
     if (myprojects) {
-        
+        $.each(myprojects, function (i, val){
+            console.log(val);
+            $('.project-list').append('<tr><td>'+ val +'</td></tr>');
+        });
     } else {
         $('.project-list').html('<tr><td>no projetcs</td></tr>');
     }
@@ -109,18 +121,26 @@ $(document).ready(function() {
         e.preventDefault();
         $(this).tab('show');
     });
-    $.post("/rest/myslice:authority/",{'fields':['authority_hrn','pi_users'],'filters':{'authority_hrn':'CONTAINS{{ authority_hrn }}' }}, function( data ) {
+    $.post("/rest/myslice:authority/",{'fields':['authority_hrn','pi_users'],'filters':{'authority_hrn':'CONTAINS{{ root_authority_hrn }}' }}, function( data ) {
        
         var projects = [];
         project_row = "<option value=''> - </option>";
         projects.push(project_row);
        
         $.each( data, function( key, val ) {
-            console.log(val);
-            project_row = "<option value='"+val.authority_hrn+"'>"+val.authority_hrn+"</option>";
-            projects.push(project_row);
+            if(val.authority_hrn.split('.').length > 2){
+                if($.inArray(val.authority_hrn, myprojects)==-1){
+                project_row = "<option value='"+val.authority_hrn+"'>"+val.authority_hrn+"</option>";
+                projects.push(project_row);
+                }
+            }
         });
+        $("#projects").show();
+        $("#projects_button").css('margin-left', '50px');
+        $("#projects_button").css('display', 'inline-block');
+        $("#project_loading").hide();
         $("#projects").html(projects.join( "" ));
+        $("#projects").combobox();
     });
 /*
        
@@ -164,7 +184,7 @@ $(document).ready(function() {
                localStorage.clear();
        });
        // auto-complete the form
-    //jQuery("#org_name").combobox();
+    jQuery("#org_name").combobox();
 
 });
 </script>