Пример #1
0
QUnit.test("extending DefineList constructor functions (#61)", function(){
  var AList = DefineList.extend('AList', { aProp: {}, aMethod: function(){} });
  var BList = AList.extend('BList', { bProp: {}, bMethod: function(){} });
  var CList = BList.extend('CList', { cProp: {}, cMethod: function(){} });

  var list = new CList([{},{}]);

  list.on("aProp", function(ev, newVal, oldVal){
      QUnit.equal(newVal, "PROP");
      QUnit.equal(oldVal, undefined);
  });
  list.on("bProp", function(ev, newVal, oldVal){
      QUnit.equal(newVal, "FOO");
      QUnit.equal(oldVal, undefined);
  });
  list.on("cProp", function(ev, newVal, oldVal){
      QUnit.equal(newVal, "BAR");
      QUnit.equal(oldVal, undefined);
  });

  list.aProp = "PROP";
  list.bProp = 'FOO';
  list.cProp = 'BAR';

  QUnit.ok(list.aMethod);
  QUnit.ok(list.bMethod);
  QUnit.ok(list.cMethod);
});
Пример #2
0
test("list defines", 6, function(){
    var Todo = function(props){
        assign(this, props);
        CID(this);
    };
    define(Todo.prototype,{
        completed: "boolean",
        destroyed: {
            value: false
        }
    });
    Todo.prototype.destroy = function(){
        this.destroyed = true;
    };

    var TodoList = DefineList.extend({

    	"*": Todo,
    	remaining: {
    		get: function() {
    			return this.filter({
    				completed: false
    			});
    		}
    	},
    	completed: {
    		get: function() {
    			return this.filter({
    				completed: true
    			});
    		}
    	},

    	destroyCompleted: function() {
    		this.completed.forEach(function(todo) {
    			todo.destroy();
    		});
    	},
    	setCompletedTo: function(value) {
    		this.forEach(function(todo) {
    			todo.completed = value;
    		});
    	}
    });

    var todos = new TodoList([{completed: true},{completed: false}]);

    ok(todos.item(0) instanceof Todo, "correct instance");
    equal(todos.completed.length, 1, "only one todo");

    todos.on("completed", function(ev, newVal, oldVal){
        ok(newVal instanceof TodoList, "right type");
        equal(newVal.length, 2, "all items");
        ok(oldVal instanceof TodoList, "right type");
        equal(oldVal.length, 1, "all items");
    });

    todos.setCompletedTo(true);

});
Пример #3
0
test('reverse returns the same list instance (#1744)', function() {
	var ParentList = DefineList.extend();
	var ChildList = ParentList.extend();

	var children = new ChildList([1,2,3]);
	ok(children.reverse() === children);
});
Пример #4
0
test('list.map', function(){
	var myArray = [
	    {id: 1, name: "Marshall"},
	    {id: 2, name: "Austin"},
	    {id: 3, name: "Hyrum"}
    ];
    var myList = new DefineList(myArray);
    var newList = myList.map(function(person) {
        person.lastName = "Thompson";
        return person;
    });

    equal(newList.length, 3);
    equal(newList[0].name, "Marshall");
    equal(newList[0].lastName, "Thompson");
    equal(newList[1].name, "Austin");
    equal(newList[1].lastName, "Thompson");
    equal(newList[2].name, "Hyrum");
    equal(newList[2].lastName, "Thompson");

    var ExtendedList = DefineList.extend({
		testMe: function(){
			return "It Worked!";
		}
	});
	var myExtendedList = new ExtendedList(myArray);
	var newExtendedList = myExtendedList.map(function(person) {
    person.lastName = "Thompson";
	    return person;
	});
	QUnit.equal("It Worked!", newExtendedList.testMe(), 'Returns the same type of list.');
});
Пример #5
0
test('Lists with maps concatenate properly', function() {
	var Person = DefineMap.extend();
	var People = DefineList.extend({
		'#': Person
	});
	var Genius = Person.extend();
	var Animal = DefineMap.extend();

	var me = new Person({ name: "John" });
	var animal = new Animal({ name: "Tak" });
	var genius = new Genius({ name: "Einstein" });
	var hero = { name: "Ghandi" };

	var people = new People([]);
	var specialPeople = new People([
		genius,
		hero
	]);

	people = people.concat([me, animal, specialPeople], specialPeople, [1, 2], 3);

	ok(people.length === 8, "List length is right");
	ok(people[0] === me, "Map in list === vars created before concat");
	ok(people[1] instanceof Person, "Animal got serialized to Person");
});
Пример #6
0
QUnit.test("shorthand getter setter (#56)", function(){

    var People = DefineList.extend({
		first: "*",
		last: "*",
		get fullName() {
			return this.first + " " + this.last;
		},
		set fullName(newVal){
			var parts = newVal.split(" ");
			this.first = parts[0];
			this.last = parts[1];
		}
	});

	var p = new People([]);
    p.fullName = "Mohamed Cherif";

	p.on("fullName", function(ev, newVal, oldVal) {
		QUnit.equal(oldVal, "Mohamed Cherif");
		QUnit.equal(newVal, "Justin Meyer");
	});

	equal(p.fullName, "Mohamed Cherif", "fullName initialized right");

	p.fullName = "Justin Meyer";
});
Пример #7
0
test('filter returns same list type (#1744)', function() {
	var ParentList = DefineList.extend();
	var ChildList = ParentList.extend();

	var children = new ChildList([1,2,3]);

	ok(children.filter(function() {}) instanceof ChildList);
});
Пример #8
0
QUnit.test("extending the base supports overwriting _eventSetup", function(){
    var L = DefineList.extend({});
    Object.getOwnPropertyDescriptor(DefineMap.prototype,"_eventSetup");
    L.prototype.arbitraryProp = true;
    ok(true,"set arbitraryProp");
    L.prototype._eventSetup = function(){};
    ok(true, "worked");
});
Пример #9
0
QUnit.test("extending DefineList constructor functions - value (#61)", function(){
    var AList = DefineList.extend("AList", { aProp: {value: 1} });

    var BList = AList.extend("BList", { });

    var CList = BList.extend("CList",{ });

    var c = new CList([]);
    QUnit.equal( c.aProp , 1 ,"got initial value" );
});
Пример #10
0
QUnit.test("serialize works", function(){
    var Person = DefineMap.extend({
        first: "string",
        last: "string"
    });
    var People = DefineList.extend({
        "*": Person
    });

    var people = new People([{first: "j", last: "m"}]);
    QUnit.deepEqual(people.serialize(), [{first: "j", last: "m"}]);

});
Пример #11
0
QUnit.test("added and removed are called after items are added/removed (#14)", function() {

	var Person = DefineMap.extend({
		id: "number",
		name: "string"
	});

	var addedFuncCalled, removedFuncCalled, theList;

	var People = DefineList.extend({
		"#": {
			added: function(items, index){
				addedFuncCalled = true;
				ok(items, "items added got passed to added");
				ok(typeof index === 'number', "index of items was passed to added and is a number");
				ok(items[0].name === 'John', "Name was correct");
				theList = this;
			},
			removed: function(items, index){
				removedFuncCalled = true;
				ok(items, "items added got passed to removed");
				ok(typeof index === 'number', "index of items was passed to removed and is a number");
				theList = this;
			},
			Type: Person
		},
		outsideProp: {
			type: "boolean",
			value: true
		}
	});

	var people = new People([]);
	var me = new Person();
	me.name = "John";
	me.id = "1234";

	ok(!addedFuncCalled, "added function has not been called yet");
	people.push(me);
	ok(addedFuncCalled, "added function was called");
	ok(theList.outsideProp === true && theList instanceof People,
		"the list was passed correctly as this to added");
	theList = null;
	ok(!removedFuncCalled, "removed function has not been called yet");
	people.splice(people.indexOf(me), 1);
	ok(removedFuncCalled, "removed function was called");
	ok(theList.outsideProp === true && theList instanceof People,
		"the list was passed correctly as this to removed");
});
Пример #12
0
QUnit.test("setting expandos on a DefineList", function(){
    var DL = DefineList.extend({
        count: "number"
    });

    var dl = new DL();
    dl.set({count: 5, skip: 2});

    QUnit.equal( dl.get("count"), 5, "read with .get defined"); //-> 5
    QUnit.equal( dl.count, 5, "read with . defined");

    QUnit.equal( dl.get("skip"), 2, "read with .get expando");
    QUnit.equal( dl.skip, 2, "read with . expando");

    QUnit.equal( dl.get("limit"), undefined, "read with .get undefined");
});
Пример #13
0
QUnit.test("default 'observable' type prevents Type from working (#29)", function(){
    var M = DefineMap.extend("M",{
        id: "number"
    });
    var L = DefineList.extend("L",{
        "*": M
    });

    var MyMap = DefineMap.extend({
        l: L
    });

    var m = new MyMap({
        l: [{id: 5}]
    });

    QUnit.ok( m.l[0] instanceof M, "is instance" );
    QUnit.ok(m.l[0].id, 5, "correct props");
});
Пример #14
0
QUnit.test("* vs # (#78)", function(){

    var MyList = DefineList.extend({
        "*": "number",
        "#": {
            added: function(){
                ok(true, "called on init");
            },
            removed: function(){},
            type: "string"
        }
    });

    var list = new MyList([1,2,3]);

    QUnit.ok(list[0] === "1", "converted to string");
    list.set("prop", "4");
    QUnit.ok(list.prop === 4, "type converted");

});
Пример #15
0
QUnit.test("'*' inheritance works (#61)", function(){
    var Account = DefineMap.extend({
        name: "string",
        amount: "number",
      	slug: {
      		serialize: true,
      		get: function() {
      			return this.name.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '');
      		}
      	}
    });

    var BaseList = DefineList.extend({
        "*": Account
    });

    var ExtendedList = BaseList.extend({});

    var xl = new ExtendedList([{}]);

    QUnit.ok(xl[0] instanceof Account);

});
Пример #16
0
QUnit.test("extending DefineList constructor functions more than once (#61)", function(){
    var AList = DefineList.extend("AList", { aProp: {}, aMethod: function(){} });

    var BList = AList.extend("BList", { bProp: {}, bMethod: function(){} });

    var CList = AList.extend("CList", { cProp: {}, cMethod: function(){} });

    var list1 = new BList([{},{}]);
    var list2 = new CList([{},{},{}]);

    list1.on("aProp", function(ev, newVal, oldVal){
        QUnit.equal(newVal, "PROP", "aProp newVal on list1");
        QUnit.equal(oldVal, undefined);
    });
    list1.on("bProp", function(ev, newVal, oldVal){
        QUnit.equal(newVal, "FOO", "bProp newVal on list1");
        QUnit.equal(oldVal, undefined);
    });

    list2.on("aProp", function(ev, newVal, oldVal){
        QUnit.equal(newVal, "PROP", "aProp newVal on list2");
        QUnit.equal(oldVal, undefined);
    });
    list2.on("cProp", function(ev, newVal, oldVal){
        QUnit.equal(newVal, "BAR", "cProp newVal on list2");
        QUnit.equal(oldVal, undefined);
    });

    list1.aProp = "PROP";
    list1.bProp = 'FOO';
    list2.aProp = "PROP";
    list2.cProp = 'BAR';
    QUnit.ok(list1.aMethod, "list1 aMethod");
    QUnit.ok(list1.bMethod);
    QUnit.ok(list2.aMethod);
    QUnit.ok(list2.cMethod, "list2 cMethod");
});
Пример #17
0
module.exports = function(){
	var todoAlgebra = new set.Algebra(
	  set.props.boolean("complete"),
	  set.props.id("id"),
	  set.props.sort("sort")
	);


	var Todo = DefineMap.extend({
	  id: "string",
	  name: "string",
	  complete: {type: "boolean", value: false}
	});

	Todo.List = DefineList.extend({
	  "#": Todo,
	  get active(){
	    return this.filter({complete: false});
	  },
	  get complete(){
	    return this.filter({complete: true});
	  },
	  get allComplete(){
	    return this.length === this.complete.length;
	  },
	  get saving(){
	    return this.filter(function(todo){
	      return todo.isSaving();
	    });
	  },
	  updateCompleteTo: function(value){
	    this.forEach(function(todo){
	      todo.complete = value;
	      todo.save();
	    });
	  },
	  destroyComplete: function(){
	    this.complete.forEach(function(todo){
	      todo.destroy();
	    });
	  }
	});

	superMap({
	  url: "/api/todos",
	  Map: Todo,
	  List: Todo.List,
	  name: "todo",
	  algebra: todoAlgebra
	});

	var TodoCreateVM = DefineMap.extend({
	  todo: {Default: Todo},
	  createTodo: function(){
	    this.todo.save().then(function(){
	      this.todo = new Todo();
	    }.bind(this));
	  }
	});

	var todoCreateTemplate = stache(document.getElementById("todo-create-template").innerHTML);

	Component.extend({
	  tag: "todo-create",
	  view: todoCreateTemplate,
	  ViewModel: TodoCreateVM
	});

	var TodoListVM = DefineMap.extend({
	  todos: Todo.List,
	  editing: Todo,
	  backupName: "string",
	  isEditing: function(todo){
	    return todo === this.editing;
	  },
	  edit: function(todo){
	    this.backupName = todo.name;
	    this.editing = todo;
	  },
	  cancelEdit: function(){
	    if(this.editing) {
	      this.editing.name = this.backupName;
	    }
	    this.editing = null;
	  },
	  updateName: function() {
	    this.editing.save();
	    this.editing = null;
	  }
	});

	var todoListTemplate = stache(document.getElementById("todo-list-template").innerHTML);

	Component.extend({
	  tag: "todo-list",
	  view: todoListTemplate,
	  ViewModel: TodoListVM
	});

	var resolveDone;
	var done = new Promise(function(r){
		resolveDone = r;
	});

	var todosPromise = Promise.resolve(new Todo.List(todosRaw));

	var AppVM = DefineMap.extend({
	  filter: "string",
	  get todosPromise(){
	    if(!this.filter) {
	      return todosPromise;
	    } else {

	    }
	  },
	  todosList: {
	    get: function(lastSetValue, resolve){
	      this.todosPromise.then(function(data){
			  resolve(data);
			  setTimeout(function(){
				 resolveDone();
			  },1)
		  });
	    }
	  },
	  get allChecked(){
	    return this.todosList && this.todosList.allComplete;
	  },
	  set allChecked(newVal){
	    this.todosList && this.todosList.updateCompleteTo(newVal);
	  }
	});

	var appVM = new AppVM();

	var template = stache(document.getElementById("todomvc-template").innerHTML);

	var frag = template(appVM);
	document.body.appendChild(frag);

	return done;
};
Пример #18
0
		}
	,	total$:
		{
			value:	0
		,	type:	Number
		,	get: function()
			{
				return this.total.toFixed(2);	
			}
		}
	}
);

Ventas.List = List.extend(
	{
		'#': Ventas
	}
);

Ventas.algebra = new set.Algebra(
	set.comparators.id('_id')
);

Ventas.connection = connect(
	[
		feathersServiceBehavior
	,	dataParse
	,	construct
	,	constructStore
	,	constructOnce
	,	canMap
Пример #19
0
			}
		}
	,	visible:
		{
			value: true
		,	serialize: function()
			{
				return undefined;
			}
		}
	}
);

Articulos.List = List.extend(
	{
		'#': Articulos
	}
);

Articulos.algebra = new set.Algebra(
	set.comparators.id('_id')
);

Articulos.connection = connect(
	[
		feathersServiceBehavior
	,	dataParse
	,	construct
	,	constructStore
	,	constructOnce
	,	canMap
Пример #20
0
	 *
	 * An email address for the user.
	 */
	get email() {
		return this.profile && this.profile.emails && this.profile.emails[0] && this.profile.emails[0].value;
	},
	/**
	 * @property {String} name
	 *
	 * The user's name -- appropriate for display.
	 */
	get name() {
		return this.profile && this.profile.displayName;
	}
});

User.List = DefineList.extend("UserList", {
	"#": User
});

User.connection = superModel({
	Map: User,
	List: User.List,
	feathersService: feathersClient.service("/api/users"),
	name: "users",
    queryLogic: new QueryLogic(User, feathersQuery)
});


export default User;
Пример #21
0
import canRef from 'can-connect/can/ref/';
import dataCallbacks from 'can-connect/data/callbacks/';

// Use feathersClient.service(url) to create a service
const cuentasService = feathers.service('/api/cuentas');

export const Cuentas = Map.extend(
	{
		seal: false
	}
,	{}
);

Cuentas.List = List.extend(
	{
		'#': Cuentas
	}
);

Cuentas.algebra = new set.Algebra(
	set.comparators.id('_id')
);

Cuentas.connection = connect(
	[
		feathersServiceBehavior
	,	dataParse
	,	construct
	,	constructStore
	,	constructOnce
	,	canMap
Пример #22
0
test('list.sort a list of DefineMaps', function(){
	var Account = DefineMap.extend({
		name: "string",
		amount: "number",
		slug: {
			serialize: true,
			get: function(){
				return this.name.toLowerCase().replace(/ /g,'-').replace(/[^\w-]+/g,'');
			}
		}
	});
	Account.List = DefineList.extend({
	  "*": Account,
	  limit: "number",
	  skip: "number",
	  total: "number"
	});

	var accounts = new Account.List([
		{
			name: "Savings",
			amount: 20.00
		},
		{
			name: "Checking",
			amount: 103.24
		},
		{
			name: "Kids Savings",
			amount: 48155.13
		}
	]);
	accounts.limit = 3;

	var template = stache('{{#each accounts}}{{name}},{{/each}}')({accounts: accounts});
	equal(template.textContent, "Savings,Checking,Kids Savings,", "template rendered properly.");

	accounts.sort(function(a, b){
		if (a.name < b.name) {
			return -1;
		} else if (a.name > b.name){
			return 1;
		} else {
			return 0;
		}
	});
	equal(accounts.length, 3);
	equal(template.textContent, "Checking,Kids Savings,Savings,", "template updated properly.");

	// Try sorting in reverse on the dynamic `slug` property
	accounts.sort(function(a, b){
		if (a.slug < b.slug) {
			return 1;
		} else if (a.slug > b.slug){
			return -1;
		} else {
			return 0;
		}
	});

	equal(accounts.length, 3);
	equal(accounts.limit, 3, "expandos still present after sorting/replacing.");
	equal(template.textContent, "Savings,Kids Savings,Checking,", "template updated properly.");
});
Пример #23
0
const staticProps = {
    seal: true,
};
const prototype = {
	target_temp_s: {
		get() {
			return this.target_temp;
		},
		set(value) {
			if (value == '') {
				value = null;
			}

			this.target_temp = value;
		}
	}
};
assign(prototype, meta.d);

const Profile = DefineMap.extend('Profile', staticProps, prototype);
Profile.List = DefineList.extend('ProfileList', {'#': Profile});

Profile.connect = tastypieRestModel({
    Map: Profile,
    List: Profile.List,
    url: meta.e,
});

export {Profile, Profile as default};
Пример #24
0
'use strict';
import meta from './g/Control';
import DefineMap from 'can-define/map/map';
import DefineList from 'can-define/list/list';
import assign from 'can-assign';
import {tastypieRestModel} from '../tastypie';

const staticProps = {
    seal: true,
};
const prototype = {
};
assign(prototype, meta.d);

const Control = DefineMap.extend('Control', staticProps, prototype);
Control.List = DefineList.extend('ControlList', {'#': Control});

Control.connect = tastypieRestModel({
    Map: Control,
    List: Control.List,
    url: meta.e,
});

export {Control, Control as default};
Пример #25
0
export const NavPage = DefineMap.extend('NavPage', {
    href: 'string',
    active: 'boolean',
    label: 'string'
});

export const ViewModel = DefineMap.extend('NavList', {
    init () {
        this.pages.forEach((item) => {
            if (item.active) {
                this.activate(item);
            }
        });
    },
    pages: DefineList.extend('NavItemList', {
        Map: NavPage
    }),
    type: {
        type: 'string',
        set (type) {
            return TYPES.indexOf(type) > 0 ? type : TYPES[0];
        },
        value: TYPES[0]
    },
    active: DefineMap,
    activate (item) {
        if (item === this.active) {
            return;
        }
        this.active = item;
    }
Пример #26
0
            }
            return [
                this.baseUrl,
                separator,
                'REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=40&LAYER=',
                this.id
            ].join('');
        }
    },
    toggleCollapsed: function (sub) {
        sub.collapsed = !sub.collapsed;
    }
});

export const SubLayerList = DefineList.extend({
    '#': SubLayerMap
});

const ViewModel = baseViewModel.extend({
    collapsed: {
        type: 'boolean',
        value: true
    },
    defaultSublayerVisible: {
        type: 'boolean',
        value: true
    },
    sublayers: {
        Value: SubLayerList,
        Type: SubLayerList
    },
Пример #27
0
 * @group toast-container.ViewModel.props Properties
 *
 * @description A `<toast-container />` component's ViewModel
 */
export default DefineMap.extend('ToastContainer', {
    /**
   * @prototype
   */
    /**
     * An array of alert toasts
     * @property {Array<toast-item.ViewModel>} toast-container.ViewModel.props.toasts toasts
     * @parent toast-container.ViewModel.props
     */
    toasts: {
        Value: DefineList.extend('ToastList', {
            '#': Toast
        })
    },
    /**
   * adds a new toast
   * @function addToast
   * @signature `addToast(properties)`
   * @param {toast-item.ViewModel} toast the toast options or toast object to add
   */
    addToast (toast) {
        if (!(toast instanceof Toast)) {
            toast = new Toast(toast);
        }
        this.toasts.push(toast);
    },
    /**
Пример #28
0
'use strict';
import meta from './g/SensorResync';
import DefineMap from 'can-define/map/map';
import DefineList from 'can-define/list/list';
import assign from 'can-assign';
import {tastypieRestModel} from '../tastypie';

const staticProps = {
    seal: true,
};
const prototype = {
};
assign(prototype, meta.d);

const SensorResync = DefineMap.extend('SensorResync', staticProps, prototype);
SensorResync.List = DefineList.extend('SensorResyncList', {'#': SensorResync});

SensorResync.connect = tastypieRestModel({
    Map: SensorResync,
    List: SensorResync.List,
    url: meta.e,
});

export {SensorResync, SensorResync as default};
Пример #29
0
export default connect.behavior('FlaskRestlessData', function (base) {
    return {
        init () {

            this.metadata = new MetaMap();

            this.algebra = algebra;

            this.ajax = this.ajax || $.ajax;
            $.ajaxSetup({
                dataType: 'json',
                headers: {
                    'Accept': 'application/vnd.api+json',
                    'Content-Type': 'application/vnd.api+json'
                }
            });
            //a new list which should hold the objects
            if (!base.List) {
                this.List = DefineList.extend('FlaskRestlessList', {
                    '#': base.Map
                });
            }
            base.init.apply(this, arguments);

        },
        getListData (params) {

            return new Promise((resolve, reject) => {

                // convert parameters to flask-restless params
                params = new ParameterMap(params).serialize();

                const promise = this.ajax({
                    url: this.url,
                    method: 'GET',
                    data: params
                });
                promise.then((props) => {

                    // update the metadata
                    this.metadata.assign(props.meta);

                    resolve(props);
                }, reject);
            });
        },
        getData (params) {
            return new Promise((resolve, reject) => {
                const promise = this.ajax({
                    url: `${this.url}/${params[this.idProp]}`,
                    method: 'GET'
                });
                promise.then(resolve, reject);
            });
        },
        createData (attrs) {
            return new Promise((resolve, reject) => {
                const data = {};

                //exclude relationship properties
                for (var a in attrs) {
                    if (attrs.hasOwnProperty(a) && !this.metadata.relationships[a]) {
                        data[a] = attrs[a];
                    }
                }

                //post attributes to the create url
                const promise = this.ajax({
                    url: this.url,
                    dataType: 'json',
                    headers: {
                        'Accept': 'application/vnd.api+json',
                        'Content-Type': 'application/vnd.api+json'
                    },
                    data: JSON.stringify({
                        data: {
                            attributes: data,
                            type: this.name
                        }
                    }),
                    method: 'POST'
                });

                promise.then(resolve, reject);
            });
        },
        updateData (attrs) {
            return new Promise((resolve, reject) => {
                const data = {};

                //exclude relationship properties
                for (var a in attrs) {
                    if (attrs.hasOwnProperty(a) && !this.metadata.relationships[a] && a !== this.idProp) {
                        data[a] = attrs[a];
                    }
                }
                const promise = this.ajax({
                    url: `${this.url}/${attrs[this.idProp]}`,
                    dataType: 'json',
                    headers: {
                        'Accept': 'application/vnd.api+json',
                        'Content-Type': 'application/vnd.api+json'
                    },
                    data: JSON.stringify({
                        data: {
                            attributes: data,
                            type: this.name,
                            id: attrs[this.idProp]
                        }
                    }),
                    method: 'PATCH'
                });
                promise.then(resolve, reject);
            });
        },
        destroyData (attrs) {
            return new Promise((resolve, reject) => {
                $.ajax({
                    url: `${this.url}/${attrs[this.idProp]}`,
                    dataType: 'json',
                    method: 'DELETE',
                    headers: {
                        'Accept': 'application/vnd.api+json',
                        'Content-Type': 'application/vnd.api+json'
                    }
                }).then(resolve, reject);
            });
        }
    };
});
Пример #30
0
            if (val && this.operator) {
                const op = FilterSerializers[this.operator];
                if (op && op.serialize) {
                    return op.serialize(val);
                }
            }
            return val;
        }
    }
});

/*
 * A list of filters
 */
export const FilterList = DefineList.extend('FilterList', {
    '#': FilterMap
});

/**
 * @module {can.Map} can-admin/behaviors/flask-restless/lib/CanRestless.SortMap SortMap
 * @parent can-admin/behaviors/flask-restless
 * @group props Properties
 * @description
 * A sorting helper class
 */
export const SortMap = DefineMap.extend('Sort', {
    /**
     * The name of the field to sort on
     * @property {String} SortMap.props.field
     * @parent SortMap.props
     */