Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanhelvoort committed Oct 4, 2017
2 parents b519515 + 3b6fe70 commit f66094b
Show file tree
Hide file tree
Showing 22 changed files with 314 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pollItResource.getOverview().then(function (result) {
$scope.content.questions = result.data;
$scope.page.isLoading = false;
});;
});

$scope.navigate = function (id) {
var location = "/pollIt/poll/edit/" + id;
Expand Down
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);
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<umb-load-indicator ng-if="isLoading"/>

<!-- FILTER -->
<div class="umb-control-group -no-border">
<div class="umb-control-group -no-border" ng-if="!isLoading && content.questions.length !== 0">
<div class="form-search">
<i class="icon-search"></i>
<input type="text"
Expand All @@ -16,16 +16,19 @@
</div>
</div>

<ul class="umb-actions umb-actions-child">
<ul class="umb-actions umb-actions-child" ng-if="!isLoading">
<li ng-repeat="question in content.questions | orderBy:'name' | filter:content.filterTerm" ng-click="pickPoll(question)">
<a href title="{{ question.name }}">
<i ng-if="!question.selected" class="icon-poll" style="display: inline-block;"></i>
<i ng-if="question.selected" class="icon-check color-green" style="font-size: 22px; display: inline-block;"></i>
<a href="" title="{{ question.name }}">
<i class="icon-poll"></i>
<span class="menu-label">
{{question.name}}
</span>
</a>
</li>

<umb-empty-state ng-if="content.questions.length === 0" position="center">
<localize key="pollIt_noQuestions">No questions</localize>
</umb-empty-state>
</ul>

<div ng-if="content.error" class="alert alert-warning">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
function DeleteController($scope, $location, navigationService, treeService, editorState, dialogService, notificationsService, pollItResource) {
$scope.performDelete = function () {

// stop from firing again on double-click
if ($scope.busy) {
return false;
Expand Down
131 changes: 25 additions & 106 deletions Source/Qvision.Umbraco.PollIt/Client/backoffice/poll/edit.controller.js
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 Source/Qvision.Umbraco.PollIt/Client/backoffice/poll/edit.html
Original file line number Diff line number Diff line change
@@ -1,82 +1,20 @@
<div ng-controller="PollIt.EditController">
<form name="contentForm" novalidate val-form-manager>

<umb-load-indicator ng-if="page.loading"></umb-load-indicator>
<umb-load-indicator ng-if="page.loading"></umb-load-indicator>

<form name="contentForm" ng-submit="save()" novalidate val-form-manager>
<umb-editor-view ng-if="!page.loading" umb-tabs>
<umb-editor-view ng-if="!page.loading">

<umb-editor-header name="content.question.name" hide-icon="true" hide-description="true" hide-alias="true" tabs="page.tabs" />
<umb-editor-header name="model.question.name" navigation="page.navigation" hide-icon="true" hide-description="true" hide-alias="true"></umb-editor-header>

<umb-editor-container>
<umb-tabs-content class="form-horizontal" view="true">
<umb-tab id="tab1" rel="1">
<umb-control-group label="@pollIt_addAnswer" description="@pollIt_addAnswerDescription">
<div ng-if="!page.create">
<div class="control-group">
<input name="newItem" type="text" ng-model="content.answer.value" val-highlight="{{content.answer.hasError}}" />
<button class="btn" ng-click="addAnswer($event)" ng-disabled="content.answers.length > 6">
<localize key="general_add">Add</localize>
</button>
</div>
<div ui-sortable="sortableOptions" ng-model="content.answers">
<div class="control-group" ng-repeat="answer in content.answers">
<i class="icon icon-navigation handle"></i>
<input type="text" ng-model="answer.value" required on-blur="updateAnswer(answer, $event)" />
<button class="btn btn-danger" ng-click="removeAnswer(answer, $event)">
<localize key="general_delete">Remove</localize>
</button>
</div>
</div>
</div>
<div ng-if="page.create">
<localize key="pollIt_saveQuestionAddAnswer">Save the question in order to add answers</localize>
</div>
</umb-control-group>

<umb-control-group class="umb-datepicker" label="@pollIt_startDate" description="@pollIt_startDateDescription">
<umb-editor model="startDatePicker"></umb-editor>
</umb-control-group>

<umb-control-group class="umb-datepicker" label="@pollIt_endDate" description="@pollIt_endDateDescription">
<umb-editor model="endDatePicker"></umb-editor>
</umb-control-group>
</umb-tab>
<umb-tab id="tab2" rel="2">
<div class="umb-listview" ng-if="content.answers.length > 0">
<table class="table table-striped">
<thead>
<tr>
<td style="width:45px"></td>
<td><localize key="pollIt_answers">Answers</localize></td>
<td><localize key="pollIt_responses">Responses</localize></td>
</tr>
</thead>
<tbody>
<tr ng-repeat="answer in content.answers">
<td>
{{getResponsesPercentage(answer.id)}}%
</td>
<td>
{{answer.value}}
</td>
<td>
{{getResponses(answer.id)}}
</td>
</tr>
</tbody>
</table>
</div>

<umb-empty-state ng-if="content.answers.length === 0" position="center">
<p>Create answers</p>
</umb-empty-state>
</umb-tab>
</umb-tabs-content>
<umb-editor-container class="form-horizontal">
<umb-editor-sub-views sub-views="page.navigation" model="model"></umb-editor-sub-views>
</umb-editor-container>

<umb-editor-footer>
<umb-editor-footer-content-right>
<umb-button type="submit" button-style="success" state="page.saveButtonState" shortcut="ctrl+s" label="Save" label-key="buttons_save" />
<umb-button action="save()" type="button" button-style="success" state="page.saveButtonState" shortcut="ctrl+s" label="Save"
label-key="buttons_save" disabled="page.saveButtonState === 'busy'" />
</umb-editor-footer-content-right>
</umb-editor-footer>
</umb-editor-view>
Expand Down
Loading

0 comments on commit f66094b

Please sign in to comment.