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