99
1010angular
1111 . module ( 'directive.inline' , [ ] )
12- . directive ( 'inline' , [ '$http' , 'asset' , function ( $http , $asset ) {
12+ . directive ( 'inline' , [ '$http' , 'asset' , 'STATUS' , function ( $http , $asset , STATUS ) {
1313 return {
1414 restrict : "A" ,
15- scope : { translation : "=" } ,
15+ scope : {
16+ translation : "="
17+ } ,
1618 templateUrl : $asset . getLink ( 'template/inline.html' ) ,
1719 link : function ( scope , element , attr ) {
1820
@@ -23,12 +25,7 @@ angular
2325 /**
2426 * @type { }
2527 */
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 } ;
3229
3330 /**
3431 * @type {int }
@@ -46,9 +43,9 @@ angular
4643 * @returns {boolean }
4744 */
4845 scope . tryActEmpty = function ( ) {
49- if ( scope . value == null || scope . value == '' ) {
46+ if ( scope . message . message == null || scope . message . message == '' ) {
5047 scope . acting = true ;
51- scope . value = 'Empty field.' ;
48+ scope . message . message = 'Empty field.' ;
5249 element . parent ( ) . addClass ( 'bg-danger' ) ;
5350
5451 return true ;
@@ -72,10 +69,10 @@ angular
7269 */
7370 scope . edit = function ( ) {
7471 if ( scope . acting ) {
75- scope . value = '' ;
72+ scope . message . message = '' ;
7673 }
7774
78- scope . oldValue = scope . value ;
75+ scope . oldValue = scope . message . message ;
7976 element . addClass ( 'active' ) ;
8077 inputElement . focus ( ) ;
8178 } ;
@@ -85,7 +82,7 @@ angular
8582 */
8683 scope . close = function ( ) {
8784 if ( scope . error !== 0 || scope . error === null ) {
88- scope . value = scope . oldValue ;
85+ scope . message . message = scope . oldValue ;
8986 }
9087
9188 scope . error = null ;
@@ -100,8 +97,8 @@ angular
10097 scope
10198 . httpValidate ( )
10299 . success ( function ( ) {
103- scope . error = 0 ;
104100 scope . httpSave ( ) ;
101+ scope . error = 0 ;
105102 } )
106103 . error ( function ( ) {
107104 scope . error = 1 ;
@@ -117,7 +114,7 @@ angular
117114 return $http . post (
118115 Routing . generate ( 'ongr_translations_api_check' ) ,
119116 {
120- message : scope . value ,
117+ message : scope . message . message ,
121118 locale : attr . locale ,
122119 }
123120 )
@@ -133,9 +130,9 @@ angular
133130 id : scope . translation . id ,
134131 name : 'messages' ,
135132 properties : {
136- message : scope . value ,
133+ message : scope . message . message ,
137134 locale : attr . locale ,
138- status : 'dirty'
135+ status : STATUS . changed
139136 } ,
140137 findBy : {
141138 locale : attr . locale
@@ -144,6 +141,7 @@ angular
144141 ) . success ( function ( ) {
145142 if ( ! scope . tryActEmpty ( ) ) {
146143 scope . suspendEmpty ( ) ;
144+ scope . message . status = STATUS . changed ;
147145 }
148146 } ) ;
149147 }
0 commit comments