Skip to content

Commit 5e00492

Browse files
author
Martynas Sudintas
committed
Now js changes status instead of need refresh
1 parent 204f589 commit 5e00492

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

Resources/public/js/controller/listController.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
angular
1111
.module('controller.list', [])
12-
.controller('list', ['$scope', '$http', 'tag', 'DATA', 'LOCALES', '$modal', 'asset',
13-
function($scope, $http, $tag, DATA, LOCALES, $modal, $asset) {
12+
.controller('list', ['$scope', '$http', 'tag', 'DATA', 'LOCALES', '$modal', 'asset', 'STATUS',
13+
function($scope, $http, $tag, DATA, LOCALES, $modal, $asset, $STATUS) {
1414

1515
/**
1616
* @type {{}}
@@ -173,9 +173,9 @@ angular
173173
*/
174174
$scope.getLabelClass = function(status) {
175175
switch (status) {
176-
case 'dirty':
176+
case $STATUS.changed:
177177
return 'label-danger';
178-
case 'fresh':
178+
case $STATUS.unchanged:
179179
return 'label-success';
180180
default:
181181
return 'label-default';

Resources/public/js/directive/InlineDirective.js

+15-17
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
angular
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
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<a href="#" ng-click="edit()" ng-bind="value" ng-class="error == 1 ? 'danger-font' : ''"></a>
1+
<a href="#" ng-click="edit()" ng-bind="message.message" ng-class="error == 1 ? 'danger-font' : ''"></a>
22
<div class="input-group input-group-sm" ng-class="error === 0 ? 'has-success' : (error === 1 ? 'has-error' : '')">
33
<span class="input-group-btn">
44
<button ng-click="save()" ng-class="error == null ? 'btn-default' : (error == 0 ? 'btn-success' : 'btn-danger')" class="btn"><i class="glyphicon glyphicon-ok"></i></button>
55
<button ng-click="close()" class="btn btn-default"><i class="glyphicon glyphicon-remove"></i></button>
66
</span>
7-
<input type="text" class="form-control" ng-model="value" ng-keydown="keyPress($event)"/>
7+
<input type="text" class="form-control" ng-model="message.message" ng-keydown="keyPress($event)"/>
88
</div>

0 commit comments

Comments
 (0)