Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Price to Catalog Items. #5719

Merged
merged 9 commits into from
Jul 4, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -87,6 +87,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', '$timeou
vm.modelCopy = angular.copy(vm.catalogItemModel);
});
}
vm.priceRequired();
};

listenToRx(function(data) {
@@ -446,6 +447,11 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', '$timeou
vm.catalogItemModel[prefix + '_dialog_name'] = '';
};

vm.priceRequired = function() {
return (typeof vm.catalogItemModel.currency_id !== 'undefined' && vm.catalogItemModel.currency_id !== ''
&& (typeof vm.catalogItemModel.price === 'undefined' || vm.catalogItemModel.price === ''))
};

vm.fieldsRequired = function(prefix) {
return prefix === 'provisioning';
};
@@ -462,8 +468,10 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', '$timeou
var fieldName = 'vm._' + name;
$scope.$watch(fieldName, function(value) {
vm.catalogItemModel[name + '_id'] = value ? value.id : '';
if (name == 'currency' && typeof value !== 'undefined')
if (name == 'currency' && typeof value !== 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (name == 'currency' && ! value) should fix the problem when unsetting currency. (It goes from undefined to a currency, but then it goes to null, not undefined, when unselecting.)

vm.catalogItemModel.currency_name = _.find(vm.currencies, {id: value.id}).code;
himdel marked this conversation as resolved.
Show resolved Hide resolved
vm.priceRequired();
}
playbookReusableCodeMixin.checkFormPristine(vm.catalogItemModel, vm.modelCopy, $scope.angularForm);
});
}
11 changes: 10 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
@@ -307,6 +307,7 @@ def st_edit
add_flash(_("Resource must be selected"), :error)
end
add_flash(_("Provisioning Entry Point is required"), :error) if @edit[:new][:fqname].blank?
validate_price
dialog_catalog_check

if @flash_array
@@ -843,7 +844,7 @@ def atomic_req_submit
end

add_flash(_("Provisioning Entry Point is required"), :error) if @edit[:new][:fqname].blank?

validate_price
# Check for a Dialog if Display in Catalog is selected
dialog_catalog_check

@@ -1064,6 +1065,8 @@ def common_st_record_vars(st)
st.generic_subtype = @edit[:new][:generic_subtype] if @edit[:new][:st_prov_type] == 'generic'
st.zone_id = @edit[:new][:zone_id]
st.additional_tenants = Tenant.where(:id => @edit[:new][:tenant_ids]) # Selected Additional Tenants in the tree
st.currency = ChargebackRateDetailCurrency.find_by(:id => @edit[:new][:currency].to_i) if @edit[:new][:currency]
st.price = @edit[:new][:price] if @edit[:new][:price]
end

def st_set_record_vars(st)
@@ -2009,6 +2012,12 @@ def dialog_catalog_check
add_flash(_("Dialog has to be set if Display in Catalog is chosen"), :error)
end

def validate_price
if @edit[:new][:currency] && @edit[:new][:price].blank?
add_flash(_("Price is required"), :error)
end
end

def x_edit_tags_reset(db)
@tagging = session[:tag_db] = db
checked_ids = find_checked_items.empty? ? [params[:id]] : find_checked_items
7 changes: 6 additions & 1 deletion app/views/catalog/_st_angular_form.html.haml
Original file line number Diff line number Diff line change
@@ -87,17 +87,22 @@
'ng-options' => 'currency as currency.symbol + " [" + currency.full_name + "]" for currency in vm.currencies',
"data-live-search" => "true",
'miq-select' => true}
%option{"value" => ""} <Choose>

.form-group
.form-group{"ng-class" => "{'has-error': vm.priceRequired()}"}
%label.col-md-2.control-label{"for" => "price"}
= _("Price (in {{vm.catalogItemModel.currency_name}})")
.col-md-8
%input.form-control{"type" => "text",
"id" => "price",
"name" => "price",
"ng-model" => "vm.catalogItemModel.price",
"ng-change" => "vm.priceRequired()",
"ng-required" => "vm.priceRequired()",
"maxlength" => 60,
"checkchange" => ""}
%span.help-block{"ng-show" => "vm.priceRequired()"}
= _("Required")

= render :partial => "layouts/angular/multi_tab_ansible_form_options",
:locals => {:record => @record, :ng_model => "vm.catalogItemModel"}