|
1 | 1 | (function () { |
2 | | - 'use strict'; |
3 | | - |
4 | | - angular.module('letsAngular') |
5 | | - .directive('fwInput', fwInput); |
6 | | - |
7 | | - fwInput.$inject = ['viaCEP', '$timeout', '$compile', 'jQuery', '$sce']; |
8 | | - |
9 | | - function fwInput(viaCEP, $timeout, $compile, jQuery, $sce) { |
10 | | - return { |
11 | | - restrict: 'E', |
12 | | - scope: true, |
13 | | - templateUrl: 'lets/views/framework/input.html', |
14 | | - replace: true, |
15 | | - link: { |
16 | | - |
17 | | - pre: function preLink(scope, $el, attrs, controller) { |
18 | | - |
19 | | - var dataVar = $el.attr('fw-data'); |
20 | | - |
21 | | - if (!scope.field.customOptions.events) { |
22 | | - scope.field.customOptions['events'] = {}; |
23 | | - } |
24 | | - |
25 | | - scope.fieldHtml = function () { |
26 | | - return $sce.trustAsHtml(scope.field.toString()); |
27 | | - } |
28 | | - |
29 | | - if (dataVar != 'data') { |
30 | | - scope.data = scope[dataVar]; |
31 | | - } |
32 | | - |
33 | | - if(dataVar=="detail_data"){ |
34 | | - var detail = scope.detail_key; |
35 | | - |
36 | | - if (scope.field.autocomplete !== false){ |
37 | | - scope.autocomplete = function (field, val) { |
38 | | - return scope.autocompleteDetail(detail, field, val); |
39 | | - } |
40 | | - |
41 | | - scope.autocompleteSelect = function ($item, $model, $label) { |
42 | | - return scope.autocompleteDetailSelect(detail, $item, $model, $label); |
43 | | - } |
44 | | - } |
45 | | - |
46 | | - if (scope.field.customOptions.file != undefined) { |
47 | | - scope.download = function (field, id) { |
48 | | - return scope.downloadDetail(detail, field, id, scope.data); |
49 | | - } |
50 | | - } |
51 | | - } |
52 | | - |
53 | | - if (scope.field.customOptions.cep != undefined) { |
54 | | - |
55 | | - $el.find('input.main-input').blur(function () { |
56 | | - var $scope = angular.element(this).scope(); |
57 | | - |
58 | | - viaCEP.get(this.value).then(function (response) { |
59 | | - var map = $scope.field.customOptions.cep; |
60 | | - |
61 | | - $scope.data[map.address] = response.logradouro; |
62 | | - $scope.data[map.district] = response.bairro; |
63 | | - $scope.data[map.city] = response.localidade; |
64 | | - $scope.data[map.state] = response.uf; |
65 | | - |
66 | | - scope.$$phase || scope.$apply(); |
67 | | - }); |
68 | | - }); |
69 | | - } |
70 | | - else if (scope.field.customOptions.multiple != undefined && scope.field.customOptions.multiple == true) { |
71 | | - var a = $compile($el.contents())(scope); |
72 | | - } |
73 | | - |
74 | | - jQuery($el).on('blur', ':input[ng-model]', function (e) { |
75 | | - try { |
76 | | - if (angular.element(this).scope().field.customOptions.events.blur != undefined) { |
77 | | - angular.element(this).scope().field.customOptions.events.blur.call(this, e); |
78 | | - } |
79 | | - } |
80 | | - catch (e) { |
81 | | - } |
82 | | - |
83 | | - |
84 | | - }); |
85 | | - |
86 | | - scope.isEmpty = function (obj) { |
87 | | - return Object.keys(obj).length; |
88 | | - } |
89 | | - } |
90 | | - |
91 | | - } |
92 | | - |
93 | | - } |
94 | | - } |
| 2 | + 'use strict'; |
| 3 | + |
| 4 | + angular.module('letsAngular').directive('fwInput', fwInput); |
| 5 | + |
| 6 | + fwInput.$inject = ['viaCEP', '$timeout', '$compile', 'jQuery', '$sce']; |
| 7 | + |
| 8 | + function fwInput(viaCEP, $timeout, $compile, jQuery, $sce) { |
| 9 | + return { |
| 10 | + restrict: 'E', |
| 11 | + scope: true, |
| 12 | + templateUrl: 'lets/views/framework/input.html', |
| 13 | + replace: true, |
| 14 | + link: { |
| 15 | + pre: function preLink(scope, $el, attrs, controller) { |
| 16 | + var dataVar = $el.attr('fw-data'); |
| 17 | + |
| 18 | + if (scope.field && scope.field.customOptions && typeof scope.field.customOptions == 'object' && !scope.field.customOptions.events) { |
| 19 | + scope.field.customOptions['events'] = {}; |
| 20 | + } |
| 21 | + |
| 22 | + scope.fieldHtml = function () { |
| 23 | + return $sce.trustAsHtml(scope.field.toString()); |
| 24 | + }; |
| 25 | + |
| 26 | + if (dataVar != 'data') { |
| 27 | + scope.data = scope[dataVar]; |
| 28 | + } |
| 29 | + // console.log('scopes', scope, dataVar); |
| 30 | + |
| 31 | + if (dataVar == 'detail_data') { |
| 32 | + var detail = scope.detail_key; |
| 33 | + |
| 34 | + if (scope.field && scope.field.autocomplete !== false) { |
| 35 | + scope.autocomplete = function (field, val) { |
| 36 | + return scope.autocompleteDetail(detail, field, val); |
| 37 | + }; |
| 38 | + |
| 39 | + scope.autocompleteSelect = function ($item, $model, $label) { |
| 40 | + return scope.autocompleteDetailSelect(detail, $item, $model, $label); |
| 41 | + }; |
| 42 | + } |
| 43 | + |
| 44 | + if (scope.field && scope.field.customOptions && scope.field.customOptions.file != undefined) { |
| 45 | + scope.download = function (field, id) { |
| 46 | + return scope.downloadDetail(detail, field, id, scope.data); |
| 47 | + }; |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + // if (scope.type == 'date') { |
| 52 | + // console.log(scope, $el, attrs, controller, dataVar); |
| 53 | + // scope.options = { |
| 54 | + // date: {startDate: moment().subtract(1, 'years'), endDate: moment().add(1, 'years')}, |
| 55 | + // picker: null, |
| 56 | + // options: { |
| 57 | + // pickerClasses: 'custom-display', //angular-daterangepicker extra |
| 58 | + // buttonClasses: 'btn', |
| 59 | + // applyButtonClasses: 'btn-primary', |
| 60 | + // cancelButtonClasses: 'btn-danger', |
| 61 | + // locale: { |
| 62 | + // separator: ' - ', |
| 63 | + // format: 'DD/MM/YYYY', |
| 64 | + // applyLabel: 'Aplicar', |
| 65 | + // cancelLabel: 'Cancelar', |
| 66 | + // daysOfWeek: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], |
| 67 | + // monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'], |
| 68 | + // }, |
| 69 | + // }, |
| 70 | + // }; |
| 71 | + // } |
| 72 | + |
| 73 | + if (scope.field && scope.field.customOptions && scope.field.customOptions.cep != undefined) { |
| 74 | + $el.find('input.main-input').blur(function () { |
| 75 | + var $scope = angular.element(this).scope(); |
| 76 | + |
| 77 | + viaCEP.get(this.value).then(function (response) { |
| 78 | + var map = $scope.field.customOptions.cep; |
| 79 | + |
| 80 | + $scope.data[map.address] = response.logradouro; |
| 81 | + $scope.data[map.district] = response.bairro; |
| 82 | + $scope.data[map.city] = response.localidade; |
| 83 | + $scope.data[map.state] = response.uf; |
| 84 | + |
| 85 | + scope.$$phase || scope.$apply(); |
| 86 | + }); |
| 87 | + }); |
| 88 | + } else if (scope.field && scope.field.customOptions && scope.field.customOptions.multiple != undefined && scope.field.customOptions.multiple == true) { |
| 89 | + var a = $compile($el.contents())(scope); |
| 90 | + } |
| 91 | + |
| 92 | + jQuery($el).on('blur', ':input[ng-model]', function (e) { |
| 93 | + try { |
| 94 | + if (angular.element(this).scope().field.customOptions.events.blur != undefined) { |
| 95 | + angular.element(this).scope().field.customOptions.events.blur.call(this, e); |
| 96 | + } |
| 97 | + } catch (e) {} |
| 98 | + }); |
| 99 | + |
| 100 | + scope.openDate = function (__scope) { |
| 101 | + // console.log(nome, nome); |
| 102 | + console.log({__scope: __scope}); |
| 103 | + $('input#' + __scope.name).click(); |
| 104 | + }; |
| 105 | + |
| 106 | + scope.isEmpty = function (obj) { |
| 107 | + return Object.keys(obj).length; |
| 108 | + }; |
| 109 | + }, |
| 110 | + }, |
| 111 | + }; |
| 112 | + } |
95 | 113 | })(); |
0 commit comments