fix: removed domain_name as required input when there is no domain costraints 44/8844/4
authorlombardofr <lombardo@everyup.it>
Sat, 2 May 2020 09:20:34 +0000 (11:20 +0200)
committerlombardofr <lombardo@everyup.it>
Thu, 7 May 2020 13:38:47 +0000 (15:38 +0200)
Change-Id: I98d47995246921b88a35102feacce9ae5381c9b4
Signed-off-by: lombardofr <lombardo@everyup.it>
projecthandler/template/project/modal/project_new.html
projecthandler/template/project/projectlist.html
static/src/userhandler/user_list.js
userhandler/templates/modal/user_create.html
userhandler/views.py

index df652d7..f1713ec 100644 (file)
@@ -26,14 +26,14 @@ limitations under the License.
             <div class="modal-body">
 
                 <div class="form-group" id="div_chose_id" >
-                    <label for="name" class="col-sm-3 control-label">Project Name* </label>
+                    <label for="name" class="col-sm-3 control-label">Project Name* </label>
                     <input name="name" id="name"  size="40" maxlength="20"required/>
                 </div>
 
-                <div class="form-group">
-                    <label for="domain_name" class="col-sm-3 control-label">Domain Name: </label>
+                <div class="form-group" id="domainNameGroupDiv">
+                    <label for="domain_name" class="col-sm-3 control-label">Domain Name* </label>
                     <div class="col-sm-6">
-                        <select required id="domain_name" class="js-example-basic form-control" name="domain_name">
+                        <select id="domain_name" class="js-example-basic form-control" name="domain_name" required>
                         </select>
                     </div>
                 </div>
index 5423aa1..61043ba 100644 (file)
@@ -160,31 +160,50 @@ limitations under the License.
     </script>
     <script>
     function showModalNewProject(args){
-        select2_groups = $('#domain_name').select2({
-            placeholder: 'Select Domain',
-            width: '100%',
-            ajax: {
-                url: args.domains_list_url,
-                dataType: 'json',
-                processResults: function (data) {
-                    domains_list = [];
-                    if (data['domains']) {
-                        for (d in data['domains']) {
-                            var domain = data['domains'][d];
-                            if( domain.endsWith(':ro') === false) {
-                                domains_list.push({ id: domain, text: domain })
-                            }
-                            
+        var dialog = bootbox.dialog({
+            message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+            closeButton: false
+        });
+        $.ajax({
+            url: args.domains_list_url,
+            dataType: "json",
+            contentType: "application/json;charset=utf-8",
+            success: function (result_domain) {
+                domains_list = [];
+                $('#domain_name').prop('disabled', false).trigger('change');
+                if (result_domain['domains']) {
+                    for (d in result_domain['domains']) {
+                        var domain = result_domain['domains'][d];
+                        if (domain.endsWith(':ro') === false) {
+                            domains_list.push({ id: domain, text: domain })
                         }
-                    }
 
-                    return {
-                        results: domains_list
-                    };
+                    }
                 }
+                if (domains_list.length == 0) {
+                    $('#domainNameGroupDiv').remove();
+                }
+                dialog.modal('hide');
+               
+                select2_groups = $('#domain_name').select2({
+                    placeholder: 'Select Domain',
+                    width: '100%',
+                    "language": {
+                        "noResults": function () {
+                            return "No domains in the platform";
+                        }
+                    },
+                    data: domains_list
+                });
+
+                $('#modal_new_project').modal('show');
+
+            },
+            error: function (result) {
+                dialog.modal('hide');
+                bootbox.alert("An error occurred.");
             }
         });
-        $('#modal_new_project').modal('show');
     }
 
     function editProject(project_id){
index 6b36f11..b3d8250 100644 (file)
 
 function openModalCreateUser(args) {
 
-    select2_groups = $('#projects').select2({
-        placeholder: 'Select Projects',
-        width: '100%',
-        ajax: {
-            url: args.projects_list_url,
-            dataType: 'json',
-            processResults: function (data) {
-                projects = [];
-                if (data['projects']) {
-                    for (d in data['projects']) {
-                        var project = data['projects'][d];
-                        projects.push({ id: project['_id'], text: project['name'] })
+    var dialog = bootbox.dialog({
+        message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
+        closeButton: false
+    });
+    $.ajax({
+        url: args.domains_list_url,
+        dataType: "json",
+        contentType: "application/json;charset=utf-8",
+        success: function (result_domain) {
+            domains_list = [];
+            $('#domain_name').prop('disabled', false).trigger('change');
+            if (result_domain['domains']) {
+                for (d in result_domain['domains']) {
+                    var domain = result_domain['domains'][d];
+                    if (domain.endsWith(':ro') === false) {
+                        domains_list.push({ id: domain, text: domain })
                     }
-                }
 
-                return {
-                    results: projects
-                };
+                }
             }
-        }
-    });
-
-    select2_groups = $('#domain_name').select2({
-        placeholder: 'Select Domain',
-        width: '100%',
-        ajax: {
-            url: args.domains_list_url,
-            dataType: 'json',
-            processResults: function (data) {
-                domains_list = [];
-
-                if (data['domains']) {
-                    for (d in data['domains']) {
-                        var domain = data['domains'][d];
-                        if( domain.endsWith(':ro') === false) {
-                            domains_list.push({ id: domain, text: domain })
+            if (domains_list.length == 0) {
+                $('#domainNameGroupDiv').remove();
+            }
+            dialog.modal('hide');
+            select2_groups = $('#projects').select2({
+                placeholder: 'Select Projects',
+                width: '100%',
+                ajax: {
+                    url: args.projects_list_url,
+                    dataType: 'json',
+                    processResults: function (data) {
+                        projects = [];
+                        if (data['projects']) {
+                            for (d in data['projects']) {
+                                var project = data['projects'][d];
+                                projects.push({ id: project['_id'], text: project['name'] })
+                            }
                         }
-                        
+
+                        return {
+                            results: projects
+                        };
                     }
                 }
+            });
+            select2_groups = $('#domain_name').select2({
+                placeholder: 'Select Domain',
+                width: '100%',
+                "language": {
+                    "noResults": function () {
+                        return "No domains in the platform";
+                    }
+                },
+                data: domains_list
+            });
 
-                return {
-                    results: domains_list
-                };
-            }
+            $('#modal_new_user').modal('show');
+
+        },
+        error: function (result) {
+            dialog.modal('hide');
+            bootbox.alert("An error occurred.");
         }
     });
 
-    $('#modal_new_user').modal('show');
+
 }
 
 function openModalEditUserCredentials(args) {
index 5aba035..0175e79 100644 (file)
@@ -56,11 +56,10 @@ limitations under the License.
                             </div>
                     </div>
 
-                    <div class="form-group">
-                        <label for="domain_name" class="col-sm-3 control-label">Domain</label>
-                        
+                    <div class="form-group" id="domainNameGroupDiv">
+                        <label for="domain_name" class="col-sm-3 control-label">Domain name *</label>
                         <div class="col-sm-6">
-                            <select required id="domain_name" class="js-example-basic form-control" name="domain_name">
+                            <select id="domain_name" class="js-example-basic form-control" name="domain_name" required>
                             </select>
                         </div>
                     </div>
index f6f2bf6..b78d1de 100644 (file)
@@ -43,12 +43,10 @@ def user_list(request):
 def create(request):
     user = osmutils.get_user(request)
     client = Client()
-    user_data = {
-        "username": request.POST['username'],
-        "password": request.POST['password'],
-        "domain_name": request.POST['domain_name']
-    }
 
+    new_user_dict = request.POST.dict()
+    keys = ["username", "password", "domain_name"]
+    user_data = dict(filter(lambda i: i[0] in keys and len(i[1]) > 0, new_user_dict.items()))
     result = client.user_create(user.get_token(), user_data)
     if result['error']:
         return __response_handler(request, result['data'], url=None,