diff --git a/config.xml b/config.xml
index 6c54148..e477343 100644
--- a/config.xml
+++ b/config.xml
@@ -83,7 +83,6 @@
-
@@ -96,6 +95,10 @@
+
+
+
+
@@ -105,7 +108,4 @@
-
-
-
diff --git a/package.json b/package.json
index 944935d..8a3ff96 100644
--- a/package.json
+++ b/package.json
@@ -1,89 +1,89 @@
{
- "name": "ionic-project",
- "version": "1.1.1",
- "description": "An Ionic project",
- "dependencies": {
- "cordova-android": "6.3.0",
- "cordova-ios": "~4.3.1",
- "cordova-plugin-advanced-http": "^1.7.1",
- "cordova-plugin-camera": "^2.4.1",
- "cordova-plugin-compat": "^1.2.0",
- "cordova-plugin-crosswalk-certificate": "^2.0.1",
- "cordova-plugin-crosswalk-webview": "^2.3.0",
- "cordova-plugin-file": "^4.3.3",
- "cordova-plugin-mauron85-background-geolocation": "^2.3.1",
- "cordova-plugin-sqlite-2": "^1.0.4",
- "cordova-plugin-sslcertificatechecker": "^5.1.0",
- "cordova-plugin-whitelist": "^1.3.2",
- "gulp": "^3.5.6",
- "gulp-concat": "^2.2.0",
- "gulp-minify-css": "^0.3.0",
- "gulp-rename": "^1.2.0",
- "gulp-sass": "^3.0.0"
+ "name": "ionic-project",
+ "version": "1.1.1",
+ "description": "An Ionic project",
+ "dependencies": {
+ "cordova-android": "6.3.0",
+ "cordova-ios": "~4.3.1",
+ "cordova-plugin-advanced-http": "^1.7.1",
+ "cordova-plugin-camera": "^2.4.1",
+ "cordova-plugin-compat": "^1.2.0",
+ "cordova-plugin-crosswalk-certificate": "^2.0.1",
+ "cordova-plugin-crosswalk-webview": "^2.3.0",
+ "cordova-plugin-file": "^4.3.3",
+ "cordova-plugin-mauron85-background-geolocation": "^2.3.1",
+ "cordova-plugin-sqlite-2": "^1.0.4",
+ "cordova-plugin-sslcertificatechecker": "^5.1.0",
+ "cordova-plugin-whitelist": "^1.3.2",
+ "gulp": "^3.5.6",
+ "gulp-concat": "^2.2.0",
+ "gulp-minify-css": "^0.3.0",
+ "gulp-rename": "^1.2.0",
+ "gulp-sass": "^3.0.0"
+ },
+ "devDependencies": {
+ "bower": "^1.3.3",
+ "gulp-preprocess": "^2.0.0",
+ "gulp-util": "^2.2.14",
+ "shelljs": "^0.3.0"
+ },
+ "cordovaPlugins": [
+ "cordova-plugin-device",
+ "cordova-plugin-console",
+ "cordova-plugin-whitelist",
+ "cordova-plugin-splashscreen",
+ "cordova-plugin-statusbar",
+ "ionic-plugin-keyboard",
+ "cordova-plugin-dialogs",
+ "cordova-plugin-camera@2.4.1",
+ {
+ "variables": {
+ "XWALK_VERSION": "23+"
+ },
+ "locator": "cordova-plugin-crosswalk-webview",
+ "id": "cordova-plugin-camera"
},
- "devDependencies": {
- "bower": "^1.3.3",
- "gulp-preprocess": "^2.0.0",
- "gulp-util": "^2.2.14",
- "shelljs": "^0.3.0"
+ "cordova-plugin-crosswalk-certificate"
+ ],
+ "cordovaPlatforms": [
+ {
+ "platform": "android",
+ "version": "6.1.0",
+ "locator": "android@6.1.0"
},
- "cordovaPlugins": [
- "cordova-plugin-device",
- "cordova-plugin-console",
- "cordova-plugin-whitelist",
- "cordova-plugin-splashscreen",
- "cordova-plugin-statusbar",
- "ionic-plugin-keyboard",
- "cordova-plugin-dialogs",
- "cordova-plugin-camera@2.4.1",
- {
- "variables": {
- "XWALK_VERSION": "23+"
- },
- "locator": "cordova-plugin-crosswalk-webview",
- "id": "cordova-plugin-camera"
- },
- "cordova-plugin-crosswalk-certificate"
+ "ios"
+ ],
+ "cordova": {
+ "platforms": [
+ "android",
+ "ios"
],
- "cordovaPlatforms": [
- {
- "platform": "android",
- "version": "6.1.0",
- "locator": "android@6.1.0"
- },
- "ios"
- ],
- "cordova": {
- "platforms": [
- "android",
- "ios"
- ],
- "plugins": {
- "cordova-plugin-camera": {
- "CAMERA_USAGE_DESCRIPTION": "DengueChat needs access to your camera for you to take photos within the app",
- "PHOTOLIBRARY_USAGE_DESCRIPTION": "DengueChat needs access to your camera for you to take photos within the app"
- },
- "cordova-plugin-crosswalk-certificate": {},
- "cordova-plugin-crosswalk-webview": {
- "XWALK_VERSION": "23+",
- "XWALK_LITEVERSION": "xwalk_core_library_canary:17+",
- "XWALK_COMMANDLINE": "--disable-pull-to-refresh-effect",
- "XWALK_MODE": "embedded",
- "XWALK_MULTIPLEAPK": "true"
- },
- "cordova-plugin-sqlite-2": {},
- "cordova-plugin-whitelist": {},
- "cordova-plugin-sslcertificatechecker": {},
- "cordova-plugin-advanced-http": {},
- "cordova-plugin-mauron85-background-geolocation": {
- "ICON": "@mipmap/icon",
- "SMALL_ICON": "@mipmap/icon",
- "ACCOUNT_NAME": "@string/app_name",
- "ACCOUNT_LABEL": "@string/app_name",
- "ACCOUNT_TYPE": "$PACKAGE_NAME.account",
- "CONTENT_AUTHORITY": "$PACKAGE_NAME",
- "ALWAYS_USAGE_DESCRIPTION": "This app requires background location tracking"
- }
- }
+ "plugins": {
+ "cordova-plugin-camera": {
+ "CAMERA_USAGE_DESCRIPTION": "DengueChat needs access to your camera for you to take photos within the app",
+ "PHOTOLIBRARY_USAGE_DESCRIPTION": "DengueChat needs access to your camera for you to take photos within the app"
+ },
+ "cordova-plugin-crosswalk-certificate": {},
+ "cordova-plugin-crosswalk-webview": {
+ "XWALK_VERSION": "23+",
+ "XWALK_LITEVERSION": "xwalk_core_library_canary:17+",
+ "XWALK_COMMANDLINE": "--disable-pull-to-refresh-effect",
+ "XWALK_MODE": "embedded",
+ "XWALK_MULTIPLEAPK": "true"
+ },
+ "cordova-plugin-sqlite-2": {},
+ "cordova-plugin-whitelist": {},
+ "cordova-plugin-sslcertificatechecker": {},
+ "cordova-plugin-advanced-http": {},
+ "cordova-plugin-mauron85-background-geolocation": {
+ "ICON": "@mipmap/icon",
+ "SMALL_ICON": "@mipmap/icon",
+ "ACCOUNT_NAME": "@string/app_name",
+ "ACCOUNT_LABEL": "@string/app_name",
+ "ACCOUNT_TYPE": "$PACKAGE_NAME.account",
+ "CONTENT_AUTHORITY": "$PACKAGE_NAME",
+ "ALWAYS_USAGE_DESCRIPTION": "This app requires background location tracking"
+ }
}
+ }
}
\ No newline at end of file
diff --git a/www/js/controllers/locationCtrl.js b/www/js/controllers/locationCtrl.js
index 8cf512d..a1e7620 100644
--- a/www/js/controllers/locationCtrl.js
+++ b/www/js/controllers/locationCtrl.js
@@ -1,116 +1,164 @@
-angular.module('starter.controllers')
-.controller('locationCtrl', ['$scope', "$state", 'Location', '$ionicLoading', "moment", '$ionicHistory', "$ionicSlideBoxDelegate", 'LocationQuiz',"$ionicModal", "Visit", function($scope, $state, Location, $ionicLoading, moment, $ionicHistory, $ionicSlideBoxDelegate, LocationQuiz, $ionicModal, Visit) {
- $scope.state = {firstLoad: true, pageIndex: 0};
- $scope.params = {search: ""};
- $scope.visit = {}
- $scope.location = {}
-
- $scope.$on("$ionicView.loaded", function() {
- $ionicLoading.show({template: "
Cargando hogares...", hideOnStateChange: true})
-
- Location.get($state.params.id).then(function(loc) {
- $scope.location = loc
- $scope.visit.location = {id: loc.id, pouchdb_id: loc._id, address: loc.address}
-
- if (!$scope.location.visits || $scope.location.visits.length == 0) {
- $scope.visits = []
- $ionicLoading.hide();
- } else {
- Visit.getAll($scope.location.visits).then(function(visits) {
- $scope.visits = visits
- $ionicLoading.hide();
- })
- }
- }).catch(function(response) {
- $ionicLoading.hide();
- })
- })
-
- $scope.createVisit = function() {
- $ionicLoading.show({template: "
Creando la visita...", hideOnStateChange: true})
-
- doc_id = Visit.documentID($state.params.id, $scope.visit);
- Visit.save(doc_id, $scope.visit, {remote: true, synced: false}).then(function(response) {
- if ($scope.location.visits)
- $scope.location.visits.push(doc_id)
- else
- $scope.location.visits = [doc_id]
-
- Location.save($state.params.id, $scope.location, {remote: false}).then(function(res) {
- $ionicLoading.hide().then(function() {
- $scope.closeNewVisitModal()
- $state.go("app.location.visit", {visit_id: doc_id})
+angular.module("starter.controllers").controller("locationCtrl", [
+ "$scope",
+ "$state",
+ "Location",
+ "$ionicLoading",
+ "moment",
+ "$ionicHistory",
+ "$ionicSlideBoxDelegate",
+ "LocationQuiz",
+ "$ionicModal",
+ "Visit",
+ function(
+ $scope,
+ $state,
+ Location,
+ $ionicLoading,
+ moment,
+ $ionicHistory,
+ $ionicSlideBoxDelegate,
+ LocationQuiz,
+ $ionicModal,
+ Visit
+ ) {
+ $scope.state = { firstLoad: true, pageIndex: 0 };
+ $scope.params = { search: "" };
+ $scope.visit = {};
+ $scope.location = {};
+
+ $scope.$on("$ionicView.loaded", function() {
+ $ionicLoading.show({
+ template: "
Cargando hogares...",
+ hideOnStateChange: true
+ });
+
+ Location.get($state.params.id)
+ .then(function(loc) {
+ $scope.location = loc;
+ $scope.visit.location = {
+ id: loc.id,
+ pouchdb_id: loc._id,
+ address: loc.address
+ };
+
+ if (!$scope.location.visits || $scope.location.visits.length == 0) {
+ $scope.visits = [];
+ $ionicLoading.hide();
+ } else {
+ Visit.getAll($scope.location.visits).then(function(visits) {
+ $scope.visits = visits;
+ $ionicLoading.hide();
+ });
+ }
})
- }, function(err) {console.log(err)})
- }, function(response) {
- console.log(response)
- $ionicLoading.hide()
- })
- }
-
- $scope.refresh = function() {
- // TODO
- // $ionicHistory.removeBackView()
-
- $scope.state.loading = true
- Location.getFromCloud($scope.location).then(function(response) {
- $scope.state.firstLoad = false;
- $scope.state.loading = false;
- $scope.$broadcast('scroll.refreshComplete');
- }, function(response) {
- $scope.state.firstLoad = false;
- $scope.state.loading = false;
- $scope.$broadcast('scroll.refreshComplete');
-
- $scope.$emit(denguechat.env.error, {error: response})
- })
- }
-
- $scope.saveQuestions = function() {
- $ionicLoading.show({hideOnStateChange: true})
-
- Location.save($state.params.id, $scope.location, {remote: true}).then(function(response) {
- $ionicLoading.hide()
- $scope.transitionToPageIndex(0)
- })
- }
-
- $scope.$on(denguechat.env.data.refresh, function() {
- $scope.state.loading = true
- $scope.refresh();
- })
-
- $scope.changeTimeline = function(pageIndex) {
- $scope.state.pageIndex = pageIndex
- }
-
- $scope.transitionToPageIndex = function(pageIndex) {
- $scope.state.pageIndex = pageIndex
- $ionicSlideBoxDelegate.slide(pageIndex);
- }
+ .catch(function(response) {
+ $ionicLoading.hide();
+ });
+ });
- $scope.shouldDisplay = function(q) {
- return LocationQuiz.shouldDisplay(q, $scope.location.questions)
- }
+ $scope.createVisit = function() {
+ $ionicLoading.show({
+ template: "
Creando la visita...",
+ hideOnStateChange: true
+ });
+
+ doc_id = Visit.documentID($state.params.id, $scope.visit);
+ Visit.save(doc_id, $scope.visit, { remote: true, synced: false }).then(
+ function(response) {
+ if ($scope.location.visits) $scope.location.visits.push(doc_id);
+ else $scope.location.visits = [doc_id];
+
+ Location.save($state.params.id, $scope.location, {
+ remote: false
+ }).then(
+ function(res) {
+ $ionicLoading.hide().then(function() {
+ $scope.closeNewVisitModal();
+ $state.go("app.location.visit", { visit_id: doc_id });
+ });
+ },
+ function(err) {
+ console.log(err);
+ }
+ );
+ },
+ function(response) {
+ console.log(response);
+ $ionicLoading.hide();
+ }
+ );
+ };
+
+ $scope.refresh = function() {
+ // TODO
+ // $ionicHistory.removeBackView()
+
+ $scope.state.loading = true;
+ Location.getFromCloud($scope.location).then(
+ function(response) {
+ $scope.state.firstLoad = false;
+ $scope.state.loading = false;
+ $scope.$broadcast("scroll.refreshComplete");
+ },
+ function(response) {
+ $scope.state.firstLoad = false;
+ $scope.state.loading = false;
+ $scope.$broadcast("scroll.refreshComplete");
+
+ $scope.$emit(denguechat.env.error, { error: response });
+ }
+ );
+ };
+
+ $scope.saveQuestions = function() {
+ $ionicLoading.show({ hideOnStateChange: true });
+
+ Location.save($state.params.id, $scope.location, {
+ remote: true
+ }).then(function(response) {
+ $ionicLoading.hide();
+ $scope.transitionToPageIndex(0);
+ });
+ };
- $scope.showNewVisitModal = function() {
- // Create the login modal that we will use later
- return $ionicModal.fromTemplateUrl('templates/locations/new_visit.html', {
- scope: $scope,
- animation: 'slide-in-up',
- focusFirstInput: true,
- backdropClickToClose: false,
- hardwareBackButtonClose: false
- }).then(function(modal) {
- $scope.modal = modal;
- modal.show()
+ $scope.$on(denguechat.env.data.refresh, function() {
+ $scope.state.loading = true;
+ $scope.refresh();
});
- }
- $scope.closeNewVisitModal = function() {
- $scope.modal.hide().then(function() {
- $scope.modal.remove();
- })
+ $scope.changeTimeline = function(pageIndex) {
+ $scope.state.pageIndex = pageIndex;
+ };
+
+ $scope.transitionToPageIndex = function(pageIndex) {
+ $scope.state.pageIndex = pageIndex;
+ $ionicSlideBoxDelegate.slide(pageIndex);
+ };
+
+ $scope.shouldDisplay = function(q) {
+ return LocationQuiz.shouldDisplay(q, $scope.location.questions);
+ };
+
+ $scope.showNewVisitModal = function() {
+ // Create the login modal that we will use later
+ return $ionicModal
+ .fromTemplateUrl("templates/locations/new_visit.html", {
+ scope: $scope,
+ animation: "slide-in-up",
+ focusFirstInput: true,
+ backdropClickToClose: false,
+ hardwareBackButtonClose: false
+ })
+ .then(function(modal) {
+ $scope.modal = modal;
+ modal.show();
+ });
+ };
+
+ $scope.closeNewVisitModal = function() {
+ $scope.modal.hide().then(function() {
+ $scope.modal.remove();
+ });
+ };
}
-
-}])
+]);
diff --git a/www/js/controllers/locationsCtrl.js b/www/js/controllers/locationsCtrl.js
index aa15eb4..c9c14c1 100644
--- a/www/js/controllers/locationsCtrl.js
+++ b/www/js/controllers/locationsCtrl.js
@@ -1,214 +1,270 @@
-angular.module('starter.controllers')
-.controller('locationsCtrl', ['$scope', 'Location', "$ionicLoading", "$ionicModal", "User", "$state", "$cordovaGeolocation", function($scope, Location, $ionicLoading, $ionicModal, User, $state, $cordovaGeolocation) {
- $scope.locations = [];
- $scope.state = {firstLoad: true, loadingGeo: false};
- $scope.params = {search: ""};
- $scope.user = {}
-
-
- User.get().then(function(user) {
- $scope.user = user
- $scope.neighborhoods = user.neighborhoods;
- $scope.location = {neighborhood_id: user.neighborhood.id, questions: user.neighborhood.questions, last_visited_at: new Date(), visits_count: 0}
- })
-
- // Triggered only once when the view is loaded.
- // http://ionicframework.com/docs/api/directive/ionView/
- $scope.$on("$ionicView.loaded", function() {
- $scope.loadAllLocations()
- })
-
- $scope.loadAllLocations = function() {
- $ionicLoading.show({hideOnStateChange: true})
-
- Location.getAll().then(function(locations) {
- $scope.locations = locations
- }).catch(function(res) {
- // navigator.notification.alert(JSON.stringify(res), null, "Problem getting all locations", "OK")
- }).finally(function(res) {
- $scope.state.loading = false
- $scope.state.firstLoad = false;
- $ionicLoading.hide();
- })
- }
-
-
- $scope.searchByAddress = function() {
- $ionicLoading.show({hideOnStateChange: true})
-
- console.log($scope.params.search)
-
- $scope.locations = []
- Location.search($scope.params.search).then(function(response) {
- console.log(response)
- $scope.locations = response.rows;
- $ionicLoading.hide();
- }, function(response) {
- $ionicLoading.hide();
+angular.module("starter.controllers").controller("locationsCtrl", [
+ "$scope",
+ "Location",
+ "$ionicLoading",
+ "$ionicModal",
+ "User",
+ "$state",
+ "$cordovaGeolocation",
+ function(
+ $scope,
+ Location,
+ $ionicLoading,
+ $ionicModal,
+ User,
+ $state,
+ $cordovaGeolocation
+ ) {
+ $scope.locations = [];
+ $scope.state = { firstLoad: true, loadingGeo: false };
+ $scope.params = { search: "" };
+ $scope.user = {};
+
+ User.get().then(function(user) {
+ $scope.user = user;
+ $scope.neighborhoods = user.neighborhoods;
+ $scope.location = {
+ neighborhood_id: user.neighborhood.id,
+ questions: user.neighborhood.questions,
+ last_visited_at: new Date(),
+ visits_count: 0
+ };
});
- }
-
- $scope.refresh = function() {
- $ionicLoading.show({hideOnStateChange: true})
-
- Location.getAllFromCloud().then(function(response) {
- return Location.getAll().then(function(locations) {
- $scope.locations = locations
- })
- }).then(function() {
- $scope.state.firstLoad = false;
- $scope.$broadcast('scroll.refreshComplete');
- $ionicLoading.hide()
- }).catch(function(res) {
- navigator.notification.alert(JSON.stringify(res), null, "Problem getting all locations from server", "OK")
- // $scope.$emit(denguechat.env.error, response)
- })
- }
-
- $scope.$on(denguechat.env.data.refresh, function() {
- $scope.state.loading = true
- $scope.refresh();
- })
-
-
- $scope.showNewLocationModal = function() {
- // Create the login modal that we will use later
- return $ionicModal.fromTemplateUrl('templates/locations/new_location.html', {
- scope: $scope,
- animation: 'slide-in-up',
- focusFirstInput: true,
- backdropClickToClose: false,
- hardwareBackButtonClose: false
- }).then(function(modal) {
- $scope.modal = modal;
- modal.show()
-
- $scope.state.loadingGeo = true;
- $scope.loadGeo()
+ // Triggered only once when the view is loaded.
+ // http://ionicframework.com/docs/api/directive/ionView/
+ $scope.$on("$ionicView.loaded", function() {
+ $scope.loadAllLocations();
});
- }
-
- $scope.closeNewLocationModal = function() {
- $scope.modal.hide().then(function() {
- $scope.modal.remove();
- })
- }
+ $scope.loadAllLocations = function() {
+ $ionicLoading.show({ hideOnStateChange: true });
-
- // Map modal.
- // $scope.loadMap = function() {
- // modal = $ionicModal.fromTemplateUrl('templates/map.html', {
- // scope: $scope,
- // animation: 'slide-in-up',
- // focusFirstInput: true
- // }).then(function(modal) {
- // $scope.mapModal = modal;
- // });
- //
- // modal.then(function() {
- // $scope.mapModal.show();
- // })
- // }
-
- // $scope.closeLogin = function() {
- // $scope.mapModal.hide();
- // };
-
-
- $scope.create = function() {
- if (!$scope.location.address) {
- navigator.notification.alert("Address can't be blank", null, "Problem saving", "OK")
- return
- }
-
- Location.search($scope.location.address).then(function(result) {
- if (result.docs.length > 0) {
- navigator.notification.alert("A location with this address already exists", null, "Problem saving", "OK")
- return
- }
-
- $ionicLoading.show()
- doc_id = Location.documentID($scope.user, $scope.location)
- $scope.location.user_id = $scope.user.id
- $scope.location.visits = []
- $scope.location.questions = $scope.user.location_questionnaire
- Location.save(doc_id, $scope.location, {remote: true, synced: false}).then(function(response) {
- $scope.location = {}
-
- $ionicLoading.hide().then(function() {
- $scope.modal.hide().then(function() {
- $scope.modal.remove();
- $state.go("app.location", {id: doc_id})
- })
+ Location.getAll()
+ .then(function(locations) {
+ $scope.locations = locations;
+ $scope.state.loading = false;
+ $scope.state.firstLoad = false;
+ $ionicLoading.hide();
})
+ .catch(function(res) {
+ $ionicLoading.hide();
+ $scope.state.loading = false;
+ $scope.state.firstLoad = false;
+ });
+ };
- }, function(response) {
- $scope.$emit(denguechat.env.error, {error: "Something went wrong. Please try again."})
- $ionicLoading.hide()
- })
+ $scope.searchByAddress = function() {
+ $ionicLoading.show({ hideOnStateChange: true });
+
+ console.log($scope.params.search);
+
+ $scope.locations = [];
+ Location.search($scope.params.search).then(
+ function(response) {
+ console.log(response);
+ $scope.locations = response.rows;
+ $ionicLoading.hide();
+ },
+ function(response) {
+ $ionicLoading.hide();
+ }
+ );
+ };
- })
+ $scope.refresh = function() {
+ $ionicLoading.show({ hideOnStateChange: true });
+ Location.getAllFromCloud()
+ .then(function(response) {
+ return Location.getAll().then(function(locations) {
+ $scope.locations = locations;
+ });
+ })
+ .then(function() {
+ $scope.state.firstLoad = false;
+ $scope.$broadcast("scroll.refreshComplete");
+ $ionicLoading.hide();
+ })
+ .catch(function(res) {
+ navigator.notification.alert(
+ JSON.stringify(res),
+ null,
+ "Problem getting all locations from server",
+ "OK"
+ );
+ // $scope.$emit(denguechat.env.error, response)
+ });
+ };
- }
+ $scope.$on(denguechat.env.data.refresh, function() {
+ $scope.state.loading = true;
+ $scope.refresh();
+ });
- $scope.$watch("params.search", function(newValue, oldValue) {
- if (newValue == "" || newValue == null) {
- $scope.loadAllLocations()
- }
- })
+ $scope.showNewLocationModal = function() {
+ // Create the login modal that we will use later
+ return $ionicModal
+ .fromTemplateUrl("templates/locations/new_location.html", {
+ scope: $scope,
+ animation: "slide-in-up",
+ focusFirstInput: true,
+ backdropClickToClose: false,
+ hardwareBackButtonClose: false
+ })
+ .then(function(modal) {
+ $scope.modal = modal;
+ modal.show();
+ $scope.state.loadingGeo = true;
+ $scope.loadGeo();
+ });
+ };
+ $scope.closeNewLocationModal = function() {
+ $scope.modal.hide().then(function() {
+ $scope.modal.remove();
+ });
+ };
+ // Map modal.
+ // $scope.loadMap = function() {
+ // modal = $ionicModal.fromTemplateUrl('templates/map.html', {
+ // scope: $scope,
+ // animation: 'slide-in-up',
+ // focusFirstInput: true
+ // }).then(function(modal) {
+ // $scope.mapModal = modal;
+ // });
+ //
+ // modal.then(function() {
+ // $scope.mapModal.show();
+ // })
+ // }
+
+ // $scope.closeLogin = function() {
+ // $scope.mapModal.hide();
+ // };
+
+ $scope.create = function() {
+ if (!$scope.location.address) {
+ navigator.notification.alert(
+ "Address can't be blank",
+ null,
+ "Problem saving",
+ "OK"
+ );
+ return;
+ }
- var markers = []
- var placeMarkerAndPanTo = function(latLng) {
- for (var i = 0; i < markers.length; i++) {
- markers[i].setMap(null);
- }
- var marker = new google.maps.Marker({
- position: latLng,
- map: $scope.map
- });
- markers.push(marker)
- }
+ Location.search($scope.location.address).then(function(result) {
+ if (result.docs.length > 0) {
+ navigator.notification.alert(
+ "A location with this address already exists",
+ null,
+ "Problem saving",
+ "OK"
+ );
+ return;
+ }
+
+ $ionicLoading.show();
+ doc_id = Location.documentID($scope.user, $scope.location);
+ $scope.location.user_id = $scope.user.id;
+ $scope.location.visits = [];
+ $scope.location.questions = $scope.user.location_questionnaire;
+ Location.save(doc_id, $scope.location, {
+ remote: true,
+ synced: false
+ }).then(
+ function(response) {
+ $scope.location = {};
+
+ $ionicLoading.hide().then(function() {
+ $scope.modal.hide().then(function() {
+ $scope.modal.remove();
+ $state.go("app.location", { id: doc_id });
+ });
+ });
+ },
+ function(response) {
+ $scope.$emit(denguechat.env.error, {
+ error: "Something went wrong. Please try again."
+ });
+ $ionicLoading.hide();
+ }
+ );
+ });
+ };
- $scope.loadGeo = function() {
- // Map-related tasks
- var options = {timeout: 10000, enableHighAccuracy: true};
-
- $cordovaGeolocation.getCurrentPosition(options).then(function(position){
- $scope.location.latitude = position.coords.latitude
- $scope.location.longitude = position.coords.longitude
-
- var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
- $scope.loadMap(latLng)
- $scope.state.loadingGeo = false;
- }, function(error){
- err = JSON.stringify(error)
- navigator.notification.alert("ERROR: " + err + " | Could not get the current position. Either GPS signals are weak or GPS has been switched off", null, "GPS issues", "OK")
- $scope.state.loadingGeo = false;
+ $scope.$watch("params.search", function(newValue, oldValue) {
+ if (newValue == "" || newValue == null) {
+ $scope.loadAllLocations();
+ }
});
- }
- $scope.loadMap = function(latLng) {
- var mapOptions = {
- center: latLng,
- zoom: 15,
- mapTypeId: google.maps.MapTypeId.ROADMAP
+ var markers = [];
+ var placeMarkerAndPanTo = function(latLng) {
+ for (var i = 0; i < markers.length; i++) {
+ markers[i].setMap(null);
+ }
+ var marker = new google.maps.Marker({
+ position: latLng,
+ map: $scope.map
+ });
+ markers.push(marker);
};
- $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
- placeMarkerAndPanTo(latLng)
+ $scope.loadGeo = function() {
+ // Map-related tasks
+ var options = { timeout: 10000, enableHighAccuracy: true };
+
+ $cordovaGeolocation.getCurrentPosition(options).then(
+ function(position) {
+ $scope.location.latitude = position.coords.latitude;
+ $scope.location.longitude = position.coords.longitude;
+
+ var latLng = new google.maps.LatLng(
+ position.coords.latitude,
+ position.coords.longitude
+ );
+ $scope.loadMap(latLng);
+ $scope.state.loadingGeo = false;
+ },
+ function(error) {
+ err = JSON.stringify(error);
+ navigator.notification.alert(
+ "ERROR: " +
+ err +
+ " | Could not get the current position. Either GPS signals are weak or GPS has been switched off",
+ null,
+ "GPS issues",
+ "OK"
+ );
+ $scope.state.loadingGeo = false;
+ }
+ );
+ };
- $scope.map.addListener("click", function(e) {
- $scope.location.latitude = e.latLng.lat();
- $scope.location.longitude = e.latLng.lng();
- $scope.$apply()
- placeMarkerAndPanTo(e.latLng);
- })
+ $scope.loadMap = function(latLng) {
+ var mapOptions = {
+ center: latLng,
+ zoom: 15,
+ mapTypeId: google.maps.MapTypeId.ROADMAP
+ };
+
+ $scope.map = new google.maps.Map(
+ document.getElementById("map"),
+ mapOptions
+ );
+ placeMarkerAndPanTo(latLng);
+
+ $scope.map.addListener("click", function(e) {
+ $scope.location.latitude = e.latLng.lat();
+ $scope.location.longitude = e.latLng.lng();
+ $scope.$apply();
+ placeMarkerAndPanTo(e.latLng);
+ });
+ };
}
-
-}])
+]);
diff --git a/www/js/controllers/loginCtrl.js b/www/js/controllers/loginCtrl.js
index 3dfc57e..54857fc 100644
--- a/www/js/controllers/loginCtrl.js
+++ b/www/js/controllers/loginCtrl.js
@@ -1,57 +1,64 @@
angular
- .module('starter.controllers')
- .controller('loginCtrl', function ($scope, User, cordovaHTTP) {
- $scope.state = { loading: false, error: null }
- $scope.user = {}
+ .module("starter.controllers")
+ .controller("loginCtrl", function($scope, User, cordovaHTTP) {
+ $scope.state = { loading: false, error: null };
+ $scope.user = {};
$scope.view = "login";
- $scope.toggleTo = function (name) {
- $scope.state.error = null
- $scope.view = name
- }
+ $scope.toggleTo = function(name) {
+ $scope.state.error = null;
+ $scope.view = name;
+ };
- $scope.login = function () {
- $scope.state = { loading: true, error: null }
+ $scope.login = function() {
+ $scope.state = { loading: true, error: null };
- cordovaHTTP.acceptAllCerts(true).then(function () {
- User.session($scope.user.username, $scope.user.password).then(function (response) {
- var parsedData = JSON.parse(response.data);
- var user = parsedData.user;
- return User.save(user).then(function (doc) {
- $scope.$emit(denguechat.env.auth.success, {});
- })
- }).catch(function (res) {
- $scope.$emit(denguechat.error, res)
- }).finally(function () {
- $scope.state.loading = false;
- });
- }, function (response) {
- $scope.$emit(denguechat.error, {});
- });
+ cordovaHTTP.acceptAllCerts(true).then(
+ function() {
+ User.session($scope.user.username, $scope.user.password)
+ .then(function(response) {
+ var parsedData = JSON.parse(response.data);
+ var user = parsedData.user;
+ return User.save(user).then(function(doc) {
+ $scope.$emit(denguechat.env.auth.success, {});
+ $scope.state.loading = false;
+ });
+ })
+ .catch(function(res) {
+ $scope.$emit(denguechat.error, res);
+ $scope.state.loading = false;
+ });
+ },
+ function(response) {
+ $scope.$emit(denguechat.error, {});
+ }
+ );
};
- $scope.signup = function () {
+ $scope.signup = function() {
if ($scope.user.password != $scope.user.password_confirmation) {
- $scope.state.error = "Passwords do not match"
- return
+ $scope.state.error = "Passwords do not match";
+ return;
}
- $scope.state.loading = true
- $scope.state.error = true
+ $scope.state.loading = true;
+ $scope.state.error = true;
- User.create($scope.user.username, $scope.user.password).then(function (response) {
- console.log(JSON.stringify(response))
- response.data = JSON.parse(response.data)
- $scope.login()
- }, function (error) {
- console.log(JSON.stringify(error))
- error.data = JSON.parse(error.data)
- if (error.data.errors.username)
- $scope.state.error = "Username " + error.data.errors.username[0]
- else if (error.data.errors.password)
- $scope.state.error = "Password " + error.data.errors.password[0]
- }).finally(function () {
- $scope.state.loading = false;
- })
+ User.create($scope.user.username, $scope.user.password).then(
+ function(response) {
+ console.log(JSON.stringify(response));
+ response.data = JSON.parse(response.data);
+ $scope.login();
+ $scope.state.loading = false;
+ },
+ function(error) {
+ error.data = JSON.parse(error.data);
+ if (error.data.errors.username)
+ $scope.state.error = "Username " + error.data.errors.username[0];
+ else if (error.data.errors.password)
+ $scope.state.error = "Password " + error.data.errors.password[0];
+ $scope.state.loading = false;
+ }
+ );
};
});
diff --git a/www/js/controllers/postsCtrl.js b/www/js/controllers/postsCtrl.js
index 2f4ca24..d881369 100644
--- a/www/js/controllers/postsCtrl.js
+++ b/www/js/controllers/postsCtrl.js
@@ -1,147 +1,158 @@
-angular.module('starter.controllers')
-.controller('postsCtrl', ['$scope', 'Post', "$ionicModal", "$ionicLoading", "User", function($scope, Post, $ionicModal, $ionicLoading, User) {
- $scope.state = {loading: false, hasMoreData: false};
- $scope.posts = [];
- $scope.post = {};
+angular.module("starter.controllers").controller("postsCtrl", [
+ "$scope",
+ "Post",
+ "$ionicModal",
+ "$ionicLoading",
+ "User",
+ function($scope, Post, $ionicModal, $ionicLoading, User) {
+ $scope.state = { loading: false, hasMoreData: false };
+ $scope.posts = [];
+ $scope.post = {};
+
+ // Triggered only once when the view is loaded.
+ // http://ionicframework.com/docs/api/directive/ionView/
+ $scope.$on("$ionicView.loaded", function() {
+ $ionicLoading.show({
+ template: "
Cargando los posts...",
+ hideOnStateChange: true
+ });
- // Triggered only once when the view is loaded.
- // http://ionicframework.com/docs/api/directive/ionView/
- $scope.$on("$ionicView.loaded", function() {
- $ionicLoading.show({template: "
Cargando los posts...", hideOnStateChange: true})
-
- User.get().then(function(user) {
- $scope.post.user_id = user.id
- $scope.post.user = user
- $scope.post.neighborhood_id = user.neighborhood.id
- })
-
- Post.getAll().then(function(posts) {
- $scope.posts = posts
- }).catch(function(res) {
- $scope.$emit(denguechat.error, res)
- }).finally(function() {
- $ionicLoading.hide()
- })
- })
-
- $scope.toggleLike = function(post) {
- Post.like(post)
- }
-
- $scope.refresh = function(offset) {
- $ionicLoading.show({template: "
Cargando los posts de denguechat.com...", hideOnStateChange: true})
-
- Post.getFromCloud(20, offset).then(function(response) {
- // Posts from cloud are insertedin couchDB in the getFromCloud callback
- return Post.getAll().then(function(posts) {
- $scope.posts = posts
- $scope.$broadcast('scroll.refreshComplete');
- $ionicLoading.hide()
- })
-
- }).catch(function(res) {
- $ionicLoading.hide()
- $scope.$emit(denguechat.env.error, res)
- })
- }
-
- $scope.loadMore = function() {
- offset = $scope.posts.length
- $scope.refresh(offset)
- }
-
- $scope.showNewPostModal = function() {
- // Create the login modal that we will use later
- return $ionicModal.fromTemplateUrl('templates/posts/new.html', {
- scope: $scope,
- animation: 'slide-in-up',
- focusFirstInput: true,
- backdropClickToClose: false,
- hardwareBackButtonClose: false
- }).then(function(modal) {
- $scope.modal = modal;
- modal.show()
+ User.get().then(function(user) {
+ $scope.post.user_id = user.id;
+ $scope.post.user = user;
+ $scope.post.neighborhood_id = user.neighborhood.id;
+ });
+
+ Post.getAll()
+ .then(function(posts) {
+ $scope.posts = posts;
+ $ionicLoading.hide();
+ })
+ .catch(function(res) {
+ $scope.$emit(denguechat.error, res);
+ $ionicLoading.hide();
+ });
});
- }
-
- // $scope.showCommentsModal = function(post) {
- // return $ionicModal.fromTemplateUrl('templates/posts/comments.html', {
- // scope: $scope,
- // animation: 'slide-in-up'
- // }).then(function(modal) {
- // $scope.modal = modal;
- // return modal.show()
- // }).then(function() {
- // $ionicScrollDelegate.$getByHandle('commentContent').scrollBottom()
- // $scope.status_update = post
- // })
- // }
- $scope.closeModal = function() {
- $scope.post = {}
- if ($scope.modal) {
- $scope.modal.hide().then(function() {
- $scope.modal.remove();
- })
- }
- }
-
- $scope.loadCamera = function() {
- if (navigator.camera) {
- navigator.camera.getPicture(function(base64) {
- $scope.post.photo = "data:image/jpeg;base64," + base64
- $scope.$apply()
- }, function(response) {
- }, {saveToPhotoAlbum: true, destinationType: 0})
- } else {
- alert("Camera not supported!")
- }
- }
-
- $scope.createPost = function() {
- $ionicLoading.show({template: "
Creando post...", hideOnStateChange: true})
- $scope.post.created_at = new Date()
- if (!$scope.post.user || !$scope.post.user.id) {
- User.get().then(function(user) {
- $scope.post.user_id = user.id
- $scope.post.user = user
- $scope.post.neighborhood_id = user.neighborhood.id
- doc_id = Post.documentID($scope.post.user, $scope.post)
- Post.save(doc_id, $scope.post, {remote: true, synced: false}).then(function(response) {
- return Post.get(doc_id).then(function(doc) {
- $scope.posts.unshift(doc)
- $scope.post = {};
- $ionicLoading.hide().then(function() {
- $scope.closeModal()
- })
- })
- }).catch(function(res) {
- $scope.$emit(denguechat.error, res)
- }).finally(function() {
- $ionicLoading.hide()
+ $scope.toggleLike = function(post) {
+ Post.like(post);
+ };
+
+ $scope.refresh = function(offset) {
+ $ionicLoading.show({
+ template:
+ "
Cargando los posts de denguechat.com...",
+ hideOnStateChange: true
+ });
+
+ Post.getFromCloud(20, offset)
+ .then(function(response) {
+ // Posts from cloud are insertedin couchDB in the getFromCloud callback
+ return Post.getAll().then(function(posts) {
+ $scope.posts = posts;
+ $scope.$broadcast("scroll.refreshComplete");
+ $ionicLoading.hide();
+ });
})
- })
- } else {
- doc_id = Post.documentID($scope.post.user, $scope.post)
- Post.save(doc_id, $scope.post, {remote: true, synced: false}).then(function(response) {
- return Post.get(doc_id).then(function(doc) {
- $scope.posts.unshift(doc)
- $scope.post = {};
- $ionicLoading.hide().then(function() {
- $scope.closeModal()
- })
+ .catch(function(res) {
+ $ionicLoading.hide();
+ $scope.$emit(denguechat.env.error, res);
+ });
+ };
+
+ $scope.loadMore = function() {
+ offset = $scope.posts.length;
+ $scope.refresh(offset);
+ };
+
+ $scope.showNewPostModal = function() {
+ // Create the login modal that we will use later
+ return $ionicModal
+ .fromTemplateUrl("templates/posts/new.html", {
+ scope: $scope,
+ animation: "slide-in-up",
+ focusFirstInput: true,
+ backdropClickToClose: false,
+ hardwareBackButtonClose: false
})
- }).catch(function(res) {
- $scope.$emit(denguechat.error, res)
- }).finally(function() {
- $ionicLoading.hide()
- })
- }
+ .then(function(modal) {
+ $scope.modal = modal;
+ modal.show();
+ });
+ };
+
+ $scope.closeModal = function() {
+ $scope.post = {};
+ if ($scope.modal) {
+ $scope.modal.hide().then(function() {
+ $scope.modal.remove();
+ });
+ }
+ };
+
+ $scope.loadCamera = function() {
+ if (navigator.camera) {
+ navigator.camera.getPicture(
+ function(base64) {
+ $scope.post.photo = "data:image/jpeg;base64," + base64;
+ $scope.$apply();
+ },
+ function(response) {},
+ { saveToPhotoAlbum: true, destinationType: 0 }
+ );
+ } else {
+ alert("Camera not supported!");
+ }
+ };
+
+ $scope.createPost = function() {
+ $ionicLoading.show({
+ template: "
Creando post...",
+ hideOnStateChange: true
+ });
+ $scope.post.created_at = new Date();
+ if (!$scope.post.user || !$scope.post.user.id) {
+ User.get().then(function(user) {
+ $scope.post.user_id = user.id;
+ $scope.post.user = user;
+ $scope.post.neighborhood_id = user.neighborhood.id;
+ doc_id = Post.documentID($scope.post.user, $scope.post);
+ Post.save(doc_id, $scope.post, { remote: true, synced: false })
+ .then(function(response) {
+ return Post.get(doc_id).then(function(doc) {
+ $scope.posts.unshift(doc);
+ $scope.post = {};
+ $ionicLoading.hide().then(function() {
+ $scope.closeModal();
+ });
+ });
+ })
+ .catch(function(res) {
+ $scope.$emit(denguechat.error, res);
+ $ionicLoading.hide();
+ });
+ });
+ } else {
+ doc_id = Post.documentID($scope.post.user, $scope.post);
+ Post.save(doc_id, $scope.post, { remote: true, synced: false })
+ .then(function(response) {
+ return Post.get(doc_id).then(function(doc) {
+ $scope.posts.unshift(doc);
+ $scope.post = {};
+ $ionicLoading.hide().then(function() {
+ $scope.closeModal();
+ });
+ });
+ })
+ .catch(function(res) {
+ $scope.$emit(denguechat.error, res);
+ $ionicLoading.hide();
+ });
+ }
+ };
+
+ $scope.$on(denguechat.env.data.refresh, function() {
+ $scope.refresh(0);
+ });
}
-
-
- $scope.$on(denguechat.env.data.refresh, function() {
- $scope.refresh(0);
- })
-
-}])
+]);
diff --git a/www/js/controllers/profileCtrl.js b/www/js/controllers/profileCtrl.js
index 9b63a44..b4ab11b 100644
--- a/www/js/controllers/profileCtrl.js
+++ b/www/js/controllers/profileCtrl.js
@@ -1,39 +1,60 @@
-angular.module('starter.controllers')
-.controller('profileCtrl', function($scope, User, $ionicLoading, $cordovaCamera) {
- $scope.user_data = {}
- $ionicLoading.show({hideOnStateChange: true})
+angular
+ .module("starter.controllers")
+ .controller("profileCtrl", function(
+ $scope,
+ User,
+ $ionicLoading,
+ $cordovaCamera
+ ) {
+ $scope.user_data = {};
+ $ionicLoading.show({ hideOnStateChange: true });
- User.current().then(function(user) {
- user.data = JSON.parse(user.data)
- $scope.user = user.data.user;
- return User.save(user.data.user)
- }).catch(function(res) {
- console.log("Error when getting current user: "+JSON.stringify(res))
- $scope.$emit(denguechat.error, res)
- }).finally(function() {
- $ionicLoading.hide()
- })
-
- $scope.loadCamera = function() {
- $cordovaCamera.getPicture({saveToPhotoAlbum: false, quality: 50, allowEdit: true, correctOrientation: true, targetWidth: 500, targetHeight: 500, destinationType: 0}).then(function(base64) {
- $scope.$applyAsync(function() {
- $scope.user.picture = "data:image/jpeg;base64," + base64
+ User.current()
+ .then(function(user) {
+ user.data = JSON.parse(user.data);
+ $scope.user = user.data.user;
+ $ionicLoading.hide();
+ return User.save(user.data.user);
})
- }).catch(function(res) {
- navigator.notification.alert("Something went wrong!", null)
- $scope.$emit(denguechat.error, res)
- })
- }
+ .catch(function(res) {
+ console.log("Error when getting current user: " + JSON.stringify(res));
+ $scope.$emit(denguechat.error, res);
+ $ionicLoading.hide();
+ });
+
+ $scope.loadCamera = function() {
+ $cordovaCamera
+ .getPicture({
+ saveToPhotoAlbum: false,
+ quality: 50,
+ allowEdit: true,
+ correctOrientation: true,
+ targetWidth: 500,
+ targetHeight: 500,
+ destinationType: 0
+ })
+ .then(function(base64) {
+ $scope.$applyAsync(function() {
+ $scope.user.picture = "data:image/jpeg;base64," + base64;
+ });
+ })
+ .catch(function(res) {
+ navigator.notification.alert("Something went wrong!", null);
+ $scope.$emit(denguechat.error, res);
+ });
+ };
- $scope.update = function() {
- $ionicLoading.show({hideOnStateChange: true})
+ $scope.update = function() {
+ $ionicLoading.show({ hideOnStateChange: true });
- User.update($scope.user).catch(function(res) {
- $scope.$emit(denguechat.error, res)
- }).catch(function(res) {
- $scope.$emit(denguechat.error, res)
- }).finally(function() {
- $ionicLoading.hide()
- })
- }
-})
+ User.update($scope.user)
+ .catch(function(res) {
+ $scope.$emit(denguechat.error, res);
+ $ionicLoading.hide();
+ })
+ .catch(function(res) {
+ $scope.$emit(denguechat.error, res);
+ $ionicLoading.hide();
+ });
+ };
+ });
diff --git a/www/js/controllers/questionsCtrl.js b/www/js/controllers/questionsCtrl.js
index 847d507..c36030d 100644
--- a/www/js/controllers/questionsCtrl.js
+++ b/www/js/controllers/questionsCtrl.js
@@ -1,22 +1,29 @@
-angular.module('starter.controllers')
-.controller('questionsCtrl', ['$scope', "$state", 'Location', '$ionicLoading', function($scope, $state, Location, $ionicLoading) {
- $scope.location = {};
- $scope.questions = [];
+angular.module("starter.controllers").controller("questionsCtrl", [
+ "$scope",
+ "$state",
+ "Location",
+ "$ionicLoading",
+ function($scope, $state, Location, $ionicLoading) {
+ $scope.location = {};
+ $scope.questions = [];
- $scope.refresh = function() {
- $ionicLoading.show().then(function() {
- LocationQuiz.questions().then(function(response) {
- $scope.questions = response.data.questions
- console.log($scope.questions[0])
- }, function(response) {
- $scope.$emit(denguechat.env.error, {error: response})
- }).finally(function() {
- $ionicLoading.hide();
+ $scope.refresh = function() {
+ $ionicLoading.show().then(function() {
+ LocationQuiz.questions().then(
+ function(response) {
+ $scope.questions = response.data.questions;
+ $ionicLoading.hide();
+ },
+ function(response) {
+ $scope.$emit(denguechat.env.error, { error: response });
+ $ionicLoading.hide();
+ }
+ );
});
- })
- }
+ };
- $scope.$on("$ionicView.loaded", function() {
- $scope.refresh();
- })
-}])
+ $scope.$on("$ionicView.loaded", function() {
+ $scope.refresh();
+ });
+ }
+]);
diff --git a/www/js/controllers/visitCtrl.js b/www/js/controllers/visitCtrl.js
index 17be053..8675ed1 100644
--- a/www/js/controllers/visitCtrl.js
+++ b/www/js/controllers/visitCtrl.js
@@ -1,151 +1,202 @@
-angular.module('starter.controllers')
-.controller('visitCtrl', ['$scope', '$state', 'Visit', "$ionicModal", "$ionicLoading", "Inspection", "User", "$cordovaCamera", "$ionicSlideBoxDelegate", "Questionnaire", function($scope, $state, Visit, $ionicModal, $ionicLoading, Inspection, User, $cordovaCamera, $ionicSlideBoxDelegate, Questionnaire) {
- $scope.visit = {};
- $scope.inspection = {};
- $scope.inspections = [];
- $scope.state = {pageIndex: 0};
-
- $scope.$on("$ionicView.loaded", function() {
- // alert("LOADED")
- $ionicLoading.show({hideOnStateChange: true})
-
- User.get().then(function(user) {
- $scope.breeding_sites = user.breeding_sites
- });
-
- Visit.get($state.params.visit_id).then(function(response) {
- $scope.visit = response
-
- if ($scope.visit.visited_at)
- $scope.visit.visited_at = new Date($scope.visit.visited_at)
-
- $scope.inspection.visit = {id: response.id, pouchdb_id: response._id}
-
- if (!response.inspections || response.inspections.length == 0) {
- $scope.inspections = []
- $ionicLoading.hide()
- } else {
- Inspection.getAll(response.inspections).then(function(inspections) {
- $ionicLoading.hide()
- $scope.inspections = inspections
-
- _.each($scope.inspections, function(ins) {
- ins.color = Inspection.color(ins)
- })
-
- $scope.$apply()
+angular.module("starter.controllers").controller("visitCtrl", [
+ "$scope",
+ "$state",
+ "Visit",
+ "$ionicModal",
+ "$ionicLoading",
+ "Inspection",
+ "User",
+ "$cordovaCamera",
+ "$ionicSlideBoxDelegate",
+ "Questionnaire",
+ function(
+ $scope,
+ $state,
+ Visit,
+ $ionicModal,
+ $ionicLoading,
+ Inspection,
+ User,
+ $cordovaCamera,
+ $ionicSlideBoxDelegate,
+ Questionnaire
+ ) {
+ $scope.visit = {};
+ $scope.inspection = {};
+ $scope.inspections = [];
+ $scope.state = { pageIndex: 0 };
+
+ $scope.$on("$ionicView.loaded", function() {
+ // alert("LOADED")
+ $ionicLoading.show({ hideOnStateChange: true });
+
+ User.get().then(function(user) {
+ $scope.breeding_sites = user.breeding_sites;
+ });
+
+ Visit.get($state.params.visit_id)
+ .then(function(response) {
+ $scope.visit = response;
+
+ if ($scope.visit.visited_at)
+ $scope.visit.visited_at = new Date($scope.visit.visited_at);
+
+ $scope.inspection.visit = {
+ id: response.id,
+ pouchdb_id: response._id
+ };
+
+ if (!response.inspections || response.inspections.length == 0) {
+ $scope.inspections = [];
+ $ionicLoading.hide();
+ } else {
+ Inspection.getAll(response.inspections).then(function(inspections) {
+ $ionicLoading.hide();
+ $scope.inspections = inspections;
+
+ _.each($scope.inspections, function(ins) {
+ ins.color = Inspection.color(ins);
+ });
+
+ $scope.$apply();
+ });
+ }
})
- }
- }).catch(function(response) {
- $scope.$emit(denguechat.error, {error: response})
- })
- })
-
- $scope.shouldDisplay = function(q) {
- return Questionnaire.shouldDisplay(q, $scope.visit.questions)
- }
-
-
- $scope.saveQuestions = function() {
- $ionicLoading.show({hideOnStateChange: true})
- Visit.save($state.params.visit_id, $scope.visit, {remote: false}).then(function(response) {
- $ionicLoading.hide()
- $scope.transitionToPageIndex(0)
- })
- }
-
- $scope.showNewInspectionModal = function() {
- // Create the login modal that we will use later
- return $ionicModal.fromTemplateUrl('templates/inspections/new.html', {
- scope: $scope,
- animation: 'slide-in-up',
- focusFirstInput: true,
- backdropClickToClose: false,
- hardwareBackButtonClose: false
- }).then(function(modal) {
- $scope.modal = modal;
- modal.show()
+ .catch(function(response) {
+ $scope.$emit(denguechat.error, { error: response });
+ });
});
- }
- $scope.closeNewInspectionModal = function() {
- $scope.modal.hide().then(function() {
- $scope.modal.remove();
- })
- }
-
- $scope.createInspection = function() {
- $ionicLoading.show({hideOnStateChange: true})
-
- console.log("Saving inspection...")
-
- $scope.inspection.created_at = (new Date()).toISOString()
- $scope.inspection.color = Inspection.color($scope.inspection)
- $scope.inspection.position = $scope.inspections.length + 1
- $scope.inspection.questions = $scope.user.visit_questionnaire
-
- console.log("About to save inspection:")
- console.log(JSON.stringify($scope.inspection))
-
- doc_id = Inspection.documentID($state.params.id, $state.params.visit_id, $scope.inspection)
- console.log("DOC ID created: " + doc_id)
- Inspection.save(doc_id, $scope.inspection, {remote: true, synced: false}).then(function(response) {
- console.log("Saved!")
-
- $scope.inspection._id = doc_id
- $scope.inspections.push($scope.inspection)
-
- if (!$scope.visit.inspections || $scope.visit.inspections.length == 0) {
- $scope.visit.inspections = [doc_id]
+ $scope.shouldDisplay = function(q) {
+ return Questionnaire.shouldDisplay(q, $scope.visit.questions);
+ };
+
+ $scope.saveQuestions = function() {
+ $ionicLoading.show({ hideOnStateChange: true });
+ Visit.save($state.params.visit_id, $scope.visit, {
+ remote: false
+ }).then(function(response) {
+ $ionicLoading.hide();
+ $scope.transitionToPageIndex(0);
+ });
+ };
+
+ $scope.showNewInspectionModal = function() {
+ // Create the login modal that we will use later
+ return $ionicModal
+ .fromTemplateUrl("templates/inspections/new.html", {
+ scope: $scope,
+ animation: "slide-in-up",
+ focusFirstInput: true,
+ backdropClickToClose: false,
+ hardwareBackButtonClose: false
+ })
+ .then(function(modal) {
+ $scope.modal = modal;
+ modal.show();
+ });
+ };
+
+ $scope.closeNewInspectionModal = function() {
+ $scope.modal.hide().then(function() {
+ $scope.modal.remove();
+ });
+ };
+
+ $scope.createInspection = function() {
+ $ionicLoading.show({ hideOnStateChange: true });
+
+ console.log("Saving inspection...");
+
+ $scope.inspection.created_at = new Date().toISOString();
+ $scope.inspection.color = Inspection.color($scope.inspection);
+ $scope.inspection.position = $scope.inspections.length + 1;
+ $scope.inspection.questions = $scope.user.visit_questionnaire;
+
+ console.log("About to save inspection:");
+ console.log(JSON.stringify($scope.inspection));
+
+ doc_id = Inspection.documentID(
+ $state.params.id,
+ $state.params.visit_id,
+ $scope.inspection
+ );
+ console.log("DOC ID created: " + doc_id);
+ Inspection.save(doc_id, $scope.inspection, {
+ remote: true,
+ synced: false
+ }).then(
+ function(response) {
+ console.log("Saved!");
+
+ $scope.inspection._id = doc_id;
+ $scope.inspections.push($scope.inspection);
+
+ if (
+ !$scope.visit.inspections ||
+ $scope.visit.inspections.length == 0
+ ) {
+ $scope.visit.inspections = [doc_id];
+ } else {
+ $scope.visit.inspections.push(doc_id);
+ }
+
+ console.log("Saving Visit...");
+ Visit.save($state.params.visit_id, $scope.visit, {
+ remote: false
+ }).then(
+ function(res) {
+ console.log("Visit saved!");
+ $scope.inspection = {};
+
+ $ionicLoading.hide().then(function() {
+ console.log("Close inspection modal...");
+ $scope.closeNewInspectionModal();
+ });
+ },
+ function(err) {
+ console.log("Error saving visit: ");
+ console.log(JSON.stringify(err));
+ }
+ );
+ },
+ function(err) {
+ console.log("Error saving Inspection:");
+ console.log(JSON.stringify(err));
+ }
+ );
+ };
+
+ $scope.loadCamera = function() {
+ // $cordovaCamera.getPicture({saveToPhotoAlbum: true, quality: 50, allowEdit: true, correctOrientation: true, targetWidth: 750, targetHeight: 750, destinationType: 0}).then(function(base64) {
+ // $scope.inspection.report.before_photo = "data:image/jpeg;base64," + base64
+ // }).catch(function(res) {
+ // navigator.notification.alert(JSON.stringify(res), null)
+ // $scope.$emit(clovi.env.error, res)
+ // })
+ if (navigator.camera) {
+ navigator.camera.getPicture(
+ function(base64) {
+ $scope.inspection.before_photo = "data:image/jpeg;base64," + base64;
+ $scope.$apply();
+ },
+ function(res) {
+ $scope.$emit(denguechat.error, res);
+ },
+ { saveToPhotoAlbum: true, destinationType: 0 }
+ );
} else {
- $scope.visit.inspections.push(doc_id)
+ alert("Camera not supported!");
}
+ };
- console.log("Saving Visit...")
- Visit.save($state.params.visit_id, $scope.visit, {remote: false}).then(function(res) {
- console.log("Visit saved!")
- $scope.inspection = {};
-
- $ionicLoading.hide().then(function() {
- console.log("Close inspection modal...")
- $scope.closeNewInspectionModal()
- })
- }, function(err) {
- console.log("Error saving visit: ")
- console.log(JSON.stringify(err))
- })
- }, function(err) {
- console.log("Error saving Inspection:")
- console.log(JSON.stringify(err))
- })
- }
-
- $scope.loadCamera = function() {
- // $cordovaCamera.getPicture({saveToPhotoAlbum: true, quality: 50, allowEdit: true, correctOrientation: true, targetWidth: 750, targetHeight: 750, destinationType: 0}).then(function(base64) {
- // $scope.inspection.report.before_photo = "data:image/jpeg;base64," + base64
- // }).catch(function(res) {
- // navigator.notification.alert(JSON.stringify(res), null)
- // $scope.$emit(clovi.env.error, res)
- // })
- if (navigator.camera) {
- navigator.camera.getPicture(function(base64) {
- $scope.inspection.before_photo = "data:image/jpeg;base64," + base64
- $scope.$apply()
- }, function(res) {
- $scope.$emit(denguechat.error, res)
- }, {saveToPhotoAlbum: true, destinationType: 0})
- } else {
- alert("Camera not supported!")
- }
- }
-
-
- $scope.changeTimeline = function(pageIndex) {
- $scope.state.pageIndex = pageIndex
- }
+ $scope.changeTimeline = function(pageIndex) {
+ $scope.state.pageIndex = pageIndex;
+ };
- $scope.transitionToPageIndex = function(pageIndex) {
- $scope.state.pageIndex = pageIndex
- $ionicSlideBoxDelegate.slide(pageIndex);
+ $scope.transitionToPageIndex = function(pageIndex) {
+ $scope.state.pageIndex = pageIndex;
+ $ionicSlideBoxDelegate.slide(pageIndex);
+ };
}
-}] )
+]);
diff --git a/www/js/controllers/visitsCtrl.js b/www/js/controllers/visitsCtrl.js
index f0d467b..d14cb69 100644
--- a/www/js/controllers/visitsCtrl.js
+++ b/www/js/controllers/visitsCtrl.js
@@ -1,47 +1,57 @@
-angular.module('starter.controllers')
-.controller('visitsCtrl', ['$scope', 'Visit', function($scope, Visit) {
- $scope.visits = [];
- $scope.state = {firstLoad: true};
- $scope.params = {search: ""};
+angular.module("starter.controllers").controller("visitsCtrl", [
+ "$scope",
+ "Visit",
+ function($scope, Visit) {
+ $scope.visits = [];
+ $scope.state = { firstLoad: true };
+ $scope.params = { search: "" };
- $scope.searchByDate = function() {
- $scope.visits = []
- $scope.state.loading = true
- Visit.search($scope.params.search).then(function(response) {
- response.data = JSON.parse(response.data);
- $scope.visits = response.data.visits
- }, function(response) {
- $scope.$emit(denguechat.env.error, {error: response})
- }).finally(function() {
- $scope.state.loading = false;
- });
- }
+ $scope.searchByDate = function() {
+ $scope.visits = [];
+ $scope.state.loading = true;
+ Visit.search($scope.params.search).then(
+ function(response) {
+ response.data = JSON.parse(response.data);
+ $scope.visits = response.data.visits;
+ $scope.state.loading = false;
+ },
+ function(response) {
+ $scope.$emit(denguechat.env.error, { error: response });
+ $scope.state.loading = false;
+ }
+ );
+ };
- $scope.refresh = function() {
- Visit.getAll().then(function(response) {
- $scope.visits = response.data.visits
- }, function(response) {
- $scope.$emit(denguechat.env.error, {error: response})
- }).finally(function() {
- $scope.state.firstLoad = false;
- $scope.$broadcast('scroll.refreshComplete');
- });
- }
+ $scope.refresh = function() {
+ Visit.getAll().then(
+ function(response) {
+ $scope.visits = response.data.visits;
+ $scope.state.firstLoad = false;
+ $scope.$broadcast("scroll.refreshComplete");
+ },
+ function(response) {
+ $scope.$emit(denguechat.env.error, { error: response });
+ $scope.state.firstLoad = false;
+ $scope.$broadcast("scroll.refreshComplete");
+ }
+ );
+ };
- $scope.$on(denguechat.env.data.refresh, function() {
- $scope.state.firstLoad = true
- $scope.refresh();
- })
+ $scope.$on(denguechat.env.data.refresh, function() {
+ $scope.state.firstLoad = true;
+ $scope.refresh();
+ });
- // Triggered only once when the view is loaded.
- // http://ionicframework.com/docs/api/directive/ionView/
- $scope.$on("$ionicView.loaded", function() {
- $scope.refresh();
- })
+ // Triggered only once when the view is loaded.
+ // http://ionicframework.com/docs/api/directive/ionView/
+ $scope.$on("$ionicView.loaded", function() {
+ $scope.refresh();
+ });
- $scope.$watch("params.search", function(newValue, oldValue) {
- if (newValue == "" || newValue == null) {
- $scope.refresh()
- }
- })
-}])
+ $scope.$watch("params.search", function(newValue, oldValue) {
+ if (newValue == "" || newValue == null) {
+ $scope.refresh();
+ }
+ });
+ }
+]);