update customer

This commit is contained in:
Shaun Chyxion 2018-04-08 22:50:45 +08:00
parent c6f528b8ae
commit 3ec4ecf076
9 changed files with 32 additions and 89 deletions

View File

@ -158,7 +158,9 @@ public class CustomerController
@RequiresRoles(User.ROLE_ADMIN)
@RequestMapping("/export")
public ResourceModel exportCSV() {
return new ResourceModel(((CustomerService) queryService).exportCSV(getUserId()), null, null);
return new ResourceModel(
((CustomerService) queryService).exportCSV(getUserId()),
"text/csv; charset=gbk", null);
}
/**

View File

@ -161,8 +161,8 @@ public class CustomerServiceSupport
final String customerId = form.getId();
customerApplicationMapper.delete(
new Search(CustomerApplication.CUSTOMER_ID, customerId));
final List<String> applications = form.getApplications();
if (applications != null) {
final String[] applications = form.getApplications();
if (applications != null && applications.length > 0) {
final String operator = form.getUpdatedBy();
final Date now = new Date();
for (final String applicationId : applications) {

View File

@ -1,8 +1,7 @@
package com.pudonghot.ambition.crm.mapper;
import java.util.List;
import java.util.Map;
import java.util.List;
import me.chyxion.tigon.mybatis.Search;
import me.chyxion.tigon.mybatis.BaseMapper;
import org.apache.ibatis.annotations.Param;

View File

@ -5,7 +5,6 @@ import lombok.Setter;
import java.util.List;
import me.chyxion.tigon.form.FU2;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import me.chyxion.tigon.format.annotation.EmptyToNull;
/**
@ -21,24 +20,8 @@ public class CustomerFormForUpdate extends FU2<String, String> {
private static final long serialVersionUID = 1L;
// Properties
@NotBlank
@Length(max = 36)
private String salesperson;
@NotBlank
@Length(max = 36)
private String name;
@EmptyToNull
private String countryCode;
@EmptyToNull
private String state;
@EmptyToNull
private String city;
@EmptyToNull
private String ms;
@EmptyToNull
private String region;
@EmptyToNull
@Length(max = 36)
private String status;
private List<String> applications;
private String[] applications;
}

View File

@ -1,6 +1,5 @@
import Ember from 'ember';
import BaseComponent from './base-component';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
@ -15,6 +14,7 @@ export default BaseComponent.extend({
backRouteParams: computed.alias('back-route-params'),
hideGoback: computed.alias('no-goback'),
hideSubmit: computed.alias('no-submit'),
'back-to-list': false,
backToList() {
const me = this;
let listRouteName = me.get('routeName').replace(/[^.]+$/, 'list');
@ -48,6 +48,9 @@ export default BaseComponent.extend({
me.get('backRouteParams'),
me.get('backRouteQueryParams'));
}
else if (me.get('back-to-list')) {
me.backToList();
}
else {
me.get('state').back() || me.backToList();
}
@ -59,7 +62,6 @@ export default BaseComponent.extend({
me.postData().then((m) => {
Ember.Logger.info('Post Model Result: ', m);
// write back
// TODO write update back
Ember.setProperties(me.getModel(), m);
me.alertMessage();
me.send('goback');
@ -93,7 +95,7 @@ export default BaseComponent.extend({
alertMessage() {
let me = this;
me.message.alert(me.get('successMsg') ||
(me.isCreate() ? 'Created successfully' : 'Updated successfully'));
(me.isCreate() ? 'Created successfully' : 'Updated successfully'));
},
getModel() {
return this.get('route.controller.model');

View File

@ -3,34 +3,18 @@ import BaseEditRoute from '../base-edit';
export default BaseEditRoute.extend({
afterModel(model) {
this.set('breadcrumbs',
const me = this;
me._super(...arguments);
me.set('breadcrumbs',
[{route: 'customer.list', params: 1, text: 'Customers'},
{text: 'Edit Customer [' + model.id + ']'}]);
if (model.applications) {
model.applicationsArray = model.applications.split(',');
let selected = model.applications.split(String.fromCharCode(0x1d));
model.applicationList.forEach(a => {
a.selected = model.applicationsArray.includes(a.id);
a.selected = selected.includes(a.id);
});
}
else {
model.applicationsArray = [];
}
Ember.addObserver(model, 'applicationsArray', function() {
Ember.Logger.info('Model application changed: ', model);
model.applications = model.applicationsArray.join(',');
me.get('service').update(model, true);
});
Ember.addObserver(model, 'status', function() {
Ember.Logger.info('Model status changed: ', model);
if (model.status) {
model.applications = model.applicationsArray.join(',');
me.get('service').update(model, true);
}
});
}
});

View File

@ -5,33 +5,19 @@ export default BaseEditRoute.extend({
issueService: Ember.inject.service('customer-issue/service'),
afterModel(model) {
let me = this;
me._super(...arguments);
me.set('breadcrumbs',
[{route: 'customer.list', params: 1, text: 'Customers'},
{text: 'Show Customer [' + model.id + ']'}]);
if (model.applications) {
model.applicationsArray = model.applications.split(',');
let selected = model.applications.split(String.fromCharCode(0x1d));
model.applicationList.forEach(a => {
a.selected = model.applicationsArray.includes(a.id);
a.selected = selected.includes(a.id);
});
}
else {
model.applicationsArray = [];
}
Ember.addObserver(model, 'applicationsArray', function() {
Ember.Logger.info('Model application changed: ', model);
model.applications = model.applicationsArray.join(',');
// me.get('service').update(model, true);
});
Ember.addObserver(model, 'status', function() {
Ember.Logger.info('Model status changed: ', model);
if (model.status) {
model.applications = model.applicationsArray.join(',');
// me.get('service').update(model, true);
}
});
Ember.set(model, 'userAccounts', Ember.get(model, 'users').mapBy('account').join(', '));
},
actions: {
@ -44,25 +30,6 @@ export default BaseEditRoute.extend({
me.get('controller.model.issues').removeObject(issue);
});
});
},
backToList() {
const me = this;
const url = me.get('state.CUSTOMER_LIST_ROUTE');
if (url) {
me.transitionTo(url);
}
else {
me.transitionTo('customer.list', 1);
}
},
update() {
const me = this;
me.get('dialog').confirm('Are you sure to update?', () => {
me.get('service').update(me.get('controller.model'), false).then(() => {
me.get('message').alert('Update successfully');
me.send('backToList');
});
});
}
}
}
});

View File

@ -68,7 +68,9 @@
</td>
<td>
<div class="hidden-sm hidden-xs btn-group">
{{#if ajax.user.admin}}
{{status-toggle-button model=it}}
{{/if}}
{{#if (eq ajax.user.id it.owner)}}
{{#link-to 'customer-application.edit' it.id class='btn btn-xs btn-info' data-rel='tooltip' title='Edit'}}
@ -76,7 +78,7 @@
{{/link-to}}
{{/if}}
{{#if (or ajax.user.admin (eq ajax.user.id it.owner))}}
{{#if ajax.user.admin}}
{{#unless it.enabled}}
{{delete-btn model=it}}
{{/unless}}
@ -88,9 +90,11 @@
<i class="ace-icon fa fa-cog icon-only bigger-110"></i>
</button>
<ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
{{#if ajax.user.admin}}
<li>
{{status-toggle-button model=it iconOnly=true}}
</li>
{{/if}}
{{#if (eq ajax.user.id it.owner)}}
<li>
{{#link-to 'customer-application.edit' it.id class='tooltip-info' data-rel='tooltip' title='Edit'}}

View File

@ -1,4 +1,6 @@
{{#form-content}}
{{form-input name='id' type='hidden'}}
{{form-input name='enabled' type='hidden'}}
{{form-input type='show' name='id' label='ID'}}
{{form-input type='show' name='name' label='Name'}}
{{form-input type='show' name='countryCode' label='Country'}}
@ -10,7 +12,7 @@
{{form-input-select2
multiple=true
name='applicationsArray'
name='applications'
label='Application'
options=model.applicationList
value-field='id'
@ -146,6 +148,6 @@
</div>
{{/form-input}}
<hr />
{{form-footer-buttons on-goback=(route-action 'backToList') on-submit=(route-action 'update')}}
{{form-footer-buttons type='update'}}
{{/form-content}}
{{outlet}}