-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
314 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Source/Qvision.Umbraco.PollIt/Client/backoffice/overlays/picker/picker.overlay.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function PickerOverlayController($scope, pollItResource) { | ||
|
||
$scope.isLoading = true; | ||
$scope.content = { questions: [], error: null } | ||
|
||
pollItResource.getQuestions().then(function (result) { | ||
$scope.content.questions = result.data; | ||
$scope.isLoading = false; | ||
}, function () { | ||
$scope.content.error = "An Error has occured while loading!"; | ||
$scope.isLoading = false; | ||
}); | ||
|
||
if (!$scope.model.selection) { | ||
$scope.model.selection = []; | ||
} | ||
|
||
$scope.pickPoll = function (question) { | ||
$scope.model.selection.push(question); | ||
$scope.model.submit($scope.model); | ||
} | ||
} | ||
|
||
angular.module("umbraco").controller("PollIt.PickerOverlayController", PickerOverlayController); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
Source/Qvision.Umbraco.PollIt/Client/backoffice/poll/delete.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 25 additions & 106 deletions
131
Source/Qvision.Umbraco.PollIt/Client/backoffice/poll/edit.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,142 +1,61 @@ | ||
function EditController($scope, $routeParams, $filter, $location, navigationService, editorState, formHelper, localizationService, pollItResource) { | ||
$scope.page = { loading: false, create: true, tabs: [{ id: 1, label: localizationService.localize("pollIt_tabContent") }, { id: 2, label: localizationService.localize("pollIt_tabResponses") }] }; | ||
$scope.content = { question: {}, answers: [], answer: { value: '', hasError: false }, responses: [] }; | ||
$scope.config = { | ||
datePicker: { | ||
pickDate: true, | ||
pickTime: true, | ||
useSeconds: false, | ||
useMinutes: false, | ||
format: "YYYY-MM-DD HH:mm:ss", | ||
icons: { | ||
time: "icon-time", | ||
date: "icon-calendar", | ||
up: "icon-chevron-up", | ||
down: "icon-chevron-down", | ||
today: "icon-locate" | ||
} | ||
} | ||
} | ||
$scope.page = { loading: false }; | ||
$scope.model = { question: { answers: [] } }; | ||
|
||
$scope.page.navigation = [ | ||
{ | ||
"name": localizationService.localize("pollIt_tabContent"), | ||
"icon": "icon-document", | ||
"view": "/app_plugins/pollit/backoffice/poll/subviews/content/content.html", | ||
"active": true | ||
}, { | ||
"name": localizationService.localize("pollIt_tabResponses"), | ||
"icon": "icon-poll", | ||
"view": "/app_plugins/pollit/backoffice/poll/subviews/responses/responses.html" | ||
}]; | ||
|
||
$scope.startDatePicker = { view: 'datepicker', value: null, config: $.extend({}, $scope.config.datePicker) }; | ||
$scope.endDatePicker = { view: 'datepicker', value: null, config: $.extend({}, $scope.config.datePicker) }; | ||
|
||
if (!$routeParams.create) { | ||
$scope.page.isLoading = true; | ||
$scope.page.create = false; | ||
|
||
pollItResource.getQuestionById($routeParams.id).then(function (result) { | ||
$scope.content.question = result.data; | ||
|
||
$scope.startDatePicker.value = $scope.content.question.startDate; | ||
$scope.endDatePicker.value = $scope.content.question.endDate; | ||
$scope.model.question = result.data; | ||
|
||
//set a shared state | ||
editorState.set($scope.content.question); | ||
editorState.set($scope.model.question); | ||
|
||
$scope.page.isLoading = false; | ||
pollItResource.getQuestionAnswersById($routeParams.id).then(function (result) { | ||
$scope.model.question.answers = $filter('orderBy')(result.data, 'index'); | ||
$scope.page.isLoading = false; | ||
}); | ||
});; | ||
|
||
pollItResource.getQuestionAnswersById($routeParams.id).then(function (result) { | ||
$scope.content.answers = $filter('orderBy')(result.data, 'index'); | ||
}); | ||
|
||
pollItResource.getQuestionResponsesById($routeParams.id).then(function (result) { | ||
$scope.content.responses = result.data; | ||
}); | ||
} | ||
|
||
$scope.getResponsesPercentage = function (id) { | ||
var amount = $filter('filter')($scope.content.responses, { answerId: id }).length; | ||
return amount > 0 ? Math.round(amount / $scope.content.responses.length * 100) : 0; | ||
} | ||
|
||
$scope.getResponses = function (id) { | ||
return $filter('filter')($scope.content.responses, { answerId: id }).length; | ||
} | ||
|
||
$scope.$watch('startDatePicker', function () { | ||
if ($scope.startDatePicker != undefined) { | ||
$scope.content.question.startDate = $scope.startDatePicker.value; | ||
} | ||
}, true); | ||
|
||
$scope.$watch('endDatePicker', function () { | ||
if ($scope.endDatePicker != undefined) { | ||
$scope.content.question.endDate = $scope.endDatePicker.value; | ||
} | ||
}, true); | ||
|
||
$scope.save = function () { | ||
if (formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) { | ||
$scope.page.saveButtonState = "busy"; | ||
|
||
pollItResource.saveQuestion($scope.content.question).then(function (result) { | ||
pollItResource.saveQuestion($scope.model.question).then(function (result) { | ||
formHelper.resetForm({ scope: $scope }); | ||
|
||
$scope.page.saveButtonState = "success"; | ||
|
||
$scope.content.question = result.data; | ||
$scope.model.question = result.data; | ||
|
||
//set a shared state | ||
editorState.set($scope.content.question); | ||
editorState.set($scope.model.question); | ||
|
||
navigationService.syncTree({ tree: 'poll', path: ['-1', $scope.content.question.id.toString()], forceReload: true, activate: true }); | ||
navigationService.syncTree({ tree: 'poll', path: ['-1', $scope.model.question.id.toString()], forceReload: true, activate: true }); | ||
|
||
if ($scope.page.create) { | ||
$scope.page.create = false; | ||
$location.url("/pollIt/poll/edit/" + $scope.content.question.id); | ||
$location.url("/pollIt/poll/edit/" + $scope.model.question.id); | ||
} | ||
}, function () { | ||
$scope.page.saveButtonState = "error"; | ||
});; | ||
} | ||
}; | ||
|
||
$scope.sortableOptions = { | ||
axis: 'y', | ||
containment: 'parent', | ||
cursor: 'move', | ||
items: '> div.control-group', | ||
tolerance: 'pointer', | ||
stop: function () { | ||
pollItResource.updateSort($scope.content.answers.map(function (answer) { return answer.id }), $scope.content.question.id); | ||
} | ||
}; | ||
|
||
$scope.addAnswer = function (event) { | ||
event.preventDefault(); | ||
|
||
if ($scope.content.answer.value) { | ||
if (!_.find($scope.content.answers, function (item) { return item.value === $scope.content.answer.value })) { | ||
var answer = { value: $scope.content.answer.value, index: $scope.content.answers.length }; | ||
|
||
pollItResource.postQuestionAnswer($routeParams.id, answer).then(function (result) { | ||
$scope.content.answers.push(result.data); | ||
$scope.content.answer = { value: '', hasError: false }; | ||
return; | ||
}); | ||
} | ||
} | ||
|
||
$scope.content.answer = { hasError: true }; | ||
}; | ||
|
||
$scope.updateAnswer = function (answer, event) { | ||
event.preventDefault(); | ||
|
||
pollItResource.saveAnswer(answer); | ||
} | ||
|
||
$scope.removeAnswer = function (answer, event) { | ||
event.preventDefault(); | ||
|
||
pollItResource.deleteAnswer(answer.id, $routeParams.id).then(function () { | ||
$scope.content.answers = _.reject($scope.content.answers, function (x) { | ||
return x.id === answer.id; | ||
}); | ||
}); | ||
}; | ||
} | ||
|
||
angular.module("umbraco").controller("PollIt.EditController", EditController); |
78 changes: 8 additions & 70 deletions
78
Source/Qvision.Umbraco.PollIt/Client/backoffice/poll/edit.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.