6 new, 4 modified for 1.3.5
[webos-internals:djcin7s-modifications.git] / contacts / contacts-swipe-to-delete.patch
1 --- /usr/palm/applications/com.palm.app.contacts/app/controllers/list-assistant.js.orig Wed Aug 19 15:19:40 2009
2 +++ /usr/palm/applications/com.palm.app.contacts/app/controllers/list-assistant.js      Mon Dec  7 07:45:16 2009
3 @@ -302,7 +302,10 @@
4                         lookahead: 50,
5                         renderLimit: 200,
6                         scrollThreshold: 4800,
7                         
8 +                       swipeToDelete:true,
9 +                       autoconfirmDelete:false,
10 +                       
11                         dividerTemplate: 'list/group_separator',
12                         dividerFunction: this.getDivider,
13                         emptyTemplate: 'list/empty'
14 @@ -315,6 +318,7 @@
15                 this.controller.listen(this.listDiv, Mojo.Event.filter, this.handleFilter.bindAsEventListener(this), true);
16                 this.controller.listen(this.listDiv, Mojo.Event.filterImmediate, this.handleFilterImmediate.bindAsEventListener(this));
17                 this.controller.listen(this.listDiv, Mojo.Event.listTap, this.handleListTap.bindAsEventListener(this));
18 +               this.controller.listen(this.listDiv, Mojo.Event.listDelete, this.handleListDelete.bindAsEventListener(this));
19                 this.emptyHolder = this.controller.get('emptyHolder');
20  
21                 if (this.mode != "picker") {
22 @@ -417,6 +421,7 @@
23                 if (this.mode != "picker") {
24                         AppAssistant.listResetCallback = undefined;
25                 }
26 +               this.controller.stopListening(this.listDiv, Mojo.Event.listDelete, this.handleListDelete);
27         },
28         
29         scrollStarting: function(event) {
30 @@ -534,7 +539,178 @@
31                         }
32                 }
33         },
34         
35 +       handleListDelete: function(event) {
36 +               this.targetId = event.item.id;
37 +               this.linkedRequest = AppAssistant.contactsService.getLinkedContacts(this.targetId, this.getLinkedContactsCallback.bind(this), this.controller, this.serviceForDeleteFailed.bind(this));
38 +       },
39 +       
40 +       doDelete: function() {
41 +               var deleteName = this.person.fullName ||
42 +               $L({
43 +                       value: "Person",
44 +                       key: "default_value_for_deletion_when_no_name"
45 +               });
46 +               var choices;
47 +               
48 +               var deleteContactChoice = {
49 +                       label: $L('Delete All Profiles'),
50 +                       value: 'DELETE_ALL',
51 +                       type: 'negative'
52 +               }
53 +               var deleteOtherContactsChoice = {
54 +                       label: $L('Delete other profiles'),
55 +                       value: 'DELETE_OTHERS',
56 +                       type: 'negative'
57 +               }
58 +               var cancelChoice = {
59 +                       label: $L('Cancel'),
60 +                       value: 'CANCEL',
61 +               }
62 +               choices = [];
63 +               var hasReadOnlyContact = false;
64 +               var hasWritableContact = false;
65 +               var readOnlyType = "";
66 +               this.linkedContacts.each(function(contact){
67 +                       if (contact.readOnly) {
68 +                               readOnlyType = contact.accountName;
69 +                               hasReadOnlyContact = true;
70 +                       } else {
71 +                               hasWritableContact = true;
72 +                       }
73 +               });
74 +               
75 +               var messageTemplate;
76 +               var extraPromptRequired = true;
77 +               if (hasReadOnlyContact && hasWritableContact) {
78 +                       messageTemplate = new Template($L('#{type} profiles cannot be deleted.  Delete all other profiles?'));
79 +                       choices.push(deleteOtherContactsChoice);
80 +                       choices.push(cancelChoice);
81 +               } else if (hasReadOnlyContact && !hasWritableContact) {
82 +                       messageTemplate = new Template($L('#{type} profiles can not be deleted'));
83 +                       choices.push(cancelChoice);
84 +               } else {
85 +                       extraPromptRequired = false;
86 +               }
87 +               
88 +               if (extraPromptRequired === true) {     
89 +                       var message = messageTemplate.evaluate({
90 +                               deleteName: deleteName,
91 +                               type:readOnlyType
92 +                       });
93 +                       this.controller.showAlertDialog({
94 +                               onChoose: function(value){
95 +                                       if (value == 'DELETE_ALL' || value == 'DELETE_OTHERS') {
96 +                                               var that = this;
97 +                                               this.linkedContacts.each(function(c){
98 +                                                       if (!c.readOnly) {
99 +                                                               AppAssistant.contactsService.doAsyncDelete(c.id);
100 +                                                       }
101 +                                               })
102 +                                               if (AppAssistant.listResetCallback) 
103 +                                                       AppAssistant.listResetCallback();
104 +                                               if (value == 'DELETE_ALL') {
105 +                                                       if(this.person.launcherId){
106 +                                                               new Mojo.Service.Request("palm://com.palm.applicationManager/removeLaunchPoint", {
107 +                                                                       parameters: {
108 +                                                                               launchPointId:this.person.launcherId,
109 +                                                                               id:"com.palm.app.contacts"
110 +                                                                       }
111 +                                                               })
112 +                                                       }
113 +                                               }
114 +                                       } else {
115 +                                               if (AppAssistant.listResetCallback) 
116 +                                                       AppAssistant.listResetCallback();
117 +                                       }
118 +                               }.bind(this),
119 +                               message: message,
120 +                               choices: choices
121 +                       });
122 +               } else {
123 +                       if(this.person.launcherId){
124 +                               new Mojo.Service.Request("palm://com.palm.applicationManager/removeLaunchPoint", {
125 +                                       parameters: {
126 +                                               launchPointId:this.person.launcherId,
127 +                                               id:"com.palm.app.contacts"
128 +                                       }
129 +                               });
130 +                       }
131 +                       this.linkedContacts.each(function(c){
132 +                               if (!c.readOnly) {
133 +                                       AppAssistant.contactsService.doAsyncDelete(c.id);
134 +                               }
135 +                       });
136 +               }
137 +       },
138 +       
139 +       getLinkedContactsCallback: function(resp){
140 +               resp.list.each(function(c){
141 +                       c.iconClass = AppAssistant.getIconClass(c.accountId)
142 +                       c.iconPath = Utilities.iconJSONToIconPath(c.accountIcons)
143 +               })
144 +               this.linkedContactsWithAccountIDs = resp.list;
145 +               if (this.linkedContacts) 
146 +                       this.giveContactsAccountIds();
147 +               this.detailRequest = AppAssistant.contactsService.details(this.targetId, this.renderContactForDelete.bind(this), this.controller, {
148 +                       collapse: false
149 +               }, this.serviceForDeleteFailed.bind(this));
150 +               this.isFirstLinking = false;
151 +       },
152 +       
153 +       giveContactsAccountIds: function(){
154 +               //Go through each contact, attatch its id to the matching contact in this.linkedContacts
155 +               for (var i = 0; i < this.linkedContactsWithAccountIDs.length; i++) {
156 +                       var linkedC = this.linkedContactsWithAccountIDs[i];
157 +                       for (var j = 0; j < this.linkedContacts.length; j++) {
158 +                               var c = this.linkedContacts[j];
159 +                               if (c.id == linkedC.id) {
160 +                                       if (linkedC.readOnly) {
161 +                                               c.disabled = true;
162 +                                       }
163 +                                       //TODO We need a better way to specify the diff between google contacts, and gtalk contacts
164 +                                       ///We should be putting better class names in the accounts.xml
165 +                                       if (linkedC.accountName == "Google") {
166 +                                               linkedC.accountDomain = "google";
167 +                                       }
168 +                                       c.accountDomain = linkedC.accountDomain;
169 +                                       
170 +                                       c.command = "c," + c.id + "," + linkedC.accountDomain;
171 +                                       c.label = c.getFullName() || $L("No name available");
172 +                                       c.accountName = linkedC.accountName;
173 +                                       c.readOnly = linkedC.readOnly;
174 +                                       c.iconPath = linkedC.iconPath;
175 +                               }
176 +                       }
177 +               }
178 +       },
179 +       
180 +       renderContactForDelete: function(response){
181 +               if(response.list.length < 1){
182 +                       Mojo.Log.info("No actual linked contacts, you must have deleted the last one.")
183 +                       if (AppAssistant.listResetCallback) 
184 +                               AppAssistant.listResetCallback();
185 +                       return;
186 +               }
187 +               response.list.each(function(c){
188 +                       //This might be a little costly, but we need the contact to be the same object that is in the linkedContacts arrays
189 +                       Object.extend(c, new Contact(c));
190 +               });
191 +               this.linkedContacts = response.list;
192 +               if (this.linkedContactsWithAccountIDs) 
193 +                       this.giveContactsAccountIds();
194 +               this.person = new Contact(response.person);
195 +               this.doDelete();
196 +       },
197 +       
198 +       serviceForDeleteFailed: function(resp){
199 +               this.linkedRequest.cancel();
200 +               this.detailRequest.cancel();
201 +               Mojo.Log.error("Getting contact details failed for id " + this.targetId + ". Response: %j", resp);
202 +               if (AppAssistant.listResetCallback) 
203 +                       AppAssistant.listResetCallback();
204 +       },
205 +       
206         peoplePickerDetailCallbackFailure:function(resp){
207                 this.controller.stageController.popScene(resp);
208         },