Matteo Scandolo | de76a45 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.sampleView', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
Matteo Scandolo | de76a45 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 6 | '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 Scandolo | c88bb9f | 2016-04-25 10:31:22 -0700 | [diff] [blame] | 26 | controller: function(Users, _){ |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 27 | |
| 28 | this.tableConfig = { |
| 29 | columns: [ |
| 30 | { |
| 31 | label: 'E-Mail', |
| 32 | prop: 'email' |
| 33 | }, |
| 34 | { |
Matteo Scandolo | 6a6586e | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 35 | label: 'First Name', |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 36 | prop: 'firstname' |
| 37 | }, |
| 38 | { |
Matteo Scandolo | 6a6586e | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 39 | label: 'Last Name', |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 40 | prop: 'lastname' |
Matteo Scandolo | 2e804cb | 2016-04-27 16:29:33 -0700 | [diff] [blame] | 41 | }, |
| 42 | { |
| 43 | label: 'Created', |
| 44 | prop: 'created' |
| 45 | }, |
| 46 | { |
| 47 | label: 'is_admin', |
| 48 | prop: 'is_admin' |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 49 | } |
| 50 | ], |
Matteo Scandolo | a7e64fd | 2016-04-14 14:59:09 -0700 | [diff] [blame] | 51 | classes: 'table table-striped table-condensed', |
| 52 | actions: [ |
| 53 | { |
| 54 | label: 'delete', |
| 55 | icon: 'remove', |
| 56 | cb: (user) => { |
| 57 | console.log(user); |
Matteo Scandolo | c88bb9f | 2016-04-25 10:31:22 -0700 | [diff] [blame] | 58 | // _.remove(this.users, {id: user.id}); |
Matteo Scandolo | a7e64fd | 2016-04-14 14:59:09 -0700 | [diff] [blame] | 59 | }, |
| 60 | color: 'red' |
| 61 | } |
Matteo Scandolo | 6a6586e | 2016-04-14 16:52:13 -0700 | [diff] [blame] | 62 | ], |
Matteo Scandolo | f32a2e9 | 2016-04-14 17:19:08 -0700 | [diff] [blame] | 63 | filter: 'field', |
Matteo Scandolo | 320ce2c | 2016-04-15 12:20:14 -0700 | [diff] [blame] | 64 | order: true, |
Matteo Scandolo | c49f53c | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 65 | pagination: { |
Matteo Scandolo | c88bb9f | 2016-04-25 10:31:22 -0700 | [diff] [blame] | 66 | pageSize: 10 |
Matteo Scandolo | c49f53c | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 67 | } |
Matteo Scandolo | dcc6524 | 2016-04-14 12:06:50 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
Matteo Scandolo | d5efedf | 2016-04-26 08:42:51 -0700 | [diff] [blame] | 70 | this.smartTableConfig = { |
Matteo Scandolo | 3a55ad6 | 2016-04-26 10:10:54 -0700 | [diff] [blame] | 71 | resource: 'Users', |
Matteo Scandolo | 3fa9871 | 2016-04-26 11:44:36 -0700 | [diff] [blame] | 72 | hiddenFields: [ |
| 73 | 'email', |
| 74 | 'username', |
Matteo Scandolo | d02ef50 | 2016-04-27 15:58:16 -0700 | [diff] [blame] | 75 | // 'created', |
Matteo Scandolo | 3fa9871 | 2016-04-26 11:44:36 -0700 | [diff] [blame] | 76 | 'updated', |
| 77 | 'last_login', |
| 78 | 'is_active', |
| 79 | 'is_admin', |
| 80 | 'is_staff', |
| 81 | 'is_readonly', |
| 82 | 'is_registering', |
Matteo Scandolo | d02ef50 | 2016-04-27 15:58:16 -0700 | [diff] [blame] | 83 | 'is_appuser', |
| 84 | 'timezone' |
Matteo Scandolo | 3fa9871 | 2016-04-26 11:44:36 -0700 | [diff] [blame] | 85 | ] |
Matteo Scandolo | d5efedf | 2016-04-26 08:42:51 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Matteo Scandolo | 918c0fa | 2016-04-15 16:43:48 -0700 | [diff] [blame] | 88 | this.alertConfig = { |
| 89 | type: 'danger', |
| 90 | closeBtn: true |
| 91 | } |
| 92 | |
Matteo Scandolo | c49f53c | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 93 | this.formConfig = { |
| 94 | exclude: ['password'], |
Matteo Scandolo | 9a8f53c | 2016-04-22 09:56:48 -0700 | [diff] [blame] | 95 | formName: 'myForm', |
Matteo Scandolo | c49f53c | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 96 | fields: { |
Matteo Scandolo | e53ee38 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 97 | 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 Scandolo | c49f53c | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 112 | }, |
| 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 Scandolo | 9bb3a95 | 2016-04-25 14:24:18 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | this.errors = { |
| 126 | email: false |
Matteo Scandolo | c49f53c | 2016-04-20 11:38:42 -0700 | [diff] [blame] | 127 | } |
Matteo Scandolo | 918c0fa | 2016-04-15 16:43:48 -0700 | [diff] [blame] | 128 | |
Matteo Scandolo | d02ef50 | 2016-04-27 15:58:16 -0700 | [diff] [blame] | 129 | console.log('aaa') |
| 130 | |
Matteo Scandolo | de76a45 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 131 | // retrieving user list |
Matteo Scandolo | 2ef0cd7 | 2016-04-12 11:59:29 -0700 | [diff] [blame] | 132 | Users.query().$promise |
Matteo Scandolo | de76a45 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 133 | .then((users) => { |
Matteo Scandolo | e53ee38 | 2016-04-25 10:11:56 -0700 | [diff] [blame] | 134 | this.users = users.concat(users).concat(users).concat(users); |
Matteo Scandolo | de76a45 | 2016-04-12 09:00:04 -0700 | [diff] [blame] | 135 | }) |
| 136 | .catch((e) => { |
| 137 | throw new Error(e); |
| 138 | }); |
| 139 | } |
| 140 | }; |
| 141 | }); |