TimeTrex Community Edition v16.2.0
This commit is contained in:
136
interface/html5/model/APIReturnHandler.js
Normal file
136
interface/html5/model/APIReturnHandler.js
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
|
||||
To be the common data model for data return from api
|
||||
|
||||
*/
|
||||
import { Base } from './Base';
|
||||
|
||||
export class APIReturnHandler extends Base {
|
||||
|
||||
constructor( options = {} ) {
|
||||
_.defaults( options, {
|
||||
result_data: null,
|
||||
delegate: null
|
||||
} );
|
||||
|
||||
super( options );
|
||||
}
|
||||
|
||||
isValid() {
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_retval ) && this.get( 'result_data' ).api_retval === false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
getDetails() {
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_details ) && Global.isSet( this.get( 'result_data' ).api_details.details ) ) {
|
||||
return this.get( 'result_data' ).api_details.details;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
getPagerData() {
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_details ) && Global.isSet( this.get( 'result_data' ).api_details.pager ) ) {
|
||||
return this.get( 'result_data' ).api_details.pager;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getResult() {
|
||||
|
||||
var result;
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_retval ) ) {
|
||||
result = this.get( 'result_data' ).api_retval;
|
||||
} else {
|
||||
result = this.get( 'result_data' );
|
||||
}
|
||||
|
||||
if ( typeof result === 'undefined' ) {
|
||||
result = null;
|
||||
} else if ( $.type( result ) === 'array' && result.length === 0 ) {
|
||||
result = {};
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
getCode() {
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_details ) && Global.isSet( this.get( 'result_data' ).api_details.code ) ) {
|
||||
return this.get( 'result_data' ).api_details.code;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getDescription() {
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_details ) && Global.isSet( this.get( 'result_data' ).api_details.description ) ) {
|
||||
return this.get( 'result_data' ).api_details.description;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getRecordDetails() {
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_details ) && Global.isSet( this.get( 'result_data' ).api_details.record_details ) ) {
|
||||
return this.get( 'result_data' ).api_details.record_details;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getTotalRecords() {
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_details ) && Global.isSet( this.get( 'result_data' ).api_details.record_details ) &&
|
||||
Global.isSet( this.get( 'result_data' ).api_details.record_details.total_records ) ) {
|
||||
return this.get( 'result_data' ).api_details.record_details.total_records;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getValidRecords() {
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_details ) && Global.isSet( this.get( 'result_data' ).api_details.record_details ) &&
|
||||
Global.isSet( this.get( 'result_data' ).api_details.record_details.valid_records ) ) {
|
||||
return this.get( 'result_data' ).api_details.record_details.valid_records;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getInValidRecords() {
|
||||
if ( Global.isSet( this.get( 'result_data' ).api_details ) && Global.isSet( this.get( 'result_data' ).api_details.record_details ) &&
|
||||
Global.isSet( this.get( 'result_data' ).api_details.record_details.invalid_records ) ) {
|
||||
return this.get( 'result_data' ).api_details.record_details.invalid_records;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getAttributeInAPIDetails( attrName ) {
|
||||
let result_data = this.get( 'result_data' );
|
||||
|
||||
if ( result_data && result_data.api_details ) {
|
||||
return result_data.api_details[attrName];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getDetailsAsString() {
|
||||
var errorInfo = '';
|
||||
|
||||
$.each( this.getDetails(), function( index, errorItem ) {
|
||||
|
||||
for ( var i in errorItem ) {
|
||||
errorInfo += errorItem[i][0] + '\r';
|
||||
}
|
||||
} );
|
||||
|
||||
return errorInfo;
|
||||
}
|
||||
|
||||
}
|
9
interface/html5/model/Base.js
Normal file
9
interface/html5/model/Base.js
Normal file
@ -0,0 +1,9 @@
|
||||
export class Base extends Backbone.Model {
|
||||
|
||||
constructor( options = {} ) {
|
||||
_.defaults( options, {
|
||||
} );
|
||||
|
||||
super( options );
|
||||
}
|
||||
}
|
13
interface/html5/model/ResponseObject.js
Normal file
13
interface/html5/model/ResponseObject.js
Normal file
@ -0,0 +1,13 @@
|
||||
import { Base } from './Base';
|
||||
|
||||
export class ResponseObject extends Base {
|
||||
constructor( options = {} ) {
|
||||
_.defaults( options, {
|
||||
onResult: null,
|
||||
onError: null,
|
||||
delegate: null,
|
||||
async: null
|
||||
} );
|
||||
super( options );
|
||||
}
|
||||
}
|
29
interface/html5/model/SearchField.js
Normal file
29
interface/html5/model/SearchField.js
Normal file
@ -0,0 +1,29 @@
|
||||
import { Base } from '@/model/Base';
|
||||
|
||||
export class SearchField extends Base {
|
||||
constructor( options = {} ) {
|
||||
_.defaults( options, {
|
||||
label: null,
|
||||
field: null,
|
||||
api_class: null,
|
||||
layout_name: '',
|
||||
multiple: true,
|
||||
optionName: '',
|
||||
form_item_type: '',
|
||||
in_column: 1,
|
||||
basic_search: false,
|
||||
adv_search: false,
|
||||
tree_mode: false,
|
||||
data_provider: null,
|
||||
script_name: '',
|
||||
addition_source_function: null,
|
||||
set_any: true,
|
||||
object_type_id: -1,
|
||||
customSearchFilter: null,
|
||||
custom_first_label: null,
|
||||
default_args: null
|
||||
} );
|
||||
|
||||
super( options );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user