Patch Email DeleteAll

From WebOS Internals

Revision as of 02:41, 15 October 2009 by Lclarkjr (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Introduction

This will add two buttons at the bottom of the screen between the Compose and Refresh buttons. One with a trashcan icon for delete all and one with an ! for the read all. Selecting the delete all button will delete all email items in the list after prompting for confirmation. Selecting the read all button will mark all the emails items in the list as read after prompting for confirmation.

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


Editing Process

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'},
{label:$L('All Read'), icon:'priority', command:'readall'},

Find the handleCommand function and add the following case statement:

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

case 'readall':
    this.handleReadAll();
    break;

Now add the following six functions:

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'}
			]
	});
  },

  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();
					
					//send msg to delete a bogus msg id. It will fail but will also give the list a chance to update
					//so that when the deleteall gets called again we can proceed
					//just calling deleteall causes an endless loop because the list doesnt get a chance to update if
					//the 0 index item does not happen to be part of the currently loaded set of data
					//need to find a better way to get the list to refresh but this should work for now.
					this.controller.serviceRequest(Email.identifier, {
					        method: 'setDeleted',
						parameters: {'message':-1, 'value': true },
						onSuccess: this.handleDeleteAllResponse.bind(this),
						onFailure: this.handleDeleteAllResponse.bind(this)
						});
				}
			}
		}//for
	}//count > 0
  },

  handleReadAllResponse: function (event) {
  },

  readAll: function(tleft){
  	var count = this.emailListElement.mojo.getLength();
	var id;
	while(tleft > 0) 
	{	
		var item = this.emailListElement.mojo.getNodeByIndex((tleft - 1));	
		if(item !== undefined)
		{
		   	id = item.id;
		   	if(id)
		   	{
				this.controller.serviceRequest(Email.identifier, {
			        	method: 'setRead',
			                parameters: {'message':id, 'value': true },
			                onSuccess: this.handleReadAllResponse.bind(this),
			                onFailure: this.handleReadAllResponse.bind(this)
	             			});
	     		}
	     	
	     		tleft = tleft - 1;
		}
		else
		{
			tleft = tleft - 1;
		}
	}	
  },
  

  handleReadAll: function (event) {
   		var totalCount = 0;
		totalCount = this.emailListElement.mojo.getLength();
		if (totalCount > 0) {
			this.controller.showAlertDialog({
        	    onChoose: function(value) {
  	        		if(value == 'yes') {
  	        				var tleft = totalCount;
							this.readAll(tleft);
	               	}
				},
	               	title: '<b>' + $L('All Read') + '</b>',
                	message: $L('Are you sure you want to mark ') + "<b>" + totalCount + "</b>" + $L(' items in this folder read?'),
                    choices: [
                    	{label:$L('Yes'), value:'yes', type:'affirmative'},
                        {label:$L('No'), value:'no', type:'alert'}
                    ]
        		});
  		}
  },
Personal tools
Google AdSense