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

Commit

Permalink
[fix] contact.save (but cant works)
Browse files Browse the repository at this point in the history
  • Loading branch information
Noëlie Andrieu committed Jan 19, 2017
1 parent 008f2b8 commit d1228c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
24 changes: 9 additions & 15 deletions app/collections/contacts.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@ module.exports = class Contacts extends Backbone.Collection

@reset() if options.reset

# FIXME: remove this line when
# cozy.query will works
@add []

success @models, @

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



Expand Down
23 changes: 17 additions & 6 deletions app/models/contact.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ module.exports = class Contact extends Backbone.Model


validate: (attrs, options) ->
console.log "PLOP", attrs, options
Handle specific attributes.
# Handle specific attributes.
attrs.fn = VCardParser.nToFN attrs.n.split ';'

datapoints = (attrs.datapoints?.toJSON() or [])
Expand All @@ -111,15 +110,27 @@ module.exports = class Contact extends Backbone.Model
# The changes are:
# name: 'share' -> name: 'url' + mediatype: 'cloud:cozy'
clouds = _.where attrs.datapoints, {name: 'share'}
if not _.isEmpty(clouds)
for cloud in clouds
cloud.name = 'url'
cloud.mediatype = 'cloud:cozy'
for cloud in clouds
cloud.name = 'url'
cloud.mediatype = 'cloud:cozy'

options.attrs = attrs
false


# FIXME: isnt saved by ther server
# because it is handled threow websocket
# thats can't works without server
# waits for cozy-client-js can handle this case
save: (options={}) ->
cozy.init { isV2: true }
cozy.create 'io.cozy.contacts', @attributes
.then (resp) =>
@attributes = resp
, () =>
console.log 'ERROR', arguments


_buildSortedName: (n) ->
n ?= @get 'n'

Expand Down
8 changes: 4 additions & 4 deletions app/views/models/contact.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ module.exports = class ContactViewModel extends Backbone.ViewModel


events:
'before:save': 'syncDatapoints'
save: 'onSave'
reset: 'onReset'
'before:save': 'syncDatapoints'
'save': 'onSave'
'reset': 'onReset'


viewEvents:
Expand Down Expand Up @@ -148,7 +148,7 @@ module.exports = class ContactViewModel extends Backbone.ViewModel
models = models.concat CH.getNonEmptyDatapoints collection

# Load new datapoints in the data model.
datapoints.reset models
datapoints?.reset models


# Save directly new tags to the server if the model is already created.
Expand Down

0 comments on commit d1228c0

Please sign in to comment.