Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support X-PHONETIC-FIRST-NAME and X-PHONETIC-LAST-NAME #595

Merged
merged 3 commits into from Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions js/components/Options/Options_controller.js
@@ -0,0 +1,17 @@
angular.module('contactsApp')
.controller('optionsCtrl', function(SettingsService) {
var ctrl = this;

ctrl.t = {
phoneticText: t('contacts', 'Enable phonetic'),
reverseNameOrderText: t('contacts', 'Reverse name order'),
};

ctrl.phoneticEnable = SettingsService.get('phoneticEnable');
ctrl.reverseNameOrder = SettingsService.get('reverseNameOrder');

ctrl.updateOptions = function() {
SettingsService.set('phoneticEnable', ctrl.phoneticEnable);
SettingsService.set('reverseNameOrder', ctrl.reverseNameOrder);
};
});
11 changes: 11 additions & 0 deletions js/components/Options/Options_directive.js
@@ -0,0 +1,11 @@
angular.module('contactsApp')
.directive('options', function() {
return {
priority: 1,
scope: {},
controller: 'optionsCtrl',
controllerAs: 'ctrl',
bindToController: {},
templateUrl: OC.linkTo('contacts', 'templates/Options.html')
};
});
50 changes: 35 additions & 15 deletions js/components/detailsItem/detailsItem_controller.js
@@ -1,5 +1,5 @@
angular.module('contactsApp')
.controller('detailsItemCtrl', function($templateRequest, vCardPropertiesService, ContactService) {
.controller('detailsItemCtrl', function($templateRequest, vCardPropertiesService, ContactService, SettingsService) {
var ctrl = this;

ctrl.meta = vCardPropertiesService.getMeta(ctrl.name);
Expand All @@ -15,12 +15,21 @@ angular.module('contactsApp')
newGroup: t('contacts', '(new group)'),
familyName: t('contacts', 'Last name'),
firstName: t('contacts', 'First name'),
phoneticFirstName: t('contacts', 'Phonetic first name'),
phoneticLastName: t('contacts', 'Phonetic last name'),
additionalNames: t('contacts', 'Additional names'),
honorificPrefix: t('contacts', 'Prefix'),
honorificSuffix: t('contacts', 'Suffix'),
delete: t('contacts', 'Delete')
};

function updateOptions() {
ctrl.phoneticEnable = SettingsService.get('phoneticEnable');
ctrl.reverseNameOrder = SettingsService.get('reverseNameOrder');
}
SettingsService.subscribe(updateOptions);
updateOptions();

ctrl.availableOptions = ctrl.meta.options || [];
if (!_.isUndefined(ctrl.data) && !_.isUndefined(ctrl.data.meta) && !_.isUndefined(ctrl.data.meta.type)) {
// parse type of the property
Expand Down Expand Up @@ -62,6 +71,9 @@ angular.module('contactsApp')
ctrl.availableGroups = _.unique(groups);
});

ctrl.data.phoneticFirstName = ctrl.model.contact.phoneticFirstName();
ctrl.data.phoneticLastName = ctrl.model.contact.phoneticLastName();

ctrl.changeType = function (val) {
if (ctrl.isPreferred) {
val += ',PREF';
Expand All @@ -87,26 +99,34 @@ angular.module('contactsApp')

ctrl.updateDetailedName = function () {
var fn = '';
if (ctrl.data.value[3]) {
fn += ctrl.data.value[3] + ' ';
}
if (ctrl.data.value[1]) {
fn += ctrl.data.value[1] + ' ';
}
if (ctrl.data.value[2]) {
fn += ctrl.data.value[2] + ' ';
}
if (ctrl.data.value[0]) {
fn += ctrl.data.value[0] + ' ';
}
if (ctrl.data.value[4]) {
fn += ctrl.data.value[4];
var order;
var fnItem = [];
if (ctrl.reverseNameOrder) {
order = [ 3, 0, 2, 1, 4 ];
} else {
order = [ 3, 1, 2, 0, 4 ];
}
angular.forEach(order, function(index) {
if (ctrl.data.value[index]) {
fnItem.push(ctrl.data.value[index]);
}
});
fn = fnItem.join(' ');

ctrl.model.contact.fullName(fn);
ctrl.model.updateContact();
};

ctrl.updatePhoneticFirstName = function () {
ctrl.model.contact.phoneticFirstName(ctrl.data.phoneticFirstName);
ctrl.model.updateContact();
};

ctrl.updatePhoneticLastName = function () {
ctrl.model.contact.phoneticLastName(ctrl.data.phoneticLastName);
ctrl.model.updateContact();
};

ctrl.getTemplate = function() {
var templateUrl = OC.linkTo('contacts', 'templates/detailItems/' + ctrl.meta.template + '.html');
return $templateRequest(templateUrl);
Expand Down
40 changes: 40 additions & 0 deletions js/models/contact_model.js
Expand Up @@ -38,6 +38,16 @@ angular.module('contactsApp')
return [this.lastName(), this.firstName()];
},

sortPhoneticFirstName: function() {
return [this.phoneticFirstName() ? this.phoneticFirstName() : this.firstName(),
this.phoneticLastName() ? this.phoneticLastName() : this.lastName()];
},

sortPhoneticLastName: function() {
return [this.phoneticLastName() ? this.phoneticLastName() : this.lastName(),
this.phoneticFirstName() ? this.phoneticFirstName() : this.firstName()];
},

sortDisplayName: function() {
return this.displayName();
},
Expand All @@ -64,6 +74,36 @@ angular.module('contactsApp')
}
},

phoneticFirstName: function(value) {
var model = this;
if (angular.isDefined(value)) {
// setter
return this.setProperty('X-PHONETIC-FIRST-NAME', { value: value });
} else {
// getter
var property = model.getProperty('X-PHONETIC-FIRST-NAME');
if(property) {
return property.value;
}
return undefined;
}
},

phoneticLastName: function(value) {
var model = this;
if (angular.isDefined(value)) {
// setter
return this.setProperty('X-PHONETIC-LAST-NAME', { value: value });
} else {
// getter
var property = model.getProperty('X-PHONETIC-LAST-NAME');
if(property) {
return property.value;
}
return undefined;
}
},

additionalNames: function() {
var property = this.getProperty('n');
if (property) {
Expand Down
21 changes: 20 additions & 1 deletion js/services/settings_service.js
@@ -1,13 +1,28 @@
angular.module('contactsApp')
.service('SettingsService', function() {
var subscriptions = [];
var settings = {
addressBooks: [
'testAddr'
]
],
phoneticEnable: false,
reverseNameOrder: false,
};

Object.assign(settings, JSON.parse(window.localStorage.getItem('contacts_settings')));

function notifyObservers () {
angular.forEach(subscriptions, function (subscription) {
if (typeof subscription === 'function') {
subscription();
}
});
}

this.set = function(key, value) {
settings[key] = value;
window.localStorage.setItem('contacts_settings', JSON.stringify(settings));
notifyObservers();
};

this.get = function(key) {
Expand All @@ -17,4 +32,8 @@ angular.module('contactsApp')
this.getAll = function() {
return settings;
};

this.subscribe = function (callback) {
subscriptions.push (callback);
};
});
4 changes: 3 additions & 1 deletion js/services/sortBy_service.js
Expand Up @@ -32,7 +32,9 @@ angular.module('contactsApp')
return {
sortDisplayName: t('contacts', 'Display name'),
sortFirstName: t('contacts', 'First name'),
sortLastName: t('contacts', 'Last name')
sortLastName: t('contacts', 'Last name'),
sortPhoneticFirstName: t('contacts', 'Phonetic first name'),
sortPhoneticLastName: t('contacts', 'Phonetic last name'),
};
}
};
Expand Down
2 changes: 2 additions & 0 deletions l10n/ja.js
Expand Up @@ -29,6 +29,8 @@ OC.L10N.register(
"(new group)" : "(新規グループ)",
"Last name" : "姓",
"First name" : "名",
"Phonetic last name" : "せい",
"Phonetic first name" : "めい",
"Additional names" : "ミドルネーム",
"Prefix" : "プレフィックス",
"Suffix" : "サフィックス",
Expand Down
4 changes: 3 additions & 1 deletion l10n/ja.json
Expand Up @@ -27,6 +27,8 @@
"(new group)" : "(新規グループ)",
"Last name" : "姓",
"First name" : "名",
"Phonetic last name" : "せい",
"Phonetic first name" : "めい",
"Additional names" : "ミドルネーム",
"Prefix" : "プレフィックス",
"Suffix" : "サフィックス",
Expand Down Expand Up @@ -63,4 +65,4 @@
"Social network" : "ソーシャルネットワーク",
"Settings" : "設定"
},"pluralForm" :"nplurals=1; plural=0;"
}
}
8 changes: 8 additions & 0 deletions templates/Options.html
@@ -0,0 +1,8 @@
<div>
<input type="checkbox" class="checkbox u-left" id="contact-phonetic" name="contact-phonetic" ng-model="ctrl.phoneticEnable" ng-change="ctrl.updateOptions()"/>
<label for="contact-phonetic">{{ctrl.t.phoneticText}}</label><br>
</div>
<div>
<input type="checkbox" class="checkbox u-left" id="contact-reverse-order" name="contact-reverse-order" ng-model="ctrl.reverseNameOrder" ng-change="ctrl.updateOptions()"/>
<label for="contact-reverse-order">{{ctrl.t.reverseNameOrderText}}</label><br>
</div>
38 changes: 38 additions & 0 deletions templates/detailItems/n.html
Expand Up @@ -5,21 +5,59 @@
<input type="text" id="details-honorificPrefix" name="honorificPrefix" ng-model="ctrl.data.value[3]" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updateDetailedName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
<div ng-if="!ctrl.reverseNameOrder">
<div>
<label for="details-firstName">{{ctrl.t.firstName}}</label>
<input type="text" id="details-firstName" name="firstName" ng-model="ctrl.data.value[1]" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updateDetailedName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
<div ng-if="ctrl.phoneticEnable">
<label for="details-phonetic-firstName">{{ctrl.t.phoneticFirstName}}</label>
<input type="text" id="details-phonetic-firstName" name="phoneticFirstName" ng-model="ctrl.data.phoneticFirstName" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updatePhoneticFirstName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
</div>
<div ng-if="ctrl.reverseNameOrder">
<div>
<label for="details-familyName">{{ctrl.t.familyName}}</label>
<input type="text" id="details-familyName" name="familyName" ng-model="ctrl.data.value[0]" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updateDetailedName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
<div ng-if="ctrl.phoneticEnable">
<label for="details-phonetic-lastName">{{ctrl.t.phoneticLastName}}</label>
<input type="text" id="details-phonetic-lastName" name="phoneticLastName" ng-model="ctrl.data.phoneticLastName" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updatePhoneticLastName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
</div>
<div>
<label for="details-additionalNames">{{ctrl.t.additionalNames}}</label>
<input type="text" id="details-additionalNames" name="additionalNames" ng-model="ctrl.data.value[2]" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updateDetailedName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
<div ng-if="!ctrl.reverseNameOrder">
<div>
<label for="details-familyName">{{ctrl.t.familyName}}</label>
<input type="text" id="details-familyName" name="familyName" ng-model="ctrl.data.value[0]" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updateDetailedName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
<div ng-if="ctrl.phoneticEnable">
<label for="details-phonetic-lastName">{{ctrl.t.phoneticLastName}}</label>
<input type="text" id="details-phonetic-lastName" name="phoneticLastName" ng-model="ctrl.data.phoneticLastName" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updatePhoneticLastName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
</div>
<div ng-if="ctrl.reverseNameOrder">
<div>
<label for="details-firstName">{{ctrl.t.firstName}}</label>
<input type="text" id="details-firstName" name="firstName" ng-model="ctrl.data.value[1]" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updateDetailedName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
<div ng-if="ctrl.phoneticEnable">
<label for="details-phonetic-firstName">{{ctrl.t.phoneticFirstName}}</label>
<input type="text" id="details-phonetic-firstName" name="phoneticFirstName" ng-model="ctrl.data.phoneticFirstName" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updatePhoneticFirstName()"
autocomplete="off" autocorrect="off" spellcheck="false" value="" />
</div>
</div>
<div>
<label for="details-honorificSuffix">{{ctrl.t.honorificSuffix}}</label>
<input type="text" id="details-honorificSuffix" name="honorificSuffix" ng-model="ctrl.data.value[4]" ng-model-options="{ debounce: 500 }" ng-change="ctrl.updateDetailedName()"
Expand Down
1 change: 1 addition & 0 deletions templates/main.php
Expand Up @@ -41,6 +41,7 @@
<addressBookList></addressBookList>
<contactImport></contactImport>
<sortBy></sortBy>
<Options></Options>
</div>
</div>
</div>
Expand Down