blob: 5f7be4d8889f61c443a6a88a64bdd889071c10cc [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 = {
63 resource: 'Users'
64 }
65
Matteo Scandolo918c0fa2016-04-15 16:43:48 -070066 this.alertConfig = {
67 type: 'danger',
68 closeBtn: true
69 }
70
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070071 this.formConfig = {
72 exclude: ['password'],
Matteo Scandolo9a8f53c2016-04-22 09:56:48 -070073 formName: 'myForm',
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070074 fields: {
Matteo Scandoloe53ee382016-04-25 10:11:56 -070075 firstname: {
76 validators: {
77 minlength: 10
78 }
79 },
80 lastname: {
81 validators: {
82 maxlength: 3
83 }
84 },
85 user_url: {
86 validators: {
87 required: true
88 }
89 }
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070090 },
91 actions: [
92 {
93 label: 'Save',
94 icon: 'ok', // refers to bootstraps glyphicon
95 cb: (user) => { // receive the model
96 console.log(user);
97 },
98 class: 'success'
99 }
100 ]
Matteo Scandolo9bb3a952016-04-25 14:24:18 -0700101 };
102
103 this.errors = {
104 email: false
Matteo Scandoloc49f53c2016-04-20 11:38:42 -0700105 }
Matteo Scandolo918c0fa2016-04-15 16:43:48 -0700106
Matteo Scandolode76a452016-04-12 09:00:04 -0700107 // retrieving user list
Matteo Scandolo2ef0cd72016-04-12 11:59:29 -0700108 Users.query().$promise
Matteo Scandolode76a452016-04-12 09:00:04 -0700109 .then((users) => {
Matteo Scandoloe53ee382016-04-25 10:11:56 -0700110 this.users = users.concat(users).concat(users).concat(users);
Matteo Scandolode76a452016-04-12 09:00:04 -0700111 })
112 .catch((e) => {
113 throw new Error(e);
114 });
115 }
116 };
117});