|
@@ -18,17 +18,21 @@
|
|
'use strict';
|
|
'use strict';
|
|
|
|
|
|
angular.module('ambariAdminConsole')
|
|
angular.module('ambariAdminConsole')
|
|
- .controller('LoginMessageMainCtrl',['$scope', 'Alert', '$timeout', '$http', '$translate', function($scope, Alert, $timeout, $http, $translate) {
|
|
|
|
- var $t = $translate.instant;
|
|
|
|
|
|
+ .controller('LoginMessageMainCtrl',['$scope', 'Alert', '$timeout', '$location', '$http', '$translate', 'UnsavedDialog', function($scope, Alert, $timeout, $location, $http, $translate, UnsavedDialog) {
|
|
|
|
+ var $t = $translate.instant,
|
|
|
|
+ targetUrl = '/loginActivities';
|
|
|
|
+
|
|
$scope.status = false;
|
|
$scope.status = false;
|
|
$scope.motdExists = false;
|
|
$scope.motdExists = false;
|
|
$scope.text = "";
|
|
$scope.text = "";
|
|
|
|
+ $scope.buttonText = "Ok";
|
|
$scope.submitDisabled = true;
|
|
$scope.submitDisabled = true;
|
|
|
|
|
|
$http.get('/api/v1/admin-settings/motd').then(function (res) {
|
|
$http.get('/api/v1/admin-settings/motd').then(function (res) {
|
|
- var respons = JSON.parse(res.data.AdminSettings.content);
|
|
|
|
- $scope.text = respons.text ? respons.text : "";
|
|
|
|
- $scope.status = respons.status && respons.status == "true" ? true : false;
|
|
|
|
|
|
+ var response = JSON.parse(res.data.AdminSettings.content);
|
|
|
|
+ $scope.text = response.text ? response.text : "";
|
|
|
|
+ $scope.buttonText = response.button ? response.button : "";
|
|
|
|
+ $scope.status = response.status && response.status == "true" ? true : false;
|
|
$scope.motdExists = true;
|
|
$scope.motdExists = true;
|
|
});
|
|
});
|
|
|
|
|
|
@@ -40,28 +44,57 @@ angular.module('ambariAdminConsole')
|
|
$scope.submitDisabled = false;
|
|
$scope.submitDisabled = false;
|
|
};
|
|
};
|
|
|
|
|
|
- $scope.saveLoginMsg = function(form) {
|
|
|
|
|
|
+ $scope.$watch(function(scope) {
|
|
|
|
+ return scope.submitDisabled;
|
|
|
|
+ }, function(submitDisabled) {
|
|
|
|
+ $scope.form.$dirty = !submitDisabled
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ $scope.saveLoginMsg = function(targetUrl) {
|
|
var method = $scope.motdExists ? 'PUT' : 'POST';
|
|
var method = $scope.motdExists ? 'PUT' : 'POST';
|
|
var data = {
|
|
var data = {
|
|
'AdminSettings' : {
|
|
'AdminSettings' : {
|
|
- 'content' : '{"text":"' + $scope.text + '", "status":"' + $scope.status + '"}',
|
|
|
|
|
|
+ 'content' : '{"text":"' + $scope.text + '", "button":"' + $scope.buttonText + '", "status":"' + $scope.status + '"}',
|
|
'name' : 'motd',
|
|
'name' : 'motd',
|
|
'setting_type' : 'ambari-server'
|
|
'setting_type' : 'ambari-server'
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- form.submitted = true;
|
|
|
|
- if (form.$valid){
|
|
|
|
|
|
+ $scope.form.submitted = true;
|
|
|
|
+ if ($scope.form.$valid){
|
|
$scope.submitDisabled = true;
|
|
$scope.submitDisabled = true;
|
|
- $http({
|
|
|
|
|
|
+ return $http({
|
|
method: method,
|
|
method: method,
|
|
url: '/api/v1/admin-settings/' + ($scope.motdExists ? 'motd' : ''),
|
|
url: '/api/v1/admin-settings/' + ($scope.motdExists ? 'motd' : ''),
|
|
data: data
|
|
data: data
|
|
}).then(function successCallback() {
|
|
}).then(function successCallback() {
|
|
$scope.motdExists = true;
|
|
$scope.motdExists = true;
|
|
|
|
+ targetUrl ? $location.path(targetUrl) : "";
|
|
}, function errorCallback(data) {
|
|
}, function errorCallback(data) {
|
|
$scope.submitDisabled = false;
|
|
$scope.submitDisabled = false;
|
|
Alert.error($t('common.loginActivities.saveError'), data.data.message);
|
|
Alert.error($t('common.loginActivities.saveError'), data.data.message);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+ $scope.$on('$locationChangeStart', function(event, __targetUrl) {
|
|
|
|
+ if( $scope.form.$dirty ){
|
|
|
|
+ UnsavedDialog().then(function(action) {
|
|
|
|
+ targetUrl = __targetUrl.split('#').pop();
|
|
|
|
+ switch(action){
|
|
|
|
+ case 'save':
|
|
|
|
+ $scope.saveLoginMsg(targetUrl);
|
|
|
|
+ break;
|
|
|
|
+ case 'discard':
|
|
|
|
+ $scope.form.$setPristine();
|
|
|
|
+ $location.path(targetUrl);
|
|
|
|
+ break;
|
|
|
|
+ case 'cancel':
|
|
|
|
+ targetUrl = '/loginActivities';
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ event.preventDefault();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
}]);
|
|
}]);
|