9
9
10
10
angular
11
11
. module ( 'directive.inline' , [ ] )
12
- . directive ( 'inline' , [ '$http' , 'asset' , function ( $http , $asset ) {
12
+ . directive ( 'inline' , [ '$http' , 'asset' , 'STATUS' , function ( $http , $asset , STATUS ) {
13
13
return {
14
14
restrict : "A" ,
15
- scope : { translation : "=" } ,
15
+ scope : {
16
+ translation : "="
17
+ } ,
16
18
templateUrl : $asset . getLink ( 'template/inline.html' ) ,
17
19
link : function ( scope , element , attr ) {
18
20
@@ -23,12 +25,7 @@ angular
23
25
/**
24
26
* @type { }
25
27
*/
26
- scope . message = scope . translation . messages [ attr . locale ] ;
27
-
28
- /**
29
- * @type {string }
30
- */
31
- scope . value = scope . message ? scope . message . message : null ;
28
+ scope . message = scope . translation . messages [ attr . locale ] ? scope . translation . messages [ attr . locale ] : { message : null } ;
32
29
33
30
/**
34
31
* @type {int }
@@ -46,9 +43,9 @@ angular
46
43
* @returns {boolean }
47
44
*/
48
45
scope . tryActEmpty = function ( ) {
49
- if ( scope . value == null || scope . value == '' ) {
46
+ if ( scope . message . message == null || scope . message . message == '' ) {
50
47
scope . acting = true ;
51
- scope . value = 'Empty field.' ;
48
+ scope . message . message = 'Empty field.' ;
52
49
element . parent ( ) . addClass ( 'bg-danger' ) ;
53
50
54
51
return true ;
@@ -72,10 +69,10 @@ angular
72
69
*/
73
70
scope . edit = function ( ) {
74
71
if ( scope . acting ) {
75
- scope . value = '' ;
72
+ scope . message . message = '' ;
76
73
}
77
74
78
- scope . oldValue = scope . value ;
75
+ scope . oldValue = scope . message . message ;
79
76
element . addClass ( 'active' ) ;
80
77
inputElement . focus ( ) ;
81
78
} ;
@@ -85,7 +82,7 @@ angular
85
82
*/
86
83
scope . close = function ( ) {
87
84
if ( scope . error !== 0 || scope . error === null ) {
88
- scope . value = scope . oldValue ;
85
+ scope . message . message = scope . oldValue ;
89
86
}
90
87
91
88
scope . error = null ;
@@ -100,8 +97,8 @@ angular
100
97
scope
101
98
. httpValidate ( )
102
99
. success ( function ( ) {
103
- scope . error = 0 ;
104
100
scope . httpSave ( ) ;
101
+ scope . error = 0 ;
105
102
} )
106
103
. error ( function ( ) {
107
104
scope . error = 1 ;
@@ -117,7 +114,7 @@ angular
117
114
return $http . post (
118
115
Routing . generate ( 'ongr_translations_api_check' ) ,
119
116
{
120
- message : scope . value ,
117
+ message : scope . message . message ,
121
118
locale : attr . locale ,
122
119
}
123
120
)
@@ -133,9 +130,9 @@ angular
133
130
id : scope . translation . id ,
134
131
name : 'messages' ,
135
132
properties : {
136
- message : scope . value ,
133
+ message : scope . message . message ,
137
134
locale : attr . locale ,
138
- status : 'dirty'
135
+ status : STATUS . changed
139
136
} ,
140
137
findBy : {
141
138
locale : attr . locale
@@ -144,6 +141,7 @@ angular
144
141
) . success ( function ( ) {
145
142
if ( ! scope . tryActEmpty ( ) ) {
146
143
scope . suspendEmpty ( ) ;
144
+ scope . message . status = STATUS . changed ;
147
145
}
148
146
} ) ;
149
147
}
0 commit comments