diff --git a/akvo/rsr/models/organisation.py b/akvo/rsr/models/organisation.py index 4c0d003f78..b6f922c6da 100644 --- a/akvo/rsr/models/organisation.py +++ b/akvo/rsr/models/organisation.py @@ -88,7 +88,8 @@ def org_type_from_iati_type(cls, iati_type): help_text=_(u'The main language of the organisation'), ) organisation_type = ValidXMLCharField( - _(u'organisation type'), max_length=1, db_index=True, choices=ORG_TYPES + _(u'organisation type'), max_length=1, db_index=True, choices=ORG_TYPES, null=True, + blank=True ) new_organisation_type = models.IntegerField( _(u'IATI organisation type'), db_index=True, diff --git a/akvo/rsr/static/scripts-src/myrsr-admin.js b/akvo/rsr/static/scripts-src/myrsr-admin.js index 24bb901b6e..b5f7c44c1a 100644 --- a/akvo/rsr/static/scripts-src/myrsr-admin.js +++ b/akvo/rsr/static/scripts-src/myrsr-admin.js @@ -2129,12 +2129,41 @@ function addOrgModal() { /* Submit the new org */ function submitModal() { if (allInputsFilled()) { - console.log("Do something to create the new organisation"); + var api_url, request, message, form, form_data; + // TODO: Check if name or long_name already exist + // Add organisation to DB + form = document.querySelector('#addOrganisation'); + form_data = serialize(form); + + api_url = '/rest/v1/organisation/?format=json'; + + request = new XMLHttpRequest(); + request.open('POST', api_url, true); + request.setRequestHeader("X-CSRFToken", csrftoken); + request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + + request.onload = function() { + if (request.status >= 200 && request.status < 400) { + var response; + response = JSON.parse(request.responseText); + // TODO: Add organisation to all organisation typeaheads + + return false; + } else { + // We reached our target server, but it returned an error + } + }; + + request.onerror = function() { + // There was a connection error of some sort + message = '
Connection error, check your internet connection
'; + + finishSave(step, message); + return false; + }; + + request.send(form_data); - /* We will need to populate the "Reporting organisation" typeahead - ** with the new org if creation is successful. We can't do this - ** until we get back the ID of the new org. - */ cancelModal(); } else { // call to allInputsFilled() shows error message @@ -2185,24 +2214,31 @@ function addOrgModal() { React.DOM.div( {className:"orgModal"}, React.DOM.div( {className:"modalContents"}, React.DOM.h4(null, "Add new organisation"), - React.DOM.form(null, + React.DOM.form( {id:"addOrganisation"}, React.DOM.div( {className:"row"}, - React.DOM.div( {className:"inputContainer newOrgName col-md-4"}, - React.DOM.input( {id:"newOrgName", type:"text", className:"form-control", maxLength:"25"}), - React.DOM.label( {for:"newOrgName", className:"control-label"}, "Name: " ), + React.DOM.div( {className:"inputContainer newOrgName col-md-6"}, + React.DOM.input( {name:"name", id:"newOrgName", type:"text", className:"form-control", maxLength:"25"}), + React.DOM.label( {htmlFor:"newOrgName", className:"control-label"}, "Name: " ), React.DOM.p( {className:"helpBlock"}) ), - React.DOM.div( {className:"inputContainer newOrgLongName col-md-4"}, - React.DOM.input( {id:"newOrgLongName", type:"text", className:"form-control", maxLength:"75"}), - React.DOM.label( {for:"newOrgLongName", className:"control-label"}, "Long name: " ), + React.DOM.div( {className:"inputContainer newOrgLongName col-md-6"}, + React.DOM.input( {name:"long_name", id:"newOrgLongName", type:"text", className:"form-control", maxLength:"75"}), + React.DOM.label( {htmlFor:"newOrgLongName", className:"control-label"}, "Long name: " ), + React.DOM.p( {className:"helpBlock"}) + ) + ), + React.DOM.div( {className:"row"}, + React.DOM.div( {className:"inputContainer newOrgIatiId col-md-6"}, + React.DOM.input( {name:"iati_org_id", id:"newOrgIatiId", type:"text", className:"form-control", maxLength:"75"}), + React.DOM.label( {htmlFor:"newOrgIatiId", className:"control-label"}, "Organisation IATI identifier: " ), React.DOM.p( {className:"helpBlock"}) ), - React.DOM.div( {className:"IATIOrgTypeContainer inputContainer col-md-4"}, - React.DOM.select( {id:"newOrgIATIType", className:"form-control"}, - React.DOM.option( {value:"10", selected:true}, "10 - Government"), + React.DOM.div( {className:"IATIOrgTypeContainer inputContainer col-md-6"}, + React.DOM.select( {name:"new_organisation_type", id:"newOrgIATIType", className:"form-control"}, + React.DOM.option( {value:"10"}, "10 - Government"), React.DOM.option( {value:"15"}, "15 - Other Public Sector"), React.DOM.option( {value:"21"}, "21 - International NGO"), - React.DOM.option( {value:"22"}, "22 - National NGO"), + React.DOM.option( {value:"22", selected:true}, "22 - National NGO"), React.DOM.option( {value:"23"}, "23 - Regional NGO"), React.DOM.option( {value:"30"}, "30 - Public Private Partnership"), React.DOM.option( {value:"40"}, "40 - Multilateral"), @@ -2210,7 +2246,7 @@ function addOrgModal() { React.DOM.option( {value:"70"}, "70 - Private Sector"), React.DOM.option( {value:"80"}, "80 - Academic, Training and Research") ), - React.DOM.label( {for:"newOrgIATIType", className:"control-label"}, "IATI organisation type: " ), + React.DOM.label( {for:"newOrgIATIType", className:"control-label"}, "Organisation type: " ), React.DOM.p( {className:"helpBlock"}) ) ) diff --git a/akvo/rsr/static/scripts-src/myrsr-admin.jsx b/akvo/rsr/static/scripts-src/myrsr-admin.jsx index cb070fb1c4..e88801c90f 100644 --- a/akvo/rsr/static/scripts-src/myrsr-admin.jsx +++ b/akvo/rsr/static/scripts-src/myrsr-admin.jsx @@ -2129,12 +2129,41 @@ function addOrgModal() { /* Submit the new org */ function submitModal() { if (allInputsFilled()) { - console.log("Do something to create the new organisation"); + var api_url, request, message, form, form_data; + // TODO: Check if name or long_name already exist + // Add organisation to DB + form = document.querySelector('#addOrganisation'); + form_data = serialize(form); + + api_url = '/rest/v1/organisation/?format=json'; + + request = new XMLHttpRequest(); + request.open('POST', api_url, true); + request.setRequestHeader("X-CSRFToken", csrftoken); + request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + + request.onload = function() { + if (request.status >= 200 && request.status < 400) { + var response; + response = JSON.parse(request.responseText); + // TODO: Add organisation to all organisation typeaheads + + return false; + } else { + // We reached our target server, but it returned an error + } + }; + + request.onerror = function() { + // There was a connection error of some sort + message = '
Connection error, check your internet connection
'; + + finishSave(step, message); + return false; + }; + + request.send(form_data); - /* We will need to populate the "Reporting organisation" typeahead - ** with the new org if creation is successful. We can't do this - ** until we get back the ID of the new org. - */ cancelModal(); } else { // call to allInputsFilled() shows error message @@ -2185,24 +2214,31 @@ function addOrgModal() {

Add new organisation

-
+
-
- - +
+ +

-
- - +
+ + +

+
+
+
+
+ +

-
- + - + @@ -2210,7 +2246,7 @@ function addOrgModal() { - +