Slice request: select a project under an authority
[unfold.git] / portal / templates / fed4fire / fed4fire_slicerequest_view.html
1 {% extends "layout.html" %}
2 {% load i18n %}
3
4 {% block content %}
5         <div class="row">
6                 <div class="col-md-12">
7                          <div class="breadcrumbs" style="line-height: 3;">
8                                  Experiment &nbsp;>&nbsp; Request a new Slice
9                          </div>
10                 </div>
11         </div>
12
13         {% if errors %}
14         <div class="row">
15                 <div class="col-md-12">
16                 <ul class="error">
17                   {% for error in errors %}
18                   <li>{{ error }}</li>
19                   {% endfor %}
20                 </ul>
21                 </div>
22         </div>
23         {% endif %}
24         
25         <div class="row">
26                 <div class="col-md-8 el">
27                         <form role="form" method="post">
28                         {% csrf_token %}
29                           <div class="form-group" style="display:none">
30                             <input type="email" class="form-control" id="email" style="width:300px" value="{{ email }}" readonly="readonly">
31                           </div>
32                           <div class="form-group">
33                             <input type="text" class="form-control" name="slice_name" id="slice_name" style="width:300px" placeholder="Slice name" value="{{slice_name}}" 
34                                 title="Please enter a name for your slice"required="required">
35                           </div>
36                           <div class="form-group">
37                                 {% if pi %}
38                                 <input type="text" class="form-control" id="authority_hrn" name="org_name" style="width:300px" placeholder="Organization" 
39                                 title="An authority responsible for vetting your slice" required="required">
40                                 {% else %}
41                             <input type="text" class="form-control" id="authority_hrn" name="org_name" placeholder="Organization" style="width:300px;" 
42                                 title="An authority responsible for vetting your slice" required="required" readonly>
43                                 {% endif %}
44                           </div>
45                           <div class="form-group">
46                 Project: 
47                 <select id="projects">
48                     <option>project A</option>
49                 </select>
50               </div>
51                           <div class="form-group">
52                             <input type="text" class="form-control" name="url" id="url" style="width:300px" placeholder="Experiment URL (if one exists)"
53                                 title="Please provide the url of your experiment if you have one." value="{{url}}">
54                           </div>
55                           <div class="form-group">
56                                 <textarea id="purpose" name="purpose" class="form-control" rows="6" placeholder="Experiment purpose" style="width:300px" 
57                                 title="Purpose of your experiment (informative)" required="required">{{ purpose }}</textarea>
58                           </div>
59                           {% if pi %}   
60                           <button type="submit" id=submit_pi class="btn btn-onelab"><span class="glyphicon glyphicon-plus"></span> Create slice</button>
61                           {% else %}
62                           <button type="submit" class="btn btn-onelab"><span class="glyphicon glyphicon-plus"></span> Request slice</button>
63                           {% endif %}   
64                         </form>
65         
66                 </div>
67         </div>
68                 
69 <script>
70 jQuery(document).ready(function(){
71         
72         $("#authority_hrn").load("/rest/user/", {"fields" : ["parent_authority"], "filters": {"user_hrn": "{{ user_hrn }}"}}, function(data) {
73                 var jsonData = JSON.parse(data);
74         $(this).attr("value", jsonData[0]['parent_authority']);
75         draw_projects(jsonData[0]['parent_authority']);
76     });
77         $("#authority_hrn").val("{{authority_name}}");
78         var availableTags = [
79     {% if authorities %}
80         {% for authority in authorities %}
81             {% if authority.name %}
82                 {value:"{{ authority.name }}",label:"{{authority.name}}"},
83                         // to show only full name
84             {% else %}
85                 {value:"{{ authority.authority_hrn }}",label:"{{authority.authority_hrn}}"},
86             {% endif %}
87         {% endfor %}    
88     {% else %}
89         {value:"",label:"No authority found !!!"}
90     {% endif %}
91     ];
92         // sorting the list
93         availableTags.sort(function(a,b){
94                 var nameA=a.value.toLowerCase(), nameB=b.value.toLowerCase();
95                 if (nameA < nameB) {
96                 return -1;
97                 }
98                 if (nameA > nameB) {
99                 return 1;
100                 }
101         return 0;
102         }); 
103     $( "#authority_hrn" ).autocomplete({
104       source: availableTags,
105       minLength: 0,
106       select: function( event, ui ) {
107         draw_projects(jQuery('.ui-state-focus').html());
108       },
109     });
110
111 });
112
113 function draw_projects(authority_hrn){
114     $.post("/rest/myslice:authority/",{'fields':['authority_hrn','pi_users'],'filters':{'authority_hrn':'CONTAINS'+authority_hrn}}, function( data ) {
115        
116         var projects = [];
117         project_row = "<option value=''> - </option>";
118         projects.push(project_row);
119        
120         $.each( data, function( key, val ) {
121             console.log(val);
122             project_row = "<option value='"+val.authority_hrn+"'>"+val.authority_hrn+"</option>";
123             projects.push(project_row);
124         });
125         $("#projects").html(projects.join( "" ));
126     });
127 }
128 </script>
129 {% endblock %}
130