~ubuntu-branches/ubuntu/vivid/cordova-ubuntu-tests/vivid

« back to all changes in this revision

Viewing changes to www/contacts/index.html

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2013-09-07 02:04:20 UTC
  • Revision ID: package-import@ubuntu.com-20130907020420-dejay9xcdmmwh0bd
Tags: upstream-2.11+13.10.20130907
ImportĀ upstreamĀ versionĀ 2.11+13.10.20130907

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html>
 
2
<!--
 
3
 
 
4
 Licensed to the Apache Software Foundation (ASF) under one
 
5
 or more contributor license agreements.  See the NOTICE file
 
6
 distributed with this work for additional information
 
7
 regarding copyright ownership.  The ASF licenses this file
 
8
 to you under the Apache License, Version 2.0 (the
 
9
 "License"); you may not use this file except in compliance
 
10
 with the License.  You may obtain a copy of the License at
 
11
 
 
12
   http://www.apache.org/licenses/LICENSE-2.0
 
13
 
 
14
 Unless required by applicable law or agreed to in writing,
 
15
 software distributed under the License is distributed on an
 
16
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
17
 KIND, either express or implied.  See the License for the
 
18
 specific language governing permissions and limitations
 
19
 under the License.
 
20
 
 
21
-->
 
22
 
 
23
 
 
24
<html>
 
25
  <head>
 
26
    <meta name="viewport" content="width=device-width,height=device-height,user-scalable=no,maximum-scale=1.0,initial-scale=1.0" />
 
27
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <!-- ISO-8859-1 -->
 
28
    <title>Cordova Mobile Spec</title>
 
29
    <link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
 
30
    <script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>      
 
31
 
 
32
      
 
33
<script type="text/javascript" charset="utf-8">
 
34
 
 
35
    var deviceReady = false;
 
36
 
 
37
    //-------------------------------------------------------------------------
 
38
    // Contacts
 
39
    //-------------------------------------------------------------------------
 
40
    function getContacts() {
 
41
        obj = new ContactFindOptions();
 
42
        // show all contacts, so don't filter
 
43
        obj.multiple = true;
 
44
        navigator.contacts.find(
 
45
            ["displayName", "name", "phoneNumbers", "emails", "urls", "note"],
 
46
            function(contacts) {
 
47
                var s = "";
 
48
                if (contacts.length == 0) {
 
49
                    s = "No contacts found";
 
50
                }
 
51
                else {
 
52
                    s = "Number of contacts: "+contacts.length+"<br><table width='100%'><tr><th>Name</th><td>Phone</td><td>Email</td></tr>";
 
53
                    for (var i=0; i<contacts.length; i++) {
 
54
                        var contact = contacts[i];
 
55
                        s = s + "<tr><td>" + contact.name.formatted + "</td><td>";
 
56
                        if (contact.phoneNumbers && contact.phoneNumbers.length > 0) {
 
57
                            s = s + contact.phoneNumbers[0].value;
 
58
                        }
 
59
                        s = s + "</td><td>"
 
60
                        if (contact.emails && contact.emails.length > 0) {
 
61
                            s = s + contact.emails[0].value;
 
62
                        }
 
63
                        s = s + "</td></tr>";
 
64
                    }
 
65
                    s = s + "</table>";
 
66
                }
 
67
                document.getElementById('contacts_results').innerHTML = s;
 
68
            },
 
69
            function(e) {
 
70
                document.getElementById('contacts_results').innerHTML = "Error: "+e.code;
 
71
            },
 
72
            obj);
 
73
    };
 
74
 
 
75
    function addContact(){
 
76
        console.log("addContact()");
 
77
        try{
 
78
            var contact = navigator.contacts.create({"displayName": "Dooney Evans"});
 
79
            var contactName = {
 
80
                formatted: "Dooney Evans",
 
81
                familyName: "Evans",
 
82
                givenName: "Dooney",
 
83
                middleName: ""
 
84
            };
 
85
 
 
86
            contact.name = contactName;
 
87
 
 
88
            var phoneNumbers = [1];
 
89
            phoneNumbers[0] = new ContactField('work', '512-555-1234', true);
 
90
            contact.phoneNumbers = phoneNumbers;
 
91
 
 
92
            contact.save(
 
93
                function() { alert("Contact saved.");},
 
94
                function(e) { alert("Contact save failed: " + e.code); }
 
95
            );
 
96
            console.log("you have saved the contact");
 
97
        }
 
98
        catch (e){
 
99
            alert(e);
 
100
        }
 
101
 
 
102
    };
 
103
    
 
104
    /**
 
105
     * Function called when page has finished loading.
 
106
     */
 
107
    function init() {
 
108
        document.addEventListener("deviceready", function() {
 
109
                deviceReady = true;
 
110
                console.log("Device="+device.platform+" "+device.version);
 
111
            }, false);
 
112
        window.setTimeout(function() {
 
113
                if (!deviceReady) {
 
114
                        alert("Error: Apache Cordova did not initialize.  Demo will not run correctly.");
 
115
                }
 
116
        },1000);
 
117
    }
 
118
 
 
119
</script>
 
120
 
 
121
  </head>
 
122
  <body onload="init();" id="stage" class="theme">
 
123
  
 
124
    <h1>Contacts</h1>    
 
125
    <div id="info">
 
126
        <b>Results:</b><br>
 
127
        <span id="contacts_results"> </span>
 
128
    </div>
 
129
    <h2>Action</h2>
 
130
    <div class="btn large" onclick="getContacts();">Get phone's contacts</div>
 
131
    <div class="btn large" onclick="addContact();">Add a new contact 'Dooney Evans'</div>
 
132
    <h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
 
133
  </body>
 
134
</html>