From 88388f40b818e0a9323dc548ab3dd0e930ae4240 Mon Sep 17 00:00:00 2001
From: Kasper Brandt
- %s' % check[1]
- return mark_safe(u'%s' % label)
-
-
-
class IatiExportForm(forms.ModelForm):
"""Form for adding an entry to the IATI export model."""
is_public = forms.BooleanField(required=False, label=_(u"Show IATI file on organisation page"))
- projects = CustomLabelModelChoiceField(
+ projects = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
queryset=Project.objects.all(),
label=_(u"Select the projects included in the export:")
diff --git a/akvo/rsr/static/scripts-src/my-iati.js b/akvo/rsr/static/scripts-src/my-iati.js
new file mode 100644
index 0000000000..174c4a9e87
--- /dev/null
+++ b/akvo/rsr/static/scripts-src/my-iati.js
@@ -0,0 +1,92 @@
+/** @jsx React.DOM */
+
+// Akvo RSR is covered by the GNU Affero General Public License.
+// See more details in the license.txt file located at the root folder of the
+// Akvo RSR module. For additional details on the GNU license please see
+// < http://www.gnu.org/licenses/agpl.html >.
+
+
+function loadAsync(url, retryCount, retryLimit, label) {
+ var xmlHttp;
+
+ xmlHttp = new XMLHttpRequest();
+
+ xmlHttp.onreadystatechange = function() {
+ if (xmlHttp.readyState == XMLHttpRequest.DONE) {
+
+ if(xmlHttp.status == 200){
+ processResponse(label, xmlHttp.responseText);
+ } else {
+ if (retryCount >= retryLimit) {
+ return;
+ } else {
+ retryCount = retryCount + 1;
+ loadAsync(url, retryCount, retryLimit);
+ }
+ }
+ } else {
+ return;
+ }
+ };
+
+ xmlHttp.open("GET", url, true);
+ xmlHttp.send();
+}
+
+function processResponse(label, response) {
+ var label_content, checks, all_checks_passed, span;
+
+ label_content = label.innerHTML;
+ checks = JSON.parse(response);
+
+ all_checks_passed = checks.all_checks_passed;
+
+ if (all_checks_passed === "True") {
+ span = document.createElement("span");
+ span.className = "success";
+ span.innerHTML = label_content;
+
+ label.innerHTML = '';
+ label.appendChild(span);
+
+ } else if (all_checks_passed === "False") {
+ span = document.createElement("span");
+ span.className = "error";
+ span.innerHTML = label_content;
+
+ label.innerHTML = '';
+ label.appendChild(span);
+ }
+}
+
+function getProjectLabels() {
+ var labels;
+
+ labels = document.getElementById('id_projects').getElementsByTagName('label');
+
+ for (var i = 0; i < labels.length; i++) {
+ var project_id;
+
+ project_id = labels[i].getElementsByTagName('input')[0].value;
+ loadAsync('/rest/v1/project_iati_check/' + project_id + '/?format=json', 0, 3, labels[i]);
+ }
+}
+
+function loadComponent(component_id) {
+ var Container;
+
+ Container = React.createClass({displayName: 'Container',
+ render: function() {
+ return (
+ React.DOM.a( {onClick:getProjectLabels}, "Perform checks")
+ );
+ }
+ });
+
+ React.render(
+ Container(null ),
+ document.getElementById(component_id)
+ );
+}
+
+loadComponent('react_iati_checks');
diff --git a/akvo/rsr/static/scripts-src/my-iati.jsx b/akvo/rsr/static/scripts-src/my-iati.jsx
new file mode 100644
index 0000000000..6d5abcdb9e
--- /dev/null
+++ b/akvo/rsr/static/scripts-src/my-iati.jsx
@@ -0,0 +1,92 @@
+/** @jsx React.DOM */
+
+// Akvo RSR is covered by the GNU Affero General Public License.
+// See more details in the license.txt file located at the root folder of the
+// Akvo RSR module. For additional details on the GNU license please see
+// < http://www.gnu.org/licenses/agpl.html >.
+
+
+function loadAsync(url, retryCount, retryLimit, label) {
+ var xmlHttp;
+
+ xmlHttp = new XMLHttpRequest();
+
+ xmlHttp.onreadystatechange = function() {
+ if (xmlHttp.readyState == XMLHttpRequest.DONE) {
+
+ if(xmlHttp.status == 200){
+ processResponse(label, xmlHttp.responseText);
+ } else {
+ if (retryCount >= retryLimit) {
+ return;
+ } else {
+ retryCount = retryCount + 1;
+ loadAsync(url, retryCount, retryLimit);
+ }
+ }
+ } else {
+ return;
+ }
+ };
+
+ xmlHttp.open("GET", url, true);
+ xmlHttp.send();
+}
+
+function processResponse(label, response) {
+ var label_content, checks, all_checks_passed, span;
+
+ label_content = label.innerHTML;
+ checks = JSON.parse(response);
+
+ all_checks_passed = checks.all_checks_passed;
+
+ if (all_checks_passed === "True") {
+ span = document.createElement("span");
+ span.className = "success";
+ span.innerHTML = label_content;
+
+ label.innerHTML = '';
+ label.appendChild(span);
+
+ } else if (all_checks_passed === "False") {
+ span = document.createElement("span");
+ span.className = "error";
+ span.innerHTML = label_content;
+
+ label.innerHTML = '';
+ label.appendChild(span);
+ }
+}
+
+function getProjectLabels() {
+ var labels;
+
+ labels = document.getElementById('id_projects').getElementsByTagName('label');
+
+ for (var i = 0; i < labels.length; i++) {
+ var project_id;
+
+ project_id = labels[i].getElementsByTagName('input')[0].value;
+ loadAsync('/rest/v1/project_iati_check/' + project_id + '/?format=json', 0, 3, labels[i]);
+ }
+}
+
+function loadComponent(component_id) {
+ var Container;
+
+ Container = React.createClass({
+ render: function() {
+ return (
+ Perform checks
+ );
+ }
+ });
+
+ React.render(
+ {% trans "My IATI" %}{% if selected_org %} {% trans "for" %} {{selected_org.
{% elif project_count > 0 %} +
+ {% blocktrans %}
+ In order to see which of your projects is fully IATI compliant, you can
+ perform checks by clicking the "Perform checks" button.
+ Projects with all mandatory IATI information filled in will be
+ marked green and projects with missing
+ information will be marked red.
+ {% endblocktrans %}
+