d0021525ec895ad913f3fcae96ad01cf766412ed
[unfold.git] / portal / templates / fed4fire / fed4fire_projectrequest_view.html
1 {% extends "layout.html" %}
2 {% load i18n %}
3
4 {% block content %}
5 <script src="{{ STATIC_URL }}js/jquery-ui.js"></script>
6 <script src="{{ STATIC_URL }}js/jquery-ui-combobox.js"></script>
7 <link rel='stylesheet' type='text/css' href="{{ STATIC_URL }}css/jquery-ui.css">
8 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/jquery.ui.combobox.css">
9 <br />
10 <div class="row">
11     <div class="col-md-12">
12         <ul class="nav nav-tabs nav-section">
13             <li class="active"><a href="#existing">Join existing Project</a></li>
14             <li><a href="#new">Create new Project</a></li>
15             
16         </ul>
17     </div>
18 </div>
19
20 {% if errors %}
21 <div class="row">
22     <div class="col-md-12">
23     <ul class="error">
24       {% for error in errors %}
25       <li>{{ error }}</li>
26       {% endfor %}
27     </ul>
28     </div>
29 </div>
30 {% endif %}
31
32 <div class="container tab-content">
33     
34         <div class="tab-pane active" id="existing"> 
35         <div class="row">
36             <div class="col-md-6">
37                  <h3>Join an existing Project</h3>
38             </div>
39             <div class="col-md-6">
40                  <h3>List of projects you are part of</h3>
41             </div>
42         </div>
43         <div class="row">
44             <div class="col-md-6">
45                 <form role="form" method="post" action="/portal/project_request">
46                 {% csrf_token %}
47                 <div id="project_loading" style="display:inline;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading projects" /></div> 
48                 <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>
49                 </form>
50             </div>
51             <div class="col-md-6">
52                 <table class="table project-list">
53                     {% for pending in pending_projects %}
54                     <tr><td>(PENDING) {{ pending.project_name }}</td><td>{{ pending.authority_hrn }}</td><td>{{ pending.created|date:"d/m/Y" }}</td></tr>
55                     {% endfor %}
56                     {% for pending in pending_join_projects %}
57                     <tr><td>(PENDING JOIN) {{ pending.project_name }}</td><td>&nbsp;</td><td>{{ pending.created|date:"d/m/Y" }}</td></tr>
58                     {% endfor %}
59
60                 </table>
61             </div>
62         </div>
63     </div>
64     
65     <div class="tab-pane" id="new"> 
66         <div class="row">
67             <div class="col-md-12">
68                  <h3>Create a new Project</h3>
69             </div>
70         </div>
71     
72         
73         <div class="row">
74             <div class="col-md-12">
75                 <form role="form" method="post" action="/portal/project_request">
76                 {% csrf_token %}
77                   <div class="form-group">
78                     <input type="text" name="project_name" value="" style="width:380px;" placeholder="Name" required>
79                   </div>
80                   <div class="form-group">
81                     <select id="org_name" name="authority_name" class="form-control" style="width:380px" value="{{ organization }}" required> 
82                     {% if authorities %}
83                         {% for authority in authorities %}
84                             {% if authority.name %}
85                                 <option value="{{ authority.authority_hrn }}" {% if authority.authority_hrn == authority_hrn %}selected{% endif %}>{{authority.name}}</option>
86                             {% else %}
87                                 <option value="{{ authority.authority_hrn }}" {% if authority.authority_hrn == authority_hrn %}selected{% endif %}>{{authority.authority_hrn}}</option>
88                             {% endif %}
89                         {% endfor %} 
90                     {% endif %}
91                     </select>
92                   </div>
93                   
94                   
95                   <div class="form-group">
96                     <textarea id="purpose" name="purpose" class="form-control" rows="6" placeholder="Description" style="width:380px" title="Purpose of your project (informative)" required="required"></textarea>
97                   </div>
98                   <button type="submit" class="btn btn-onelab"><span class="glyphicon glyphicon-plus"></span> Send Request</button>
99                 </form>
100         
101             </div>
102         </div>
103     </div>
104     
105 </div>
106                 
107 <script>
108 $(document).ready(function() {
109     var myprojects = JSON.parse(localStorage.getItem('projects'));
110     console.log(myprojects);
111     if (myprojects) {
112         $.each(myprojects, function (i, val){
113             console.log(val);
114             $('.project-list').append('<tr><td>'+ val +'</td></tr>');
115         });
116     } else {
117         $('.project-list').html('<tr><td>no projetcs</td></tr>');
118     }
119     
120     $('.nav-tabs a').click(function (e) {
121         e.preventDefault();
122         $(this).tab('show');
123     });
124     $.post("/rest/myslice:authority/",{'fields':['authority_hrn','pi_users'],'filters':{'authority_hrn':'CONTAINS{{ root_authority_hrn }}' }}, function( data ) {
125        
126         var projects = [];
127         project_row = "<option value=''> - </option>";
128         projects.push(project_row);
129        
130         $.each( data, function( key, val ) {
131             if(val.authority_hrn.split('.').length > 2){
132                 if($.inArray(val.authority_hrn, myprojects)==-1){
133                 project_row = "<option value='"+val.authority_hrn+"'>"+val.authority_hrn+"</option>";
134                 projects.push(project_row);
135                 }
136             }
137         });
138         $("#projects").show();
139         $("#projects_button").css('margin-left', '50px');
140         $("#projects_button").css('display', 'inline-block');
141         $("#project_loading").hide();
142         $("#projects").html(projects.join( "" ));
143         $("#projects").combobox();
144     });
145 /*
146         
147         $("#authority_hrn").load("/rest/user/", {"fields" : ["parent_authority"], "filters": {"user_hrn": "{{ user_hrn }}"}}, function(data) {
148                 var jsonData = JSON.parse(data);
149         $(this).attr("value", jsonData[0]['parent_authority']);
150     });
151         $("#authority_hrn").val("{{authority_name}}");
152         var availableTags = [
153     {% if authorities %}
154         {% for authority in authorities %}
155             {% if authority.name %}
156                 {value:"{{ authority.name }}",label:"{{authority.name}}"},
157                         // to show only full name
158             {% else %}
159                 {value:"{{ authority.authority_hrn }}",label:"{{authority.authority_hrn}}"},
160             {% endif %}
161         {% endfor %}    
162     {% else %}
163         {value:"",label:"No authority found !!!"}
164     {% endif %}
165     ];
166         // sorting the list
167         availableTags.sort(function(a,b){
168                 var nameA=a.value.toLowerCase(), nameB=b.value.toLowerCase();
169                 if (nameA < nameB) {
170                 return -1;
171                 }
172                 if (nameA > nameB) {
173                 return 1;
174                 }
175         return 0;
176         }); 
177     $( "#authority_hrn" ).autocomplete({
178       source: availableTags,
179       minLength: 0,
180       select: function( event, ui ) {console.log(jQuery(this));}
181     });
182 */
183         $("#submit_pi").click(function() {
184                 localStorage.clear();
185         });
186         // auto-complete the form
187     jQuery("#org_name").combobox();
188
189 });
190 </script>
191 {% endblock %}
192