4
SmartMergeDialog = Y.Base.create('smartMergeDialog', Y.Overlay, [], {
5
initializer: function() {
6
this._getMergeCandidates();
9
/* Listen for escape event. */
10
Y.on('keydown', function(e) {
11
if (e.keyCode === 27) {
13
Y.Global.fire('one:idle');
17
_getMergeCandidates: function() {
18
Y.io('/contacts/_/smart_merge_contact_list', {
19
timeout: 2*60*1000, // 2 minutes
21
success: Y.bind(this._populateContent, this),
22
failure: Y.bind(this._handleFailure, this)
26
_handleCancel: function(e) {
30
_handleFailure: function() {
31
Y.Global.fire('one:idle');
32
Y.Global.fire('one:error');
35
_handleSave: function(e) {
37
Y.Global.fire('one:busy');
38
Y.io('/contacts/merge', {
40
data: {'csrfmiddlewaretoken': YUI.Env.CSRF_TOKEN},
41
timeout: 2*60*1000, // 2 minutes
43
id: Y.one('#smart-merge-form')
46
success: Y.bind(this._saveSuccess, this),
52
_populateContent: function(id, response) {
53
if (!this.get('cancelled')) {
54
var content = Y.Node.create('<div class="contact-box">' +
55
response.responseText + '</div>'),
57
footer = Y.Node.create('<div class="control-footer"></div>'),
58
submitButton = content.one('input[type="submit"]'),
65
submitButton.remove();
66
wrapperDiv = Y.Node.create(
68
description = Y.Node.create(
69
'<p>' + this.get('strings').description + '</p>'),
70
save = Y.Node.create('<a class="clickable save-button">Merge</a>'),
71
cancel = Y.Node.create('<a class="clickable cancel-button">Cancel</a>');
73
wrapperDiv.appendChild(description);
74
wrapperDiv.appendChild(content);
75
this.set('bodyContent', wrapperDiv);
77
save.on(CLICK, this._handleSave, this);
78
cancel.on(CLICK, this._handleCancel, this);
80
footer.appendChild(save);
81
footer.appendChild(cancel);
82
this.set('footerContent', footer);
85
close = Y.Node.create(
86
'<a class="clickable save-button">OK</a>');
87
close.on(CLICK, this._handleCancel, this);
89
footer.appendChild(close);
90
this.set('bodyContent', content);
91
this.set('footerContent', footer);
93
Y.Global.fire('one:idle');
97
_saveFailure: function() {
98
Y.Global.fire('one:idle');
102
this.get('strings').error_msg);
104
_saveSuccess: function() {
105
Y.Global.fire('one:stale');
106
Y.Global.fire('one:idle');
111
headerContent: { value: '<h2>Merge contacts</h2>' },
112
visible: { value: true },
113
centered: { value: true },
114
width: { value: '400px' },
115
zIndex: { value: 1000 },
124
description: "We found some contacts that look pretty similar. We can merge them together if you'd like.",
125
error_msg: "We're sorry. Something has gone wrong. Our engineers have been notified."
130
Y.SmartMergeDialog = SmartMergeDialog;