Projects: Join project resquests
authorLoic Baron <loic.baron@lip6.fr>
Wed, 28 Jan 2015 17:50:05 +0000 (18:50 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Wed, 28 Jan 2015 17:50:05 +0000 (18:50 +0100)
myslice/settings.py
portal/actions.py
portal/models.py
portal/projectrequestview.py
portal/templates/base.html
portal/templates/fed4fire/fed4fire_account-view.html
portal/templates/fed4fire/fed4fire_home-view.html
portal/templates/fed4fire/fed4fire_projectrequest_view.html
portal/templates/fed4fire/fed4fire_slicerequest_view.html
portal/templates/management-tab-requests.html

index 3b1f1f3..bd1474b 100644 (file)
@@ -47,7 +47,7 @@ except:
 # assume we have ./static present already
 HTTPROOT="/var/myslice-f4f"
 # the place to store local data, like e.g. the sqlite db
-DATAROOT="/Users/moray/Sites/upmc/myslice"
+DATAROOT="/var/unfold"
 # if not there, then we assume it's from a devel tree
 if not os.path.isdir (os.path.join(HTTPROOT,"static")):
     HTTPROOT=ROOT
index 05abf0b..fa3ed10 100644 (file)
@@ -1,7 +1,7 @@
 from django.http                    import HttpResponse
 from manifold.core.query            import Query
 from manifoldapi.manifoldapi        import execute_query,execute_admin_query
-from portal.models                  import PendingUser, PendingSlice, PendingAuthority, PendingProject
+from portal.models                  import PendingUser, PendingSlice, PendingAuthority, PendingProject, PendingJoin
 from unfold.page                    import Page
 
 import json
@@ -28,11 +28,16 @@ import activity.slice
 
 # Get the list of pis in a given authority
 def authority_get_pis(request, authority_hrn):
+    # CACHE PB with fields
+    page = Page(request)
+    metadata = page.get_metadata()
+    auth_md = metadata.details_by_object('authority')
+    auth_fields = [column['name'] for column in auth_md['column']]
 
     # REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
-    query = Query.get('myslice:authority').filter_by('authority_hrn', '==', authority_hrn).select('pi_users')
+    query = Query.get('myslice:authority').filter_by('authority_hrn', '==', authority_hrn).select(auth_fields)
     results = execute_admin_query(request, query)
-    print "authority_get_pis = %s" % results
+    #print "authority_get_pis = %s" % results
     # NOTE: temporarily commented. Because results is giving empty list. 
     # Needs more debugging
     #if not results:
@@ -89,7 +94,7 @@ def authority_add_pis(request, authority_hrn,user_hrn):
             pi_list = pi['pi_users']
    
         updated_pi_list = pi_list.append(user_hrn) 
-        query = Query.update('authority').filter_by('authority_hrn', '==', authority_hrn).set({'pi_users':pi_list})
+        query = Query.update('myslice:authority').filter_by('authority_hrn', '==', authority_hrn).set({'pi_users':pi_list})
         results = execute_query(request,query)
         newpis = authority_get_pis (request, authority_hrn)
         return newpis
@@ -197,12 +202,12 @@ def is_pi(wsgi_request, user_hrn, authority_hrn):
     
 # SFA get record
 
-def sfa_get_user(request, user_hrn, pub):
+def sfa_get_user(request, user_hrn, pub=None):
 
     # REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
     query_sfa_user = Query.get('myslice:user').filter_by('user_hrn', '==', user_hrn)
     result_sfa_user = execute_admin_query(request, query_sfa_user)
-    return result_sfa_user                        
+    return result_sfa_user[0]                        
 
 def sfa_update_user(request, user_hrn, user_params):
     # user_params: keys [public_key] 
@@ -217,7 +222,7 @@ def sfa_update_user(request, user_hrn, user_params):
 def sfa_add_authority(request, authority_params):
 
     # REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
-    query = Query.create('authority').set(authority_params).select('authority_hrn')
+    query = Query.create('myslice:authority').set(authority_params).select('authority_hrn')
     results = execute_query(request, query)
     print "sfa_add_auth results=",results
     if not results:
@@ -352,13 +357,26 @@ def make_request_slice(slice):
 def make_request_project(project):
     request = {}
     request['type'] = 'project'
+    request['id'] = project.id
     request['user_hrn'] = project.user_hrn
+    request['email'] = project.email
     request['timestamp'] = project.created
     request['authority_hrn'] = project.authority_hrn
     request['project_name'] = project.project_name
     request['purpose'] = project.purpose
     return request
 
+def make_request_join(join):
+    request = {}
+    request['type'] = 'join'
+    request['id'] = join.id
+    request['user_hrn'] = join.user_hrn
+    request['email'] = join.email
+    request['timestamp'] = join.created
+    request['authority_hrn'] = join.authority_hrn
+    request['project_name'] = join.project_name
+    return request
+
 def make_request_authority(authority):
     request = {}
     request['type']                  = 'authority'
@@ -380,7 +398,8 @@ def make_request_authority(authority):
     request['timestamp']             = authority.created
     return request
 
-def make_requests(pending_users, pending_slices, pending_authorities, pending_projects):
+def make_requests(pending_users, pending_slices, pending_authorities, pending_projects, pending_joins):
+    print "$$$$$$$$$$$$$$$  make_request"
     requests = []
     for user in pending_users:
         requests.append(make_request_user(user))
@@ -390,10 +409,13 @@ def make_requests(pending_users, pending_slices, pending_authorities, pending_pr
         requests.append(make_request_authority(authority))
     for project in pending_projects:
         requests.append(make_request_project(project))
+    for join in pending_joins:
+        requests.append(make_request_join(join))
     return requests   
 
 def get_request_by_id(ids):
-    sorted_ids = { 'user': [], 'slice': [], 'authority': [] }
+    print "$$$$$$$$$$$$$$$$  get_request_by_id"
+    sorted_ids = { 'user': [], 'slice': [], 'authority': [], 'project': [], 'join': [] }
     for type__id in ids:
         type, id = type__id.split('__')
         sorted_ids[type].append(id)
@@ -402,44 +424,53 @@ def get_request_by_id(ids):
         pending_users  = PendingUser.objects.all()
         pending_slices = PendingSlice.objects.all()
         pending_authorities = PendingAuthority.objects.all()
+        pending_projects = PendingProject.objects.all()
+        pending_joins = PendingJoin.objects.all()
     else:
         pending_users  = PendingUser.objects.filter(id__in=sorted_ids['user']).all()
         pending_slices = PendingSlice.objects.filter(id__in=sorted_ids['slice']).all()
         pending_authorities = PendingAuthority.objects.filter(id__in=sorted_ids['authority']).all()
+        pending_projects = PendingProject.objects.filter(id__in=sorted_ids['project']).all()
+        pending_joins = PendingJoin.objects.filter(id__in=sorted_ids['join']).all()
 
-    return make_requests(pending_users, pending_slices, pending_authorities)
+    return make_requests(pending_users, pending_slices, pending_authorities, pending_projects, pending_joins)
 
 def get_requests(authority_hrns=None):
-    print "get_request_by_authority auth_hrns = ", authority_hrns
+    print "$$$$$$$$$$$$$   get_request_by_authority auth_hrns = ", authority_hrns
     if not authority_hrns:
         ## get those pending users who have confirmed their emails
         pending_users  = PendingUser.objects.filter(status__iexact = 'True')
         pending_slices = PendingSlice.objects.all()
         pending_authorities = PendingAuthority.objects.all()
         pending_projects = PendingProject.objects.all()
+        pending_joins = PendingJoin.objects.all()
     else:
         pending_users  = PendingUser.objects
         pending_slices = PendingSlice.objects
         pending_authorities = PendingAuthority.objects
         pending_projects = PendingProject.objects
+        pending_joins = PendingJoin.objects
         from django.db.models import Q
         list_user_Q = list()
         list_slice_Q = list()
         list_auth_Q = list()
         list_proj_Q = list()
+        list_join_Q = list()
         for hrn in authority_hrns:
             list_user_Q.append(Q(authority_hrn__startswith=hrn, status__iexact = 'True'))
             list_slice_Q.append(Q(authority_hrn__startswith=hrn))
             list_auth_Q.append(Q(site_authority__startswith=hrn))
             list_proj_Q.append(Q(authority_hrn__startswith=hrn))
+            list_join_Q.append(Q(authority_hrn__startswith=hrn))
         from operator import __or__ as OR
         pending_users        = pending_users.filter(reduce(OR, list_user_Q))
         pending_slices       = pending_slices.filter(reduce(OR, list_slice_Q))
         pending_authorities  = pending_authorities.filter(reduce(OR, list_auth_Q))
         pending_projects     = pending_projects.filter(reduce(OR, list_proj_Q))
+        pending_joins        = pending_joins.filter(reduce(OR, list_join_Q))
         #pending_authorities  = pending_authorities.all() #filter(reduce(OR, list_Q))
 
-    return make_requests(pending_users, pending_slices, pending_authorities, pending_projects)
+    return make_requests(pending_users, pending_slices, pending_authorities, pending_projects, pending_joins)
 
 # XXX Is it in sync with the form fields ?
 
@@ -489,6 +520,10 @@ def portal_validate_request(wsgi_request, request_ids):
                 request_status['SFA slice'] = {'status': True }
                 PendingSlice.objects.get(id=request['id']).delete()
 
+                # Clear user's Credentials
+                sfa_user = sfa_get_user(wsgi_request, request['user_hrn'])
+                clear_user_creds(wsgi_request,sfa_user['user_email'])
+
             except Exception, e:
                 request_status['SFA slice'] = {'status': False, 'description': str(e)}
 
@@ -516,6 +551,43 @@ def portal_validate_request(wsgi_request, request_ids):
             except Exception, e:
                 request_status['SFA authority'] = {'status': False, 'description': str(e)}
 
+        elif request['type'] == 'project':
+            try:
+                hrn = request['authority_hrn'] + '.' + request['project_name']
+
+                # Only hrn is required for Manifold Query 
+                sfa_authority_params = {
+                    'authority_hrn'        : hrn
+                }
+                sfa_add_authority(wsgi_request, sfa_authority_params)
+                request_status['SFA project'] = {'status': True }
+                PendingProject.objects.get(id=request['id']).delete()
+                
+                # Add user as a PI of the project
+                authority_add_pis(wsgi_request, hrn , request['user_hrn'])
+
+                # Clear user's Credentials
+                #sfa_user = sfa_get_user(wsgi_request, request['user_hrn'])
+                clear_user_creds(wsgi_request,request['email'])
+
+            except Exception, e:
+                request_status['SFA project'] = {'status': False, 'description': str(e)}
+
+        elif request['type'] == 'join':
+            try:
+                # Add user as a PI of the project
+                authority_add_pis(wsgi_request, request['authority_hrn'] , request['user_hrn'])
+
+                request_status['SFA join'] = {'status': True }
+                PendingJoin.objects.get(id=request['id']).delete()
+
+                # Clear user's Credentials
+                clear_user_creds(wsgi_request,request['email'])
+
+            except Exception, e:
+                request_status['SFA join'] = {'status': False, 'description': str(e)+' - '+str(request)}
+        else:
+            request_status['other'] = {'status': False, 'description': 'unknown type of request'}
         # XXX Remove from Pendings in database
 
         status['%s__%s' % (request['type'], request['id'])] = request_status
@@ -689,6 +761,15 @@ def portal_reject_request(wsgi_request, request_ids):
 
             PendingAuthority.objects.get(id=request['id']).delete()
 
+        # XXX TMP we should send an email to the user to inform him/her
+        elif request['type'] == 'project':
+            request_status['SFA project'] = {'status': True }
+            PendingProject.objects.get(id=request['id']).delete()
+
+        elif request['type'] == 'join':
+            request_status['SFA join'] = {'status': True }
+            PendingJoin.objects.get(id=request['id']).delete()
+
         status['%s__%s' % (request['type'], request['id'])] = request_status
 
     return status
@@ -824,11 +905,26 @@ def create_pending_project(wsgi_request, request):
     s = PendingProject(
         project_name    = request['project_name'],
         user_hrn        = request['user_hrn'],
+        email           = request['email'],
         authority_hrn   = request['authority_hrn'],
         purpose         = request['purpose'],
     )
     s.save()
 
+def create_pending_join(wsgi_request, request):
+    """
+    """
+
+    # Insert an entry in the PendingJoin table
+    s = PendingJoin(
+        user_hrn        = request['user_hrn'],
+        email           = request['email'],
+        project_name    = request['project_name'],
+        authority_hrn   = request['authority_hrn'],
+    )
+    s.save()
+
+
 #     try:
 #         # Send an email: the recipients are the PI of the authority
 #         recipients = authority_get_pi_emails(wsgi_request, request['authority_hrn'])
index 6670c4c..f578d93 100644 (file)
@@ -100,6 +100,14 @@ class PendingSlice(models.Model):
 class PendingProject(models.Model):
     project_name    = models.TextField()
     user_hrn        = models.TextField()
+    email           = models.TextField()
     authority_hrn   = models.TextField(null=True)
     purpose         = models.TextField(default='NA')
     created         = models.DateTimeField(auto_now_add = True)
+
+class PendingJoin(models.Model):
+    user_hrn        = models.TextField()
+    email           = models.TextField()
+    project_name    = models.TextField(null=True)
+    authority_hrn   = models.TextField()
+    created         = models.DateTimeField(auto_now_add = True)
index 70f4994..aaa79b2 100644 (file)
@@ -6,9 +6,8 @@ from manifoldapi.manifoldapi    import execute_admin_query, execute_query
 
 from unfold.loginrequired       import LoginRequiredAutoLogoutView
 
-from portal.actions import create_pending_project
-
-from portal.models import PendingProject
+from portal.actions import create_pending_project, create_pending_join, sfa_add_authority, authority_add_pis, is_pi
+from portal.models import PendingProject, PendingJoin
 
 from myslice.theme import ThemeView
 
@@ -53,6 +52,13 @@ class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
                         account_config = json.loads(account_detail['config'])
                         user_hrn = account_config.get('user_hrn','N/A')
         return user_hrn        
+
+    def getUserEmail(self, request):
+        # Get user_email (XXX Would deserve to be simplified)
+        user_query  = Query().get('local:user').select('email','config')
+        user_details = execute_query(request, user_query)
+        user_email = user_details[0].get('email')
+        return user_email
                    
     def post(self, request):
         return self.handle_request(request, 'POST')
@@ -65,7 +71,11 @@ class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
         authority_hrn = None
         authority_name = None
         
+        #errors.append(wsgi_request.POST)
+
         user_hrn = self.getUserHrn(wsgi_request)
+
+        user_email = self.getUserEmail(wsgi_request)
         
         authorities = self.getAuthorities(wsgi_request)
         
@@ -77,51 +87,71 @@ class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
                 authority_name = authority['name']
         
         if method == 'POST' :
-           
-            post = {
-                'user_hrn'          : user_hrn,
-                'authority_hrn'     : wsgi_request.POST.get('authority_name', ''),
-                'project_name'      : wsgi_request.POST.get('project_name', ''),
-                'purpose'           : wsgi_request.POST.get('purpose', ''),
-            }
         
-#             # create slice_hrn based on authority_hrn and slice_name
-#             #             slice_name = slice_request['slice_name']
-#             req_slice_hrn = authority_hrn + '.' + slice_name
-#             # comparing requested slice_hrn with the existing slice_hrn 
-#             slice_query  = Query().get('myslice:slice').select('slice_hrn','parent_authority').filter_by('parent_authority','==',authority_hrn)
-#             slice_details_sfa = execute_admin_query(wsgi_request, slice_query)
-#             for _slice in slice_details_sfa:
-#                 if _slice['slice_hrn'] == req_slice_hrn:
-#                     errors.append('Slice already exists. Please use a different slice name.')
-            
+            if 'join' in wsgi_request.POST:
+                post = {
+                    'user_hrn'          : user_hrn,
+                    'email'             : user_email,
+                    'project_name'      : wsgi_request.POST.get('project_name', ''),
+                    'authority_hrn'     : wsgi_request.POST.get('project_name', ''),
+                }
 
-            # What kind of slice name is valid?
+            else:
+                post = {
+                    'user_hrn'          : user_hrn,
+                    'email'             : user_email,
+                    'authority_hrn'     : wsgi_request.POST.get('authority_name', ''),
+                    'project_name'      : wsgi_request.POST.get('project_name', ''),
+                    'purpose'           : wsgi_request.POST.get('purpose', ''),
+                }
+
+                if (post['authority_hrn'] is None or post['authority_hrn'] == ''):
+                    errors.append('Organization is mandatory')
+    
+                if (post['purpose'] is None or post['purpose'] == ''):
+                    errors.append('Experiment purpose is mandatory')
+
+                if (re.search(r'^[A-Za-z0-9_]*$', post['project_name']) == None):
+                    errors.append('Project name may contain only letters, numbers, and underscore.')
+
+            # What kind of project name is valid?
             if (post['project_name'] is None or post['project_name'] == ''):
                 errors.append('Project name is mandatory')
             
-            if (re.search(r'^[A-Za-z0-9_]*$', post['project_name']) == None):
-                errors.append('Project name may contain only letters, numbers, and underscore.')
-            
-            if (post['authority_hrn'] is None or post['authority_hrn'] == ''):
-                errors.append('Organization is mandatory')
-    
-            if (post['purpose'] is None or post['purpose'] == ''):
-                errors.append('Experiment purpose is mandatory')
-
             if not errors:
-                create_pending_project(wsgi_request, post)
-        
-        # retrieves the pending projects list
+                print "is_pi on auth_hrn = ", user_authority
+                if is_pi(wsgi_request, user_hrn, user_authority):
+                    # PIs can directly create/join project in their own authority...
+                    if 'join' in wsgi_request.POST:
+                        authority_add_pis(wsgi_request, post['project_name'], user_hrn)
+                    else:
+                        hrn = post['authority_hrn'] + '.' + post['project_name']
+                        sfa_add_authority(wsgi_request, {'authority_hrn':hrn})
+                        authority_add_pis(wsgi_request, hrn, user_hrn)
+                    self.template_name = 'slice-request-done-view.html'
+                else:
+                    # Otherwise a wsgi_request is sent to the PI
+                    if 'join' in wsgi_request.POST:
+                        create_pending_join(wsgi_request, post)
+                    else:
+                        create_pending_project(wsgi_request, post)
+                    self.template_name = 'slice-request-ack-view.html'
+
+        # retrieves the pending projects creation list
         pending_projects = PendingProject.objects.all().filter(user_hrn=user_hrn)
-                    
+        # retrieves the pending join a project list
+        pending_join_projects = PendingJoin.objects.all().filter(user_hrn=user_hrn)
+
+        root_authority = user_authority.split('.', 1)[0]                  
         env = {
                'errors':        errors,
                'username':      wsgi_request.user,
                'theme':         self.theme,
                'authorities':   authorities,
                'authority_hrn': user_authority,
+               'root_authority_hrn': root_authority,
                'pending_projects': pending_projects,
+               'pending_join_projects': pending_join_projects,
         }
         return render(wsgi_request, self.template, env)
     
index 6ccabce..cbbc0ac 100644 (file)
 {% insert_str prelude "css/slider.css" %}
 {% insert_str prelude "css/topmenu.css" %}
 {% insert_str prelude "js/logout.js" %}
+{% insert_str prelude "js/jquery-ui.js" %}
+{% insert_str prelude "js/jquery-ui-combobox.js" %}
+<link rel='stylesheet' type='text/css' href='https://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css'/>
+<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/jquery.ui.combobox.css">
 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/{{ theme }}.css">
 <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/jquery.qtip.min.css">
 
index 034ec4f..985974f 100644 (file)
@@ -9,10 +9,10 @@
                         Account &nbsp;>&nbsp; <a href="/account">{{ person.email }}</a>
                 </div>
        </div>
-        {%if 'no_creds'  in user_cred %}
+        {%if 'no_creds' in user_cred %}
     <p class="command"><a href="#" style="color:red" data-toggle="modal" data-target="#myModal">NO CREDENTIALS</a> are delegated to the portal!</p>
     {%endif%}
-        {%if 'creds_expired'  in user_cred %}
+        {%if 'creds_expired' in user_cred %}
     <p class="command"><a href="#" style="color:red" data-toggle="modal" data-target="#myModal">EXPIRED CREDENTIALS</a> Please delegate again your credentials to the portal!</p>
     {%endif%}
 
@@ -26,7 +26,7 @@
 {% endif %}
 
 <form id="editForm" method="post" action="account_process" enctype="multipart/form-data">
-<input type="text" id="button_value"  name="button_value" value="" />
+<input type="hidden" id="button_value"  name="button_value" value="" />
 
 <div class="row">
        <div class="col-md-12">
 </form>
 <script>
     $(document).ready(function() {
+           {%if 'no_creds' in user_cred or 'creds_expired' in user_cred %}
+        localStorage.clear();
+        $.post("/cache/clear/", function( data ) {
+        });
+        {% endif %}
        $('.nav-tabs a').click(function (e) {
                        e.preventDefault();
                        $(this).tab('show');
index ab31f9f..5d632b6 100644 (file)
 
 <script type="text/javascript">
        $(document).ready(function() {
+           {%if 'no_creds' in user_cred or 'creds_expired' in user_cred %}
+        localStorage.clear();
+        $.post("/cache/clear/", function( data ) {
+        });
+        {% endif %}
                $('a.home-tab').click(function() {
                        $('ul.nav-tabs li').removeClass('active');
                        $(this).parent().addClass('active');
index a4c433b..78801b7 100644 (file)
         </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 %}
@@ -84,7 +89,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 +117,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 +180,7 @@ $(document).ready(function() {
                localStorage.clear();
        });
        // auto-complete the form
-    //jQuery("#org_name").combobox();
+    jQuery("#org_name").combobox();
 
 });
 </script>
index 7c172d5..7bcd56d 100644 (file)
@@ -47,8 +47,8 @@
                                {% endif %}
                          </div>
                          <div class="form-group">
-                Project: 
-                <select id="project" name="project">
+                Project: <div id="project_loading" style="display:inline;"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading projects" /></div> 
+                <select id="project" name="project" style="display:none;">
                 </select>
               </div>
                          <div class="form-group">
@@ -114,6 +114,8 @@ jQuery(document).ready(function(){
       source: availableTags,
       minLength: 0,
       select: function( event, ui ) {
+        $("#project").hide();
+        $("#project_loading").css('display', 'inline-block');
         draw_projects(jQuery('.ui-state-focus').html());
       },
     });
@@ -121,6 +123,7 @@ jQuery(document).ready(function(){
 });
 
 function draw_projects(authority_hrn){
+
     var projects = [];
     project_row = "<option value=''> - </option>";
     projects.push(project_row);
@@ -147,6 +150,8 @@ function draw_projects(authority_hrn){
         });
         $("#project").html(projects.join( "" ));
     }
+    $("#project").show();
+    $("#project_loading").hide();
 }
 </script>
 {% endblock %}
index dd3ce14..db4ace2 100644 (file)
             <b>{{request.slice_name}}</b> -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
             {% elif request.type == 'project' %}
             <b>{{request.project_name}}</b>  -- {{ request.user_hrn }} -- Purpose: {{request.purpose}}
+            {% elif request.type == 'join' %}
+            <b>{{request.user_hrn}}</b> --  to join {{ request.authority_hrn }}
             {% else %}
             <b>{{request.site_name}}</b> ({{request.site_authority}}) -- {{request.address_city}}, {{request.address_country}}
             {% endif %}
                    {% if request.type == 'slice' %}
                Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
                   {% elif request.type == 'project' %}
-            <b>{{request.project_name}}</b>  -- {{ request.user_hrn }} -- Purpose: {{request.purpose}}   
+            <b>{{request.project_name}}</b>  -- {{ request.user_hrn }} -- Purpose: {{request.purpose}}
+                  {% elif request.type == 'join' %}
+            <b>{{request.user_hrn}}</b> --  to join {{ request.authority_hrn }}
                    {% else %} {# authority #}
                Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
                    {% endif %}