contactsPane.js
function (book, name, selectedGroups, callbackFunction) {
        book = findBookFromGroups(book)
        var nameEmailIndex = kb.any(book, ns.vcard('nameEmailIndex'))

        var uuid = UI.utils.genUuid()
        var person = kb.sym(book.dir().uri + 'Person/' + uuid + '/index.ttl#this')
        var doc = person.doc()

        // Sets of statements to different files
        var agenda = [ // Patch the main index to add the person
          [ $rdf.st(person, ns.vcard('inAddressBook'), book, nameEmailIndex), // The people index
            $rdf.st(person, ns.vcard('fn'), name, nameEmailIndex) ]
        ]

        // @@ May be missing email - sync that differently

        // sts.push(new $rdf.Statement(person, DCT('created'), new Date(), doc));  ??? include this?
        for (var gu in selectedGroups) {
          var g = kb.sym(gu)
          var gd = g.doc()
          agenda.push([ $rdf.st(g, ns.vcard('hasMember'), person, gd),
            $rdf.st(person, ns.vcard('fn'), name, gd)
          ])
        }

        var updateCallback = function (uri, success, body) {
          if (!success) {
            console.log("Error: can't update " + uri + ' for new contact:' + body + '\n')
            callbackFunction(false, "Error: can't update " + uri + ' for new contact:' + body)
          } else {
            if (agenda.length > 0) {
              console.log('Patching ' + agenda[0] + '\n')
              updater.update([], agenda.shift(), updateCallback)
            } else { // done!
              console.log('Done patching. Now reading back in.\n')
              UI.store.fetcher.nowOrWhenFetched(doc, undefined, function (ok, body) {
                if (ok) {
                  console.log('Read back in OK.\n')
                  callbackFunction(true, person)
                } else {
                  console.log('Read back in FAILED: ' + body + '\n')
                  callbackFunction(false, body)
                }
              })
            }
          }
        }

        UI.store.fetcher.nowOrWhenFetched(nameEmailIndex, undefined, function (ok, message) {
          if (ok) {
            console.log(' People index must be loaded\n')
            updater.put(doc, [
              $rdf.st(person, ns.vcard('fn'), name, doc),
              $rdf.st(person, ns.rdf('type'), ns.vcard('Individual'), doc) ],
              'text/turtle', updateCallback)
          } else {
            console.log('Error loading people index!' + nameEmailIndex.uri + ': ' + message)
            callbackFunction(false, 'Error loading people index!' + nameEmailIndex.uri + ': ' + message + '\n')
          }
        })
      }
function (book, name, selectedGroups, callbackFunction) {
        book = findBookFromGroups(book)
        var nameEmailIndex = kb.any(book, ns.vcard('nameEmailIndex'))

        var uuid = UI.utils.genUuid()
        var person = kb.sym(book.dir().uri + 'Person/' + uuid + '/index.ttl#this')
        var doc = person.doc()

        // Sets of statements to different files
        var agenda = [ // Patch the main index to add the person
          [ $rdf.st(person, ns.vcard('inAddressBook'), book, nameEmailIndex), // The people index
            $rdf.st(person, ns.vcard('fn'), name, nameEmailIndex) ]
        ]

        // @@ May be missing email - sync that differently

        // sts.push(new $rdf.Statement(person, DCT('created'), new Date(), doc));  ??? include this?
        for (var gu in selectedGroups) {
          var g = kb.sym(gu)
          var gd = g.doc()
          agenda.push([ $rdf.st(g, ns.vcard('hasMember'), person, gd),
            $rdf.st(person, ns.vcard('fn'), name, gd)
          ])
        }

        var updateCallback = function (uri, success, body) {
          if (!success) {
            console.log("Error: can't update " + uri + ' for new contact:' + body + '\n')
            callbackFunction(false, "Error: can't update " + uri + ' for new contact:' + body)
          } else {
            if (agenda.length > 0) {
              console.log('Patching ' + agenda[0] + '\n')
              updater.update([], agenda.shift(), updateCallback)
            } else { // done!
              console.log('Done patching. Now reading back in.\n')
              UI.store.fetcher.nowOrWhenFetched(doc, undefined, function (ok, body) {
                if (ok) {
                  console.log('Read back in OK.\n')
                  callbackFunction(true, person)
                } else {
                  console.log('Read back in FAILED: ' + body + '\n')
                  callbackFunction(false, body)
                }
              })
            }
          }
        }

        UI.store.fetcher.nowOrWhenFetched(nameEmailIndex, undefined, function (ok, message) {
          if (ok) {
            console.log(' People index must be loaded\n')
            updater.put(doc, [
              $rdf.st(person, ns.vcard('fn'), name, doc),
              $rdf.st(person, ns.rdf('type'), ns.vcard('Individual'), doc) ],
              'text/turtle', updateCallback)
          } else {
            console.log('Error loading people index!' + nameEmailIndex.uri + ': ' + message)
            callbackFunction(false, 'Error loading people index!' + nameEmailIndex.uri + ': ' + message + '\n')
          }
        })
      }
function ( book , name , selectedGroups , callbackFunction ) { book = findBookFromGroups ( book ) var nameEmailIndex = kb . any ( book , ns . vcard ( 'nameEmailIndex' ) ) var uuid = UI . utils . genUuid ( ) var person = kb . sym ( book . dir ( ) . uri + 'Person/' + uuid + '/index.ttl#this' ) var doc = person . doc ( ) // Sets of statements to different files var agenda = [ // Patch the main index to add the person [ $rdf . st ( person , ns . vcard ( 'inAddressBook' ) , book , nameEmailIndex ) , // The people index $rdf . st ( person , ns . vcard ( 'fn' ) , name , nameEmailIndex ) ] ] // @@ May be missing email - sync that differently // sts.push(new $rdf.Statement(person, DCT('created'), new Date(), doc));  ??? include this? for ( var gu in selectedGroups ) { var g = kb . sym ( gu ) var gd = g . doc ( ) agenda . push ( [ $rdf . st ( g , ns . vcard ( 'hasMember' ) , person , gd ) , $rdf . st ( person , ns . vcard ( 'fn' ) , name , gd ) ] ) } var updateCallback = function ( uri , success , body ) { if ( ! success ) { console . log ( "Error: can't update " + uri + ' for new contact:' + body + '\n' ) callbackFunction ( false , "Error: can't update " + uri + ' for new contact:' + body ) } else { if ( agenda . length > 0 ) { console . log ( 'Patching ' + agenda [ 0 ] + '\n' ) updater . update ( [ ] , agenda . shift ( ) , updateCallback ) } else { // done! console . log ( 'Done patching. Now reading back in.\n' ) UI . store . fetcher . nowOrWhenFetched ( doc , undefined , function ( ok , body ) { if ( ok ) { console . log ( 'Read back in OK.\n' ) callbackFunction ( true , person ) } else { console . log ( 'Read back in FAILED: ' + body + '\n' ) callbackFunction ( false , body ) } } ) } } } UI . store . fetcher . nowOrWhenFetched ( nameEmailIndex , undefined , function ( ok , message ) { if ( ok ) { console . log ( ' People index must be loaded\n' ) updater . put ( doc , [ $rdf . st ( person , ns . vcard ( 'fn' ) , name , doc ) , $rdf . st ( person , ns . rdf ( 'type' ) , ns . vcard ( 'Individual' ) , doc ) ] , 'text/turtle' , updateCallback ) } else { console . log ( 'Error loading people index!' + nameEmailIndex . uri + ': ' + message ) callbackFunction ( false , 'Error loading people index!' + nameEmailIndex . uri + ': ' + message + '\n' ) } } ) }
Write a new contact to the web
Write a new contact to the web