7bcd56dec7e79ac778df0cf9f15d6d32ac286745
[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="hidden" 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                 <span style="float:left;">Authority: &nbsp;</span>
44                 <div id="authority_display">
45                 <img src="{{ STATIC_URL }}img/loading.gif" alt="Loading authority" />
46                 </div>
47                                 {% endif %}
48                           </div>
49                           <div class="form-group">
50                 Project: <div id="project_loading" style="display:inline;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading projects" /></div> 
51                 <select id="project" name="project" style="display:none;">
52                 </select>
53               </div>
54                           <div class="form-group">
55                             <input type="text" class="form-control" name="url" id="url" style="width:300px" placeholder="Experiment URL (if one exists)"
56                                 title="Please provide the url of your experiment if you have one." value="{{url}}">
57                           </div>
58                           <div class="form-group">
59                                 <textarea id="purpose" name="purpose" class="form-control" rows="6" placeholder="Experiment purpose" style="width:300px" 
60                                 title="Purpose of your experiment (informative)" required="required">{{ purpose }}</textarea>
61                           </div>
62                           {% if pi %}   
63                           <button type="submit" id=submit_pi class="btn btn-onelab"><span class="glyphicon glyphicon-plus"></span> Create slice</button>
64                           {% else %}
65                           <button type="submit" class="btn btn-onelab"><span class="glyphicon glyphicon-plus"></span> Request slice</button>
66                           {% endif %}   
67                         </form>
68         
69                 </div>
70         </div>
71                 
72 <script>
73 jQuery(document).ready(function(){
74         
75         $("#authority_hrn").load("/rest/user/", {"fields" : ["parent_authority"], "filters": {"user_hrn": "{{ user_hrn }}"}}, function(data) {
76                 var jsonData = JSON.parse(data);
77         $(this).attr("value", jsonData[0]['parent_authority']);
78             {% if pi %}
79         draw_projects(jsonData[0]['parent_authority']);
80         {% else %}
81         $('#authority_display').html(jsonData[0]['parent_authority']);
82         draw_projects('');
83         {% endif %}
84     });
85
86         {% if pi %}
87         $("#authority_hrn").val("{{authority_name}}");
88         var availableTags = [
89     {% if authorities %}
90         {% for authority in authorities %}
91             {% if authority.name %}
92                 {value:"{{ authority.name }}",label:"{{authority.name}}"},
93                         // to show only full name
94             {% else %}
95                 {value:"{{ authority.authority_hrn }}",label:"{{authority.authority_hrn}}"},
96             {% endif %}
97         {% endfor %}    
98     {% else %}
99         {value:"",label:"No authority found !!!"}
100     {% endif %}
101     ];
102         // sorting the list
103         availableTags.sort(function(a,b){
104                 var nameA=a.value.toLowerCase(), nameB=b.value.toLowerCase();
105                 if (nameA < nameB) {
106                 return -1;
107                 }
108                 if (nameA > nameB) {
109                 return 1;
110                 }
111         return 0;
112         }); 
113     $( "#authority_hrn" ).autocomplete({
114       source: availableTags,
115       minLength: 0,
116       select: function( event, ui ) {
117         $("#project").hide();
118         $("#project_loading").css('display', 'inline-block');
119         draw_projects(jQuery('.ui-state-focus').html());
120       },
121     });
122     {% endif %}
123 });
124
125 function draw_projects(authority_hrn){
126
127     var projects = [];
128     project_row = "<option value=''> - </option>";
129     projects.push(project_row);
130
131     if(authority_hrn.length > 0){
132         // Not for root authority
133         if(authority_hrn.split('.').length > 1){
134             $.post("/rest/myslice:authority/",{'fields':['authority_hrn','pi_users'],'filters':{'authority_hrn':'CONTAINS'+authority_hrn}}, function( data ) {
135                
136                 $.each( data, function( key, val ) {
137                     project_row = "<option value='"+val.authority_hrn+"'>"+val.authority_hrn+"</option>";
138                     projects.push(project_row);
139                 });
140                 $("#project").html(projects.join( "" ));
141             });
142         }else{
143             $("#project").html(projects.join( "" ));
144         }
145     }else{
146         my_projects = JSON.parse(localStorage.getItem('projects'));
147         $.each( my_projects, function( i, val ) {
148             project_row = "<option value='"+val+"'>"+val+"</option>";
149             projects.push(project_row);
150         });
151         $("#project").html(projects.join( "" ));
152     }
153     $("#project").show();
154     $("#project_loading").hide();
155 }
156 </script>
157 {% endblock %}
158