Skip to content
This repository has been archived by the owner on Jan 16, 2018. It is now read-only.

Commit

Permalink
[feature] migrate Contacts.fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Noëlie Andrieu committed Jan 19, 2017
1 parent 690f58b commit 3c11689
Show file tree
Hide file tree
Showing 5 changed files with 2,354 additions and 7 deletions.
17 changes: 11 additions & 6 deletions app/application.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ class Application extends Mn.Application

@contacts = new ContactsCollection()
@filtered = new FilteredCollection()
@tags = new TagsCollection(@contacts)

# As long as Tags require Contacts to be loaded (see Tags.refs), we
# trigger all TagsCollection fetch after syncing ContactsCollection.
@listenToOnce @contacts, 'sync': -> @tags.underlying.fetch reset: true
@tags = new TagsCollection @contacts

@layout = new AppLayout model: @model
@router = new Router()
Expand All @@ -49,10 +45,19 @@ class Application extends Mn.Application

Object.freeze @ if typeof Object.freeze is 'function'


# render components when app starts
onStart: ->
@layout.render()
@contacts.fetch reset: true

callback = () =>
console.log 'SUCCESS', arguments

# As long as Tags require Contacts to be loaded (see Tags.refs), we
# trigger all TagsCollection fetch after syncing ContactsCollection.
# @tags.underlying.fetch {reset: true}

@contacts.fetch {reset: true}, callback

# prohibit pushState because URIs mapped from cozy-home rely on
# fragment
Expand Down
35 changes: 34 additions & 1 deletion app/collections/contacts.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Contact = require 'models/contact'
module.exports = class Contacts extends Backbone.Collection

model: Contact
url: 'contacts'

sortDisabled: false

Expand All @@ -20,6 +19,40 @@ module.exports = class Contacts extends Backbone.Collection
@listenToOnce @, 'sync', -> @contactListener.watch @


fetch: (options={}, callback = -> ) ->
@reset() if options.reset


# TODO : return fake contacts
# {
# title: '',
# department: '',
# bday: '',
# nickname: '',
# url: '',
# revision: new Date(),
# datapoints: [],
# note: "",
# tags: [],
# _attachments: null,
# accounts: []
# }

# @add contacts

# cozy.init { isV2: true }
# cozy.defineIndex 'io.cozy.contacts', ['id']
# .then (index) =>
# cozy.query index, { selector: id: {"$gte": " "} }
# .then (result=[]) =>
# @add result if result?.length
#
# callback result
# , (err) =>
# callback null, err



# Turns a vcard text into a list of contacts. Then it saves every contacts
# in the data system. Finally it reloads the contact list.
importFromVCF: (vcard) ->
Expand Down
1 change: 1 addition & 0 deletions app/views/models/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = class AppViewModel extends Backbone.ViewModel
app = require 'application'

@set 'selected', []

@listenTo @, 'change:filter', (nil, value) ->
@unselectAll()
@set 'scored', CONFIG.search.pattern('text').test value
Expand Down
1 change: 1 addition & 0 deletions config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports.config =
'vendor/marionette/backbone.radio.js'
'vendor/marionette/backbone.marionette.js'
'vendor/marionette/radio.shim.js'
'vendor/cozy-client-0.0.1.js'
]

stylesheets:
Expand Down
Loading

0 comments on commit 3c11689

Please sign in to comment.