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

Commit

Permalink
CB-10636 Add JSHint for plugins
Browse files Browse the repository at this point in the history
Fixed contacts.spec.5
  • Loading branch information
daserge committed Feb 26, 2016
1 parent df9f936 commit ca62fa7
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -12,7 +12,7 @@ Thumbs.db
*.swp
*.user


node_modules



Expand Down
24 changes: 24 additions & 0 deletions .jshintrc
@@ -0,0 +1,24 @@
{
"browser": true
, "devel": true
, "bitwise": true
, "undef": true
, "trailing": true
, "quotmark": false
, "indent": 4
, "unused": "vars"
, "latedef": "nofunc"
, "globals": {
"module": false,
"exports": false,
"require": false,
"cordova": true,
"ContactFindOptions": true,
"ContactError": true,
"Contact": true,
"ContactName": true,
"ContactField": true,
"ContactAddress": true,
"ContactOrganization": true
}
}
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: node_js
sudo: false
node_js:
- "4.2"
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -17,6 +17,8 @@
# under the License.
-->

[![Build Status](https://travis-ci.org/apache/cordova-plugin-contacts.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-contacts)

# cordova-plugin-contacts

This plugin defines a global `navigator.contacts` object, which provides access to the device contacts database.
Expand Down
9 changes: 8 additions & 1 deletion package.json
Expand Up @@ -35,6 +35,13 @@
"cordova-windows8",
"cordova-windows"
],
"scripts": {
"test": "npm run jshint",
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
},
"author": "Apache Software Foundation",
"license": "Apache-2.0"
"license": "Apache-2.0",
"devDependencies": {
"jshint": "^2.6.0"
}
}
4 changes: 3 additions & 1 deletion src/blackberry10/contactUtils.js
Expand Up @@ -18,7 +18,9 @@
* under the License.
*
*/


/* global ContactPickerOptions */

var self,
ContactFindOptions = require("./ContactFindOptions"),
ContactError = require("./ContactError"),
Expand Down
47 changes: 15 additions & 32 deletions src/blackberry10/index.js
Expand Up @@ -13,27 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* global PluginResult, JNEXT, escape */

var pimContacts,
contactUtils = require("./contactUtils"),
contactConsts = require("./contactConsts"),
ContactError = require("./ContactError"),
ContactName = require("./ContactName"),
ContactFindOptions = require("./ContactFindOptions"),
noop = function () {};

function getAccountFilters(options) {
if (options.includeAccounts) {
options.includeAccounts = options.includeAccounts.map(function (acct) {
return acct.id.toString();
});
}

if (options.excludeAccounts) {
options.excludeAccounts = options.excludeAccounts.map(function (acct) {
return acct.id.toString();
});
}
}
ContactFindOptions = require("./ContactFindOptions");

function populateSearchFields(fields) {
var i,
Expand All @@ -58,21 +44,21 @@ function populateSearchFields(fields) {
searchFieldsObject[ContactFindOptions.SEARCH_FIELD_PHONE] = true;
} else if (fields[i] === "emails") {
searchFieldsObject[ContactFindOptions.SEARCH_FIELD_EMAIL] = true;
} else if (field === "addresses") {
} else if (fields[i] === "addresses") {
// not supported by Cascades
} else if (field === "ims") {
} else if (fields[i] === "ims") {
// not supported by Cascades
} else if (field === "organizations") {
} else if (fields[i] === "organizations") {
searchFieldsObject[ContactFindOptions.SEARCH_FIELD_ORGANIZATION_NAME] = true;
} else if (field === "birthday") {
} else if (fields[i] === "birthday") {
// not supported by Cascades
} else if (field === "note") {
} else if (fields[i] === "note") {
// not supported by Cascades
} else if (field === "photos") {
} else if (fields[i] === "photos") {
// not supported by Cascades
} else if (field === "categories") {
} else if (fields[i] === "categories") {
// not supported by Cascades
} else if (field === "urls") {
} else if (fields[i] === "urls") {
// not supported by Cascades
}
}
Expand All @@ -98,8 +84,7 @@ function convertBirthday(birthday) {
}

function processJnextSaveData(result, JnextData) {
var data = JnextData,
birthdayInfo;
var data = JnextData;

if (data._success === true) {
data.birthday = convertBirthday(data.birthday);
Expand All @@ -124,8 +109,7 @@ function processJnextFindData(eventId, eventHandler, JnextData) {
i,
l,
more = false,
resultsObject = {},
birthdayInfo;
resultsObject = {};

if (data.contacts) {
for (i = 0, l = data.contacts.length; i < l; i++) {
Expand Down Expand Up @@ -192,7 +176,6 @@ module.exports = {
save: function (successCb, failCb, args, env) {
var attributes = {},
result = new PluginResult(args, env),
key,
nativeEmails = [];

attributes = JSON.parse(decodeURIComponent(args[0]));
Expand Down Expand Up @@ -286,7 +269,7 @@ JNEXT.PimContacts = function ()
}

JNEXT.invoke(self.m_id, "find " + JSON.stringify(jnextArgs));
}
};

self.getContact = function (args) {
return JSON.parse(JNEXT.invoke(self.m_id, "getContact " + JSON.stringify(args)));
Expand Down
69 changes: 36 additions & 33 deletions src/firefoxos/ContactsProxy.js
Expand Up @@ -19,6 +19,8 @@
*
*/

/* global mozContact */

// Cordova contact definition:
// http://cordova.apache.org/docs/en/2.5.0/cordova_contacts_contacts.md.html#Contact
// FxOS contact definition:
Expand All @@ -27,7 +29,6 @@

var Contact = require('./Contact');
var ContactField = require('./ContactField');
var ContactAddress = require('./ContactAddress');
var ContactName = require('./ContactName');

// XXX: a hack to check if id is "empty". Cordova inserts a
Expand All @@ -46,13 +47,13 @@ function updateFromCordova(contact, fromContact) {
function exportContactFieldArray(contactFieldArray, key) {
if (!key) {
key = 'value';
}
}
var arr = [];
for (var i=0; i < contactFieldArray.length; i++) {
arr.push(contactFieldArray[i][key]);
};
}
return arr;
}
}

function exportAddress(addresses) {
// TODO: check moz address format
Expand All @@ -66,15 +67,15 @@ function updateFromCordova(contact, fromContact) {
} else if (key == 'type') {
addr[key] = [addresses[i][key]];
} else if (key == 'country') {
addr['countryName'] = addresses[i][key];
addr.countryName = addresses[i][key];
} else {
addr[key] = addresses[i][key];
addr[key] = addresses[i][key];
}
}
}
arr.push(addr);
}
}
return arr;
}
}

function exportContactField(data) {
var contactFields = [];
Expand All @@ -99,17 +100,17 @@ function updateFromCordova(contact, fromContact) {
['middleName', 'additionalName']];
var baseArrayFields = [['displayName', 'name'], ['nickname']];
var baseStringFields = [];
var j = 0; while(field = nameFields[j++]) {
var j = 0, field; while(field = nameFields[j++]) { // jshint ignore:line
if (fromContact.name[field[0]]) {
contact[field[1] || field[0]] = fromContact.name[field[0]].split(' ');
}
}
j = 0; while(field = baseArrayFields[j++]) {
j = 0; while(field = baseArrayFields[j++]) { // jshint ignore:line
if (fromContact[field[0]]) {
contact[field[1] || field[0]] = fromContact[field[0]].split(' ');
}
}
j = 0; while(field = baseStringFields[j++]) {
j = 0; while(field = baseStringFields[j++]) { // jshint ignore:line
if (fromContact[field[0]]) {
contact[field[1] || field[0]] = fromContact[field[0]];
}
Expand All @@ -118,7 +119,7 @@ function updateFromCordova(contact, fromContact) {
contact.bday = new Date(fromContact.birthday);
}
if (fromContact.emails) {
var emails = exportContactField(fromContact.emails)
var emails = exportContactField(fromContact.emails);
contact.email = emails;
}
if (fromContact.categories) {
Expand Down Expand Up @@ -172,17 +173,17 @@ Contact.prototype.updateFromMozilla = function(moz) {
var addr = {};
for (var key in addresses[i]) {
if (key == 'countryName') {
addr['country'] = addresses[i][key];
addr.country = addresses[i][key];
} else if (key == 'type') {
addr[key] = addresses[i][key].join(' ');
} else {
addr[key] = addresses[i][key];
addr[key] = addresses[i][key];
}
}
}
arr.push(addr);
}
return arr;
}
}

function createOrganizations(orgs, jobs) {
orgs = (orgs) ? orgs : [];
Expand Down Expand Up @@ -221,18 +222,18 @@ Contact.prototype.updateFromMozilla = function(moz) {
var baseArrayFields = [['name', 'displayName'], 'nickname', ['note']];
var baseStringFields = [];
var name = new ContactName();
var j = 0; while(field = nameFields[j++]) {
var j = 0, field; while(field = nameFields[j++]) { // jshint ignore:line
if (moz[field[0]]) {
name[field[1] || field[0]] = moz[field[0]].join(' ');
}
}
this.name = name;
j = 0; while(field = baseArrayFields[j++]) {
j = 0; while(field = baseArrayFields[j++]) { // jshint ignore:line
if (moz[field[0]]) {
this[field[1] || field[0]] = moz[field[0]].join(' ');
}
}
j = 0; while(field = baseStringFields[j++]) {
j = 0; while(field = baseStringFields[j++]) { // jshint ignore:line
if (moz[field[0]]) {
this[field[1] || field[0]] = moz[field[0]];
}
Expand Down Expand Up @@ -276,7 +277,7 @@ Contact.prototype.updateFromMozilla = function(moz) {
// genderIdentity
// key
*/
}
};


function createMozillaFromCordova(successCB, errorCB, contact) {
Expand Down Expand Up @@ -323,26 +324,28 @@ function saveContacts(successCB, errorCB, contacts) {
var contact = createCordovaFromMozilla(moz);
// call callback
successCB(contact);
}
};
}
var i=0;
var contact;
while(contact = contacts[i++]){
var moz = createMozillaFromCordova(function(moz) {
var request = navigator.mozContacts.save(moz);
// success and/or fail will be called every time a contact is saved
request.onsuccess = makeSaveSuccessCB(moz);
request.onerror = errorCB;
/*jshint -W083 */
while(contact = contacts[i++]) { // jshint ignore:line
createMozillaFromCordova(function(moz) {
var request = navigator.mozContacts.save(moz);
// success and/or fail will be called every time a contact is saved
request.onsuccess = makeSaveSuccessCB(moz);
request.onerror = errorCB;
}, function() {}, contact);
}
}
/*jshint +W083 */
}


// API provides a list of ids to be removed
function remove(successCB, errorCB, ids) {
var i=0;
var id;
for (var i=0; i < ids.length; i++){
var i;
/*jshint -W083 */
for (i = 0; i < ids.length; i++){
// throw an error if no id provided
if (!_hasId(ids[i])) {
console.error('FFOS: Attempt to remove unsaved contact');
Expand All @@ -365,6 +368,7 @@ function remove(successCB, errorCB, ids) {
};
search.onerror = errorCB;
}
/*jshint +W083 */
}


Expand Down Expand Up @@ -445,7 +449,6 @@ function search(successCB, errorCB, params) {
request.onsuccess = function() {
var contacts = [];
var mozContacts = request.result;
var moz = mozContacts[0];
for (var i=0; i < mozContacts.length; i++) {
contacts.push(createCordovaFromMozilla(mozContacts[i]));
}
Expand Down

0 comments on commit ca62fa7

Please sign in to comment.