Skip to content

Commit

Permalink
Merge pull request #699 from ushahidi/698-create-post-view-route
Browse files Browse the repository at this point in the history
adding route for /views/create
  • Loading branch information
rjmackay authored Jul 28, 2017
2 parents d3221c1 + ee95e49 commit 6ab0426
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/common/services/mainsheet.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function MainsheetService($rootScope, $q) {
}

function setState(open) {
$rootScope.$emit('mainsheet:statechange');
isOpen = open;
}
}
1 change: 1 addition & 0 deletions app/main/posts/posts-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ angular.module('ushahidi.posts', [])
.directive('postView', require('./views/post-view.directive.js'))
.directive('postViewList', require('./views/post-view-list.directive.js'))
.directive('postViewMap', require('./views/post-view-map.directive.js'))
.directive('postViewCreate', require('./views/post-view-create.directive.js'))
.directive('postCard', require('./views/post-card.directive.js'))
.directive('postPreviewMedia', require('./views/post-preview-media.directive.js'))
.directive('addPostButton', require('./views/add-post-button.directive.js'))
Expand Down
43 changes: 43 additions & 0 deletions app/main/posts/views/post-view-create.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = PostViewCreate;

PostViewCreate.$inject = [];

function PostViewCreate() {
return {
restrict: 'E',
replace: true,
scope: {},
controller: PostViewCreateController
};
}
PostViewCreateController.$inject = ['$rootScope', '$scope', 'PostSurveyService', 'MainsheetService', '$location', 'Notify'];

function PostViewCreateController($rootScope, $scope, PostSurveyService, MainsheetService, $location, Notify) {
// resetting path to map-view when mainsheet-modal is closed
$rootScope.$on('mainsheet:statechange', function () {
if (MainsheetService.getState() && $location.path() === '/views/create') {
$location.path('/views/map');
}
});

activate();
function activate() {
PostSurveyService
.allowedSurveys()
.then(function (forms) {
$scope.forms = forms;
if (forms.length > 0) {
$scope.disabled = false;
}
if ($scope.forms.length === 1) {
$location.path('/posts/create/' + $scope.forms[0].id);
} else {
MainsheetService.openTemplate(
'<add-post-survey-list></add-post-survey-list>', 'app.submit_response', $scope
);
}
}, function (errorResponse) {
Notify.apiErrors(errorResponse);
});
}
}
4 changes: 4 additions & 0 deletions app/main/posts/views/post-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
<!-- list view -->
<post-view-list ng-switch-when="list" is-loading="isLoading" filters="filters"></post-view-list>

<!-- create view -->
<post-view-create ng-switch-when="create"></post-view-create>

<!-- unavailable view -->
<post-view-unavailable ng-switch-when="unavailable" view="unavailableView"></post-view-unavailable>


<!-- default view -->
<post-view-map ng-switch-default is-loading="isLoading" filters="filters"></post-view-map>
</div>
Expand Down

0 comments on commit 6ab0426

Please sign in to comment.