blob: 3dc24a6004b976da9bf4668cb75d7cfa0a71e569 [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'
Matteo Scandolo2e804cb2016-04-27 16:29:33 -070041 },
42 {
43 label: 'Created',
44 prop: 'created'
45 },
46 {
47 label: 'is_admin',
48 prop: 'is_admin'
Matteo Scandolodcc65242016-04-14 12:06:50 -070049 }
50 ],
Matteo Scandoloa7e64fd2016-04-14 14:59:09 -070051 classes: 'table table-striped table-condensed',
52 actions: [
53 {
54 label: 'delete',
55 icon: 'remove',
56 cb: (user) => {
57 console.log(user);
Matteo Scandoloc88bb9f2016-04-25 10:31:22 -070058 // _.remove(this.users, {id: user.id});
Matteo Scandoloa7e64fd2016-04-14 14:59:09 -070059 },
60 color: 'red'
61 }
Matteo Scandolo6a6586e2016-04-14 16:52:13 -070062 ],
Matteo Scandolof32a2e92016-04-14 17:19:08 -070063 filter: 'field',
Matteo Scandolo320ce2c2016-04-15 12:20:14 -070064 order: true,
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070065 pagination: {
Matteo Scandoloc88bb9f2016-04-25 10:31:22 -070066 pageSize: 10
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070067 }
Matteo Scandolodcc65242016-04-14 12:06:50 -070068 };
69
Matteo Scandolod5efedf2016-04-26 08:42:51 -070070 this.smartTableConfig = {
Matteo Scandolo3a55ad62016-04-26 10:10:54 -070071 resource: 'Users',
Matteo Scandolo3fa98712016-04-26 11:44:36 -070072 hiddenFields: [
73 'email',
74 'username',
Matteo Scandolod02ef502016-04-27 15:58:16 -070075 // 'created',
Matteo Scandolo3fa98712016-04-26 11:44:36 -070076 'updated',
77 'last_login',
78 'is_active',
79 'is_admin',
80 'is_staff',
81 'is_readonly',
82 'is_registering',
Matteo Scandolod02ef502016-04-27 15:58:16 -070083 'is_appuser',
84 'timezone'
Matteo Scandolo3fa98712016-04-26 11:44:36 -070085 ]
Matteo Scandolod5efedf2016-04-26 08:42:51 -070086 }
87
Matteo Scandolo918c0fa2016-04-15 16:43:48 -070088 this.alertConfig = {
89 type: 'danger',
90 closeBtn: true
91 }
92
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070093 this.formConfig = {
94 exclude: ['password'],
Matteo Scandolo9a8f53c2016-04-22 09:56:48 -070095 formName: 'myForm',
Matteo Scandoloc49f53c2016-04-20 11:38:42 -070096 fields: {
Matteo Scandoloe53ee382016-04-25 10:11:56 -070097 firstname: {
98 validators: {
99 minlength: 10
100 }
101 },
102 lastname: {
103 validators: {
104 maxlength: 3
105 }
106 },
107 user_url: {
108 validators: {
109 required: true
110 }
111 }
Matteo Scandoloc49f53c2016-04-20 11:38:42 -0700112 },
113 actions: [
114 {
115 label: 'Save',
116 icon: 'ok', // refers to bootstraps glyphicon
117 cb: (user) => { // receive the model
118 console.log(user);
119 },
120 class: 'success'
121 }
122 ]
Matteo Scandolo9bb3a952016-04-25 14:24:18 -0700123 };
124
125 this.errors = {
126 email: false
Matteo Scandoloc49f53c2016-04-20 11:38:42 -0700127 }
Matteo Scandolo918c0fa2016-04-15 16:43:48 -0700128
Matteo Scandolod02ef502016-04-27 15:58:16 -0700129 console.log('aaa')
130
Matteo Scandolode76a452016-04-12 09:00:04 -0700131 // retrieving user list
Matteo Scandolo2ef0cd72016-04-12 11:59:29 -0700132 Users.query().$promise
Matteo Scandolode76a452016-04-12 09:00:04 -0700133 .then((users) => {
Matteo Scandoloe53ee382016-04-25 10:11:56 -0700134 this.users = users.concat(users).concat(users).concat(users);
Matteo Scandolode76a452016-04-12 09:00:04 -0700135 })
136 .catch((e) => {
137 throw new Error(e);
138 });
139 }
140 };
141});