Skip to content

Commit

Permalink
Used layouts/angular/x_edit_buttons_angular partial for the buttons
Browse files Browse the repository at this point in the history
Also made a few other adjustments in the haml
  • Loading branch information
AparnaKarve committed Aug 19, 2015
1 parent 8a0ed80 commit 836e5eb
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 190 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//= require directives/repository/valid_unc_path
//= require services/miq_service
//= require services/timer_option_service
//= require controllers/angular-bootstrap/DatepickerCtrl
//= require controllers/host/host_form_controller
//= require controllers/provider_foreman/provider_foreman_form_controller
//= require controllers/repository/repository_form_controller
Expand Down
81 changes: 71 additions & 10 deletions app/assets/javascripts/controllers/host/host_form_controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ManageIQ.angularApplication.controller('hostFormController', ['$http', '$scope', 'hostFormId', 'miqService', function($http, $scope, hostFormId, miqService) {
ManageIQ.angularApplication.controller('hostFormController', ['$http', '$scope', '$attrs', 'hostFormId', 'miqService', function($http, $scope, $attrs, hostFormId, miqService) {
var init = function() {
$scope.hostModel = {
name: '',
Expand Down Expand Up @@ -26,10 +26,15 @@ ManageIQ.angularApplication.controller('hostFormController', ['$http', '$scope',
$scope.modelCopy = angular.copy( $scope.hostModel );
$scope.afterGet = false;
$scope.formId = hostFormId;
ManageIQ.angularApplication.$scope = $scope;
$scope.saveable = miqService.saveable;
$scope.validateClicked = miqService.validateClicked;
$scope.formFieldsUrl = $attrs.formFieldsUrl;
$scope.createUrl = $attrs.createUrl;
$scope.updateUrl = $attrs.updateUrl;
ManageIQ.angularApplication.$scope = $scope;

if (hostFormId == 'new') {
$scope.newRecord = true;
$scope.hostModel.name = "";
$scope.hostModel.hostname = "";
$scope.hostModel.ipmi_address = "";
Expand All @@ -52,9 +57,9 @@ ManageIQ.angularApplication.controller('hostFormController', ['$http', '$scope',
$scope.hostModel.validate_id = "";
$scope.afterGet = true;

} else {
} else if (hostFormId.split(",").length == 1) {
miqService.sparkleOn();
$http.get('/host/host_form_fields/' + hostFormId).success(function(data) {
$http.get($scope.formFieldsUrl + hostFormId).success(function (data) {
$scope.hostModel.name = data.name;
$scope.hostModel.hostname = data.hostname;
$scope.hostModel.ipmi_address = data.ipmi_address;
Expand All @@ -81,14 +86,15 @@ ManageIQ.angularApplication.controller('hostFormController', ['$http', '$scope',
$scope.modelCopy = angular.copy( $scope.hostModel );
miqService.sparkleOff();
});
}
} else if (hostFormId.split(",").length > 1) {
$scope.afterGet = true;
}

$scope.currentTab = "default";

$scope.$watch("hostModel.name", function() {
$scope.form = $scope.angularForm;
$scope.model = "hostModel";
$scope.miqService = miqService;
});
};

Expand All @@ -105,17 +111,25 @@ ManageIQ.angularApplication.controller('hostFormController', ['$http', '$scope',
$scope.cancelClicked = function() {
miqService.sparkleOn();
if (hostFormId == 'new') {
var url = '/host/create/new' + '?button=cancel';
var url = $scope.createUrl + 'new?button=cancel';
}
else {
var url = '/host/update/' + hostFormId + '?button=cancel';
else if (hostFormId.split(",").length == 1) {
var url = $scope.updateUrl + hostFormId + '?button=cancel';
}
else if (hostFormId.split(",").length > 1) {
var url = $scope.updateUrl + '?button=cancel';
}
miqService.miqAjaxButton(url);
};

$scope.saveClicked = function() {
miqService.sparkleOn();
var url = '/host/update/' + hostFormId + '?button=save';
if (hostFormId.split(",").length > 1) {
var url = $scope.updateUrl + '?button=save';
}
else {
var url = $scope.updateUrl + hostFormId + '?button=save';
}
miqService.miqAjaxButton(url, true);
};

Expand All @@ -135,21 +149,25 @@ ManageIQ.angularApplication.controller('hostFormController', ['$http', '$scope',

$scope.isBasicInfoValid = function() {
if(($scope.currentTab == "default") &&
($scope.hostModel.hostname || $scope.hostModel.validate_id) &&
($scope.hostModel.default_userid != '' && $scope.angularForm.default_userid.$valid &&
$scope.hostModel.default_password != '' && $scope.angularForm.default_password.$valid &&
$scope.hostModel.default_verify != '' && $scope.angularForm.default_verify.$valid)) {
return true;
} else if(($scope.currentTab == "remote") &&
($scope.hostModel.hostname || $scope.hostModel.validate_id) &&
($scope.hostModel.remote_userid != '' && $scope.angularForm.remote_userid.$valid &&
$scope.hostModel.remote_password != '' && $scope.angularForm.remote_password.$valid &&
$scope.hostModel.remote_verify != '' && $scope.angularForm.remote_verify.$valid)) {
return true;
} else if(($scope.currentTab == "ws") &&
($scope.hostModel.hostname || $scope.hostModel.validate_id) &&
($scope.hostModel.ws_userid != '' && $scope.angularForm.ws_userid.$valid &&
$scope.hostModel.ws_password != '' && $scope.angularForm.ws_password.$valid &&
$scope.hostModel.ws_verify != '' && $scope.angularForm.ws_verify.$valid)) {
return true;
} else if(($scope.currentTab == "ipmi") &&
($scope.hostModel.ipmi_address) &&
($scope.hostModel.ipmi_userid != '' && $scope.angularForm.ipmi_userid.$valid &&
$scope.hostModel.ipmi_password != '' && $scope.angularForm.ipmi_password.$valid &&
$scope.hostModel.ipmi_verify != '' && $scope.angularForm.ipmi_verify.$valid)) {
Expand All @@ -158,5 +176,48 @@ ManageIQ.angularApplication.controller('hostFormController', ['$http', '$scope',
return false;
};

$scope.canValidate = function () {
if ($scope.isBasicInfoValid() && $scope.validateFieldsDirty())
return true;
else
return false;
}

$scope.canValidateBasicInfo = function () {
if ($scope.isBasicInfoValid())
return true;
else
return false;
}

$scope.validateFieldsDirty = function () {
if(($scope.currentTab == "default") &&
(($scope.angularForm.hostname.$dirty || $scope.angularForm.validate_id.$dirty) &&
$scope.angularForm.default_userid.$dirty &&
$scope.angularForm.default_password.$dirty &&
$scope.angularForm.default_verify.$dirty)) {
return true;
} else if(($scope.currentTab == "remote") &&
(($scope.angularForm.hostname.$dirty || $scope.angularForm.validate_id.$dirty) &&
$scope.angularForm.remote_userid.$dirty &&
$scope.angularForm.remote_password.$dirty &&
$scope.angularForm.remote_verify.$dirty)) {
return true;
} else if(($scope.currentTab == "ws") &&
(($scope.angularForm.hostname.$dirty || $scope.angularForm.validate_id.$dirty) &&
$scope.angularForm.ws_userid.$dirty &&
$scope.angularForm.ws_password.$dirty &&
$scope.angularForm.ws_verify.$dirty)) {
return true;
} else if(($scope.currentTab == "ipmi") &&
($scope.angularForm.ipmi_address.$dirty &&
$scope.angularForm.ipmi_userid.$dirty &&
$scope.angularForm.ipmi_password.$dirty &&
$scope.angularForm.ipmi_verify.$dirty)) {
return true;
} else
return false;
}

init();
}]);
37 changes: 0 additions & 37 deletions app/assets/javascripts/directives/host/multiple_tabs.js

This file was deleted.

66 changes: 7 additions & 59 deletions app/assets/javascripts/services/miq_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ ManageIQ.angularApplication.service('miqService', function() {
var outerBox = $('<div class="alert alert-success">');
var innerSpan = $('<span class="pficon pficon-ok">');
}
$(outerBox).append(innerSpan);
$(outerBox).append(txt);
$(outerMost).append(outerBox);
$(outerMost).appendTo($("#flash_msg_div"));
$(outerBox).append(innerSpan);
$(outerBox).append(txt);
$(outerMost).append(outerBox);
$(outerMost).appendTo($("#flash_msg_div"));
}

this.miqFlashClear = function() {
Expand All @@ -66,61 +66,9 @@ ManageIQ.angularApplication.service('miqService', function() {
return form.$valid && form.$dirty;
};

this.canValidate = function (form, prefix) {
if (this.validateFieldsValid(form, prefix) && this.validateFieldsDirty(form, prefix))
return true;
else
return false;
}

this.canValidateBasicInfo = function () {
if (ManageIQ.angularApplication.$scope.isBasicInfoValid())
return true;
else
return false;
}

this.validateFieldsValid = function (form, prefix) {
if (form != undefined) {
if (prefix == "log") {
if (form.depot_name.$valid &&
form.uri.$valid &&
form[prefix + '_userid'].$valid &&
form[prefix + '_password'].$valid &&
form[prefix + '_verify'].$valid)
return true;
} else {
if (form[prefix + '_userid'].$valid &&
form[prefix + '_password'].$valid &&
form[prefix + '_verify'].$valid)
return true;
}
} else
return false;
}

this.validateFieldsDirty = function (form, prefix) {
if (form != undefined) {
if (prefix == "log") {
if (form.depot_name.$dirty ||
form.uri.$dirty ||
form[prefix + '_userid'].$dirty ||
form[prefix + '_password'].$dirty ||
form[prefix + '_verify'].$dirty)
return true;
} else {
if (form[prefix + '_userid'].$dirty ||
form[prefix + '_password'].$dirty ||
form[prefix + '_verify'].$dirty)
return true;
}
} else
return false;
}

this.validateClicked = function (url) {
this.sparkleOn();
this.miqAjaxButton(url, true);
this.validateClicked = function (url) {
miqSparkleOn();
miqAjaxButton(url, true);
};

this.serializeModel = function(model) {
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/host_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ def create
add_flash(_("Credential validation was successful"))
end
render :update do |page|
p "XXXXXX"
page.replace("flash_msg_div", :partial=>"layouts/flash_msg")
end
end
Expand Down Expand Up @@ -334,7 +333,6 @@ def update
assert_privileges("host_edit")
case params[:button]
when "cancel"
@host = find_by_id_filtered(Host, params[:id])
session[:edit] = nil # clean out the saved info
flash = "Edit for Host \""
@breadcrumbs.pop if @breadcrumbs
Expand All @@ -345,6 +343,7 @@ def update
page.redirect_to :action=>@lastaction, :display=>session[:host_display], :flash_msg=>flash
end
else
@host = find_by_id_filtered(Host, params[:id])
flash = _("Edit of %{model} \"%{name}\" was cancelled by the user") % {:model=>ui_lookup(:model=>"Host"), :name=>@host.name}
render :update do |page|
page.redirect_to :action=>@lastaction, :id=>@host.id, :display=>session[:host_display], :flash_msg=>flash
Expand Down Expand Up @@ -593,11 +592,11 @@ def host_form_fields
host_hash = {
:name => host.name,
:hostname => host.hostname,
:ipmi_address => host.ipmi_address,
:custom_1 => host.custom_1,
:ipmi_address => host.ipmi_address ? host.ipmi_address : "",
:custom_1 => host.custom_1 ? host.custom_1 : "",
:user_assigned_os => host.user_assigned_os,
:operating_system => !(host.operating_system.nil? || host.operating_system.product_name.nil?),
:mac_address => host.mac_address,
:mac_address => host.mac_address ? host.mac_address : "",
:default_userid => host.authentication_userid.to_s,
:default_password => host.authentication_password.to_s,
:default_verify => host.authentication_password.to_s,
Expand Down
Loading

0 comments on commit 836e5eb

Please sign in to comment.