Commit 9a0cfb99 authored by Majerti - Tjebbes's avatar Majerti - Tjebbes

Merge branch 'jd-further-js-BaseModel-factorization' into 'master'

Poursuit le factoring autour du BaseModel JS.

See merge request !1167
parents be6d86fd 0a8bc1aa
Pipeline #136114 passed with stage
in 5 minutes and 21 seconds
import Radio from 'backbone.radio';
import { ajax_call } from '../../tools.js';
const DuplicableMixin = {
/**
* A mixin for models that implement back-end duplication.
*
* REST API side has to offer a ?action=duplicate on resource.
*
* duplicate() method to the model.
*/
onDuplicateError: function(result){
this.collection.fetch();
let channel = Radio.channel('message');
channel.trigger('error:ajax', result);
},
onDuplicateCallback: function(result){
this.collection.fetch();
let channel = Radio.channel('message');
channel.trigger('success:ajax', result);
},
duplicate: function(datas){
var request = ajax_call(
this.url() + '?action=duplicate',
datas,
'POST'
);
request.done(
this.onDuplicateCallback.bind(this)
).fail(
this.onDuplicateError.bind(this)
);
return request;
},
};
export default DuplicableMixin;
import Bb from 'backbone'; import Bb from 'backbone';
import Radio from 'backbone.radio'; import Radio from 'backbone.radio';
import BaseModel from '../../base/models/BaseModel.js';
import DuplicableMixin from '../../base/models/DuplicableMixin.js';
import { ajax_call } from '../../tools.js'; import { ajax_call } from '../../tools.js';
const BaseModel = Bb.Model.extend({ const ExpenseBaseModel = BaseModel.extend(DuplicableMixin).extend({
/* /*
* BaseModel for expenses, provides tools to access main options * BaseModel for expenses, provides tools to access main options
*/ */
...@@ -39,32 +42,5 @@ const BaseModel = Bb.Model.extend({ ...@@ -39,32 +42,5 @@ const BaseModel = Bb.Model.extend({
return current_type.label; return current_type.label;
} }
}, },
rollback: function(){
if (this.get('id') && this.url){
this.fetch();
}
},
onDuplicateError(result){
this.collection.fetch();
let channel = Radio.channel('message');
channel.trigger('error:ajax', result);
},
onDuplicateCallback(result){
this.collection.fetch();
let channel = Radio.channel('message');
channel.trigger('success:ajax', result);
},
duplicate(datas){
var request = ajax_call(
this.url() + '?action=duplicate',
datas,
'POST'
);
request.done(this.onDuplicateCallback.bind(this)
).fail(
this.onDuplicateError.bind(this)
);
return request;
},
}); });
export default BaseModel; export default ExpenseBaseModel;
import BaseModel from './BaseModel.js'; import ExpenseBaseModel from './ExpenseBaseModel.js';
import { formatPaymentDate } from '../../date.js'; import { formatPaymentDate } from '../../date.js';
import Radio from 'backbone.radio'; import Radio from 'backbone.radio';
const ExpenseKmModel = BaseModel.extend({ const ExpenseKmModel = ExpenseBaseModel.extend({
defaults:{ defaults:{
type: 'km', type: 'km',
category:null, category:null,
......
import BaseModel from './BaseModel.js'; import ExpenseBaseModel from './ExpenseBaseModel.js';
import { formatPaymentDate } from '../../date.js'; import { formatPaymentDate } from '../../date.js';
import { getPercent } from '../../math.js'; import { getPercent } from '../../math.js';
import Radio from 'backbone.radio'; import Radio from 'backbone.radio';
const ExpenseModel = BaseModel.extend({ const ExpenseModel = ExpenseBaseModel.extend({
defaults:{ defaults:{
category: null, category: null,
description:"", description:"",
......
import _ from 'underscore';
import Bb from 'backbone';
const BaseModel = Bb.Model.extend({
props: null,
constructor: function() {
if (!_.isNull(this.props)){
arguments[0] = _.pick(arguments[0], this.props);
arguments[0] = _.omit(arguments[0], function(value){
return _.isNull(value) || _.isUndefined(value);
});
}
Bb.Model.apply(this, arguments);
},
toJSON: function(options) {
var attributes = _.clone(this.attributes);
if (!_.isNull(this.props)){
attributes = _.pick(attributes, this.props);
attributes = _.omit(attributes, function(value){
return _.isNull(value) || _.isUndefined(value);
});
}
return attributes;
},
rollback: function(){
if (this.get('id')){
this.fetch();
}
}
});
export default BaseModel;
import _ from 'underscore';
import Bb from 'backbone';
const BaseModel = Bb.Model.extend({
props: null,
constructor: function() {
if (!_.isNull(this.props)){
arguments[0] = _.pick(arguments[0], this.props);
arguments[0] = _.omit(arguments[0], function(value){
return _.isNull(value) || _.isUndefined(value);
});
}
Bb.Model.apply(this, arguments);
},
toJSON: function(options) {
var attributes = _.clone(this.attributes);
if (!_.isNull(this.props)){
attributes = _.pick(attributes, this.props);
attributes = _.omit(attributes, function(value){
return _.isNull(value) || _.isUndefined(value);
});
}
return attributes;
},
rollback: function(){
if (this.get('id')){
this.fetch();
}
}
});
export default BaseModel;
import _ from 'underscore'; import _ from 'underscore';
import BaseModel from "./BaseModel.js"; import BaseModel from "../../base/models/BaseModel.js";
import { getTvaPart, strToFloat } from '../../math.js'; import { getTvaPart, strToFloat } from '../../math.js';
import Radio from 'backbone.radio'; import Radio from 'backbone.radio';
......
import Bb from 'backbone'; import Bb from 'backbone';
import { strToFloat, getTvaPart } from '../../math.js'; import { strToFloat, getTvaPart } from '../../math.js';
import BaseModel from './BaseModel.js'; import BaseModel from '../../base/models/BaseModel.js';
const DiscountModel = BaseModel.extend({ const DiscountModel = BaseModel.extend({
props: [ props: [
......
import Bb from 'backbone'; import Bb from 'backbone';
import BaseModel from "./BaseModel.js"; import BaseModel from "../../base/models/BaseModel.js";
import { dateToIso } from '../../date.js'; import { dateToIso } from '../../date.js';
import { strToFloat } from "../../math.js"; import { strToFloat } from "../../math.js";
......
import _ from 'underscore'; import _ from 'underscore';
import TaskLineCollection from './TaskLineCollection.js'; import TaskLineCollection from './TaskLineCollection.js';
import BaseModel from "./BaseModel.js"; import BaseModel from "../../base/models/BaseModel.js";
const TaskGroupModel = BaseModel.extend({ const TaskGroupModel = BaseModel.extend({
......
import _ from 'underscore'; import _ from 'underscore';
import Bb from 'backbone'; import Bb from 'backbone';
import { strToFloat, getTvaPart } from '../../math.js'; import { strToFloat, getTvaPart } from '../../math.js';
import BaseModel from "./BaseModel.js"; import BaseModel from "../../base/models/BaseModel.js";
const TaskLineModel = BaseModel.extend({ const TaskLineModel = BaseModel.extend({
props: [ props: [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment