blob: 5d6ff39ee5c744bf3cb3550fd451bfb56f4550c9 [file] [log] [blame]
Matteo Scandolo8cc22e42016-04-12 09:00:04 -07001'use strict';
2
3angular.module('xos.sampleView', [
4 'ngResource',
5 'ngCookies',
Matteo Scandolo8cc22e42016-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 Scandolob0280752016-04-25 10:31:22 -070026 controller: function(Users, _){
Matteo Scandolo18adcb52016-04-14 12:06:50 -070027
28 this.tableConfig = {
29 columns: [
30 {
31 label: 'E-Mail',
32 prop: 'email'
33 },
34 {
Matteo Scandoloa6a9e612016-04-14 16:52:13 -070035 label: 'First Name',
Matteo Scandolo18adcb52016-04-14 12:06:50 -070036 prop: 'firstname'
37 },
38 {
Matteo Scandoloa6a9e612016-04-14 16:52:13 -070039 label: 'Last Name',
Matteo Scandolo18adcb52016-04-14 12:06:50 -070040 prop: 'lastname'
41 }
42 ],
Matteo Scandolo9e6c6fc2016-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 Scandolob0280752016-04-25 10:31:22 -070050 // _.remove(this.users, {id: user.id});
Matteo Scandolo9e6c6fc2016-04-14 14:59:09 -070051 },
52 color: 'red'
53 }
Matteo Scandoloa6a9e612016-04-14 16:52:13 -070054 ],
Matteo Scandolo03e59602016-04-14 17:19:08 -070055 filter: 'field',
Matteo Scandolocc6954e2016-04-15 12:20:14 -070056 order: true,
Matteo Scandolo7bc39c42016-04-20 11:38:42 -070057 pagination: {
Matteo Scandolob0280752016-04-25 10:31:22 -070058 pageSize: 10
Matteo Scandolo7bc39c42016-04-20 11:38:42 -070059 }
Matteo Scandolo18adcb52016-04-14 12:06:50 -070060 };
61
Matteo Scandoloaaa733d2016-04-26 08:42:51 -070062 this.smartTableConfig = {
Matteo Scandoloba1d35c2016-04-26 10:10:54 -070063 resource: 'Users',
Matteo Scandolodc249eb2016-04-26 11:44:36 -070064 hiddenFields: [
65 'email',
66 'username',
67 'created',
68 'updated',
69 'last_login',
70 'is_active',
71 'is_admin',
72 'is_staff',
73 'is_readonly',
74 'is_registering',
75 'is_appuser'
76 ]
Matteo Scandoloaaa733d2016-04-26 08:42:51 -070077 }
78
Matteo Scandolo74b6ef72016-04-15 16:43:48 -070079 this.alertConfig = {
80 type: 'danger',
81 closeBtn: true
82 }
83
Matteo Scandolo7bc39c42016-04-20 11:38:42 -070084 this.formConfig = {
85 exclude: ['password'],
Matteo Scandolo840260d2016-04-22 09:56:48 -070086 formName: 'myForm',
Matteo Scandolo7bc39c42016-04-20 11:38:42 -070087 fields: {
Matteo Scandolo90ed0642016-04-25 10:11:56 -070088 firstname: {
89 validators: {
90 minlength: 10
91 }
92 },
93 lastname: {
94 validators: {
95 maxlength: 3
96 }
97 },
98 user_url: {
99 validators: {
100 required: true
101 }
102 }
Matteo Scandolo7bc39c42016-04-20 11:38:42 -0700103 },
104 actions: [
105 {
106 label: 'Save',
107 icon: 'ok', // refers to bootstraps glyphicon
108 cb: (user) => { // receive the model
109 console.log(user);
110 },
111 class: 'success'
112 }
113 ]
Matteo Scandolo88e18462016-04-25 14:24:18 -0700114 };
115
116 this.errors = {
117 email: false
Matteo Scandolo7bc39c42016-04-20 11:38:42 -0700118 }
Matteo Scandolo74b6ef72016-04-15 16:43:48 -0700119
Matteo Scandolo8cc22e42016-04-12 09:00:04 -0700120 // retrieving user list
Matteo Scandolobd2e5cd2016-04-12 11:59:29 -0700121 Users.query().$promise
Matteo Scandolo8cc22e42016-04-12 09:00:04 -0700122 .then((users) => {
Matteo Scandolo90ed0642016-04-25 10:11:56 -0700123 this.users = users.concat(users).concat(users).concat(users);
Matteo Scandolo8cc22e42016-04-12 09:00:04 -0700124 })
125 .catch((e) => {
126 throw new Error(e);
127 });
128 }
129 };
130});