blob: 790eb4923e3362522f7a2a0e35fe9d9ddb478a7b [file] [log] [blame]
Matteo Scandolode76a452016-04-12 09:00:04 -07001'use strict';
2
3angular.module('xos.sampleView', [
4 'ngResource',
5 'ngCookies',
Matteo Scandolode76a452016-04-12 09:00:04 -07006 'ui.router',
7 'xos.helpers'
8])
9.config(($stateProvider) => {
10 $stateProvider
11 .state('user-list', {
12 url: '/',
13 template: '<users-list></users-list>'
14 });
15})
16.config(function($httpProvider){
17 $httpProvider.interceptors.push('NoHyperlinks');
18})
19.directive('usersList', function(){
20 return {
21 restrict: 'E',
22 scope: {},
23 bindToController: true,
24 controllerAs: 'vm',
25 templateUrl: 'templates/users-list.tpl.html',
Matteo Scandoloc88bb9f2016-04-25 10:31:22 -070026 controller: function(Users, _){
Matteo Scandolodcc65242016-04-14 12:06:50 -070027
28 this.tableConfig = {
29 columns: [
30 {
31 label: 'E-Mail',
32 prop: 'email'
33 },
34 {
Matteo Scandolo6a6586e2016-04-14 16:52:13 -070035 label: 'First Name',
Matteo Scandolodcc65242016-04-14 12:06:50 -070036 prop: 'firstname'
37 },
38 {
Matteo Scandolo6a6586e2016-04-14 16:52:13 -070039 label: 'Last Name',
Matteo Scandolodcc65242016-04-14 12:06:50 -070040 prop: 'lastname'
41 }
42 ],
Matteo Scandoloa7e64fd2016-04-14 14:59:09 -070043 classes: 'table table-striped table-condensed',
44 actions: [
45 {
46 label: 'delete',
47 icon: 'remove',
48 cb: (user) => {
49 console.log(user);
Matteo Scandoloc88bb9f2016-04-25 10:31:22 -070050 // _.remove(this.users, {id: user.id});
Matteo Scandoloa7e64fd2016-04-14 14:59:09 -070051 },
52 color: 'red'
53 }
Matteo Scandolo6a6586e2016-04-14 16:52:13 -070054 ],
Matteo Scandolof32a2e92016-04-14 17:19:08 -070055 filter: 'field',
Matteo Scandolo320ce2c2016-04-15 12:20:14 -070056 order: true,
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070057 pagination: {
Matteo Scandoloc88bb9f2016-04-25 10:31:22 -070058 pageSize: 10
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070059 }
Matteo Scandolodcc65242016-04-14 12:06:50 -070060 };
61
Matteo Scandolod5efedf2016-04-26 08:42:51 -070062 this.smartTableConfig = {
Matteo Scandolo3a55ad62016-04-26 10:10:54 -070063 resource: 'Users',
64 hiddenFields: ['last_login']
Matteo Scandolod5efedf2016-04-26 08:42:51 -070065 }
66
Matteo Scandolo918c0fa2016-04-15 16:43:48 -070067 this.alertConfig = {
68 type: 'danger',
69 closeBtn: true
70 }
71
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070072 this.formConfig = {
73 exclude: ['password'],
Matteo Scandolo9a8f53c2016-04-22 09:56:48 -070074 formName: 'myForm',
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070075 fields: {
Matteo Scandoloe53ee382016-04-25 10:11:56 -070076 firstname: {
77 validators: {
78 minlength: 10
79 }
80 },
81 lastname: {
82 validators: {
83 maxlength: 3
84 }
85 },
86 user_url: {
87 validators: {
88 required: true
89 }
90 }
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070091 },
92 actions: [
93 {
94 label: 'Save',
95 icon: 'ok', // refers to bootstraps glyphicon
96 cb: (user) => { // receive the model
97 console.log(user);
98 },
99 class: 'success'
100 }
101 ]
Matteo Scandolo9bb3a952016-04-25 14:24:18 -0700102 };
103
104 this.errors = {
105 email: false
Matteo Scandoloc49f53c2016-04-20 11:38:42 -0700106 }
Matteo Scandolo918c0fa2016-04-15 16:43:48 -0700107
Matteo Scandolode76a452016-04-12 09:00:04 -0700108 // retrieving user list
Matteo Scandolo2ef0cd72016-04-12 11:59:29 -0700109 Users.query().$promise
Matteo Scandolode76a452016-04-12 09:00:04 -0700110 .then((users) => {
Matteo Scandoloe53ee382016-04-25 10:11:56 -0700111 this.users = users.concat(users).concat(users).concat(users);
Matteo Scandolode76a452016-04-12 09:00:04 -0700112 })
113 .catch((e) => {
114 throw new Error(e);
115 });
116 }
117 };
118});