Patch Email DeleteAll

From WebOS Internals
Revision as of 20:33, 20 September 2009 by Mamouton (talk | contribs)
Jump to: navigation, search
<<- Return to webOS Patches


This will add a button at the bottom of the screen with a trashcan icon between the Compose and Refresh buttons. Selecting the button will delete all email items in the list after prompting the user for confirmation.

I am deliberately not using line numbers to minimize the need for updates as new WebOS releases come out.

Open:

/usr/palm/applications/com.palm.app.email/app/controllers/list-assistant.js

Find the setup function and modify the cmdMenuModel items, replace the

{},

with

{label:$L('Delete All'), icon:'delete', command:'deleteall'},

Find the handleCommand function and add the following case statement:

case 'deleteall':
	this.handleDeleteAll();
	break;

Now add the following three functions:

  handleDeleteAllResponse: function (event) {
        //check to see if there are more items to delete.
        this.deleteAll();
  },

  deleteAll: function(){
  
  	var count = this.emailListElement.mojo.getLength();

        var id;

        if(count > 0)
        {
                var i;

                //Since the list is loaded dynamically we may have the count of all emails but not all of the data
                //So start with count and work backward with error handling
                //When reach 0 trigger at least one more pass after data has had a chance to refresh
                for(i=count-1; i>=0; i--)
                {
                        var item = this.emailListElement.mojo.getNodeByIndex(i);

                        if(item !== undefined)
                        {
                                id = item.id;

                                if(id)
                                {
                                        if(i==0)
                                        {
                                                this.controller.serviceRequest(Email.identifier, {
                                                        method: 'setDeleted',
                                                        parameters: {'message':id, 'value': true },
                                                        onSuccess: this.handleDeleteAllResponse.bind(this),
                                                        onFailure: this.handleDeleteAllResponse.bind(this)
                                                        });
                                        }
                                        else
                                        {
                                                this.controller.serviceRequest(Email.identifier, {
                                                        method: 'setDeleted',
                                                        parameters: {'message':id, 'value': true },
                                                        onSuccess: undefined,
                                                        onFailure: undefined
                                                        });
                                        }
                                }//if(id)
                        }//if item !== undefined
                        else
                        {
                                if(i==0)
                                {
                                        //item was undefined probably because it is currently marked for delete
                                        this.deleteAll();
                                }
                        }
                }//for
        }//count > 0
  },

  handleDeleteAll: function (event) {
   	
	var totalCount = 0;
	
	totalCount = this.emailListElement.mojo.getLength();
	
	this.controller.showAlertDialog({
                             onChoose: function(value) {
  	                              		if(value == 'yes') {
							//Delete all items in this folder
							this.deleteAll();
	                        	        	}
						},
	                                	title: '<b>' + $L('Delete All') + '</b>',
                      				message: $L('Are you sure you want to delete all ') + "<b>" + totalCount + "</b>" + $L(' items in this folder?'),
                       				choices: [
                               				{label:$L('Yes'), value:'yes', type:'affirmative'},
                                    			{label:$L('No'), value:'no', type:'alert'}
                                                 	]
                			});
  },