supervisor own pictos, add new picto not working

parent ec7a00d4
/* global dashboardControllers */
'use strict';
// Please note that $modalInstance represents a modal window (instance) dependency.
// It is not the same as the $modal service used above.
dashboardControllers.controller('OwnPictosCtrl', function (
$scope,
$http,
config,
$window,
$location,
$modal,
$modalInstance,
$translate,
supervisor,
student
) {
//Data
$scope.studentData = student;
$scope.supervisor = supervisor;
$scope.source = 'ownpictos';
//Supervisor pictos
$http.get(config.backend + '/sup/' + $scope.supervisor.id + '/pictos')
.success(function (data) {
if (data) {
$scope.pictos = data;
} else {
$scope.pictos = [];
}
})
.error(function () {
$translate('error_loading_pictos').then(function (translation) {
ngToast.danger({ content: translation });
});
});
//Add own picto
$scope.addOwnPicto = function () {
$scope.progress = 0;
var modalInstance = $modal.open({
animation: true,
templateUrl: 'modules/common/views/cropimg.html',
controller: 'CropImgCtrl',
size: 'lg',
resolve: {
picFile: () => {return $scope.picFile;},
uploadFunc: () => {return $scope.upload;},
progress: () => {return $scope.progress;}
}
});
modalInstance.result.then(function () {});
};
// Delete own picto
$scope.removeOwnPicto = function (pictoId) {
$translate('confirmation').then(t => {
if ($window.confirm(t))
$http.delete(config.backend + '/picto/' + pictoId)
.success(function () {
var i;
for (i = 0; i < $scope.pictos.length; i++) {
if (pictoId === $scope.pictos[i].id) {
$scope.pictos.splice(i, 1);
}
}
// websocket emit vocabulary delete action
io.socket.post('/stu/vocabulary', {
action: 'delete',
attributes: {
stu_picto: pictoId
}
}, function () {});
})
.error(function () {});
});
};
//Modal interaction
$scope.close = function (pictoId) {
$modalInstance.close(pictoId);
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
});
......@@ -5,7 +5,16 @@
//-----------------------
// Supervisor Controller
//-----------------------
dashboardControllers.controller('SupervisorCtrl', function SupervisorCtrl($scope, $window, $location, IOService, $modal, $translate) {
dashboardControllers.controller('SupervisorCtrl', function SupervisorCtrl(
$scope,
$http,
config,
$window,
$location,
IOService,
$modal,
$translate
) {
// Restore user data from session
var user = JSON.parse($window.sessionStorage.user);
......@@ -35,4 +44,24 @@ dashboardControllers.controller('SupervisorCtrl', function SupervisorCtrl($scope
}
});
//
// Own Pictos
//
$scope.own_pictos = function () {
var modalInstance = $modal.open({
animation: true,
templateUrl: 'modules/supervisor/views/own_pictos.html',
controller: 'OwnPictosCtrl',
size: 'lg',
resolve: {
student: function () {
return $scope.studentData;
},
supervisor: function () {
return $scope.user;
}
}
});
};
});
......@@ -44,6 +44,12 @@
</a>
</li>
<li>
<a ng-click="own_pictos()" class="pointer" role="menuitem" tabindex="0" href="">
<i class="glyphicon glyphicon-picture" aria-hidden="true"></i>
{{ 'own_pictos' | translate }}
</a>
</li>
<li>
<a class="pointer" role="menuitem" tabindex="0" href="/app/#/setup">
<i class="glyphicon glyphicon-cog" aria-hidden="true"></i>
{{ 'setup' | translate }}
......
<div>
<div class="modal-header">
<button type="button" class="close" ng-click="close()">
<span aria-hidden="true">&times;</span><span class="sr-only" translate>close</span>
</button>
<h4 class="modal-title" id="myModalLabel" translate>own_pictos</h4>
</div>
<div class="modal-body">
<div>
<alert ng-show="alert.show" ng-model="alert" type="{{alert.type}}" close="closeAlert()">{{alert.msg | translate}}</alert>
</div>
<div class="row" ng-show="source != 'newfile'" >
<div id="collections" class="col-md-12 category-collection"
ng-class="{ 'category-collection-loading': loadingCatPictos }"
data-loading="{{ 'loading_pictos' | translate }}">
<div ng-show="source == 'ownpictos'" class="input-group">
<button class="btn btn-success" ngf-select ng-model="picFile" accept="image/*" ngf-change="addOwnPicto()">
<span class="glyphicon glyphicon-folder-open"></span> {{ 'new_img' | translate }}
</button>
</div>
<hr>
<!-- Galería de pictos -->
<div id="clearfix-infiniteScroll-parent" infinite-scroll="scroll()"
infinite-scroll-container="'#collections'">
<div
class="picto_peq pull-left"
ng-repeat="p in pictos" >
<img ng-src="{{p.uri}}" popover="{{p.expressions[0].text}}" popover-trigger="mouseenter" />
<!-- Options to remove picto (Only for own pictos) -->
<div class="picto_options" ng-show="source == 'ownpictos'">
<a ng-click="removeOwnPicto(p.id)" class="picto_remove" title="{{ 'delete' | translate}}">
<span class="color_red glyphicon glyphicon-remove-circle" aria-hidden="true"></span>
</a>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<!-- crop view -->
<div id="crop_area" ng-show="source == 'newfile'">
<div class="row">
<div class="col-md-8">
<div ngf-drop ng-model="picFile" ngf-pattern="image/*" class="cropArea">
<img-crop
image="picFile | ngfDataUrl"
result-image="croppedDataUrl" ng-init="croppedDataUrl=''"
area-type="square"
result-image-size="200"
>
</img-crop>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<img ng-src="{{ croppedDataUrl }}" />
</div>
<div class="form-group">
<button class="btn btn-default" ng-click="upload(croppedDataUrl, picFile.name)" ng-model="picFile" accept="image/*">
<span class="glyphicon glyphicon-upload"></span> {{ 'upload_image' | translate }}
</button>
</div>
<div class="form-group">
<span class="progress" ng-show="progress >= 0">
<div style="width:{{progress}}%" ng-bind="progress + '%'"></div>
</span>
</div>
</div>
</div>
</div>
</div> <!-- /modal-body -->
<div class="modal-footer">
<button class="btn btn-primary" ng-click="cancel()">{{ 'close' | translate }}</button>
</div>
</div>
......@@ -49,6 +49,7 @@ module.exports = function (grunt) {
'assets/scripts/modules/admin/controllers/licenses.js',
'assets/scripts/modules/admin/controllers/offices.js',
'assets/scripts/modules/admin/controllers/supervisors.js',
'assets/scripts/modules/supervisor/controllers/own_pictos.js',
'assets/scripts/modules/supervisor/controllers/supervisor.js',
'assets/scripts/modules/supervisor/controllers/supervisors.js',
'assets/scripts/modules/supervisor/controllers/students.js',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment