Difference between revisions of "Patch Email DeleteAll"

From WebOS Internals
Jump to navigation Jump to search
(Fix bug in delete all causing an endless loop and include read all functionality.)
 
Line 1: Line 1:
 
{{template:patch}}
 
{{template:patch}}
 
==Introduction==
 
==Introduction==
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.
+
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.
 
I am deliberately not using line numbers to minimize the need for updates as new WebOS releases come out.
Line 18: Line 18:
 
with  
 
with  
  
<pre><nowiki>{label:$L('Delete All'), icon:'delete', command:'deleteall'},</nowiki></pre>
+
<pre><nowiki>
 +
{label:$L('Delete All'), icon:'delete', command:'deleteall'},
 +
{label:$L('All Read'), icon:'priority', command:'readall'},
 +
</nowiki></pre>
  
 
Find the handleCommand function and add the following case statement:
 
Find the handleCommand function and add the following case statement:
Line 24: Line 27:
 
<pre><nowiki>
 
<pre><nowiki>
 
case 'deleteall':
 
case 'deleteall':
this.handleDeleteAll();
+
    this.handleDeleteAll();
break;
+
    break;
 +
 
 +
case 'readall':
 +
    this.handleReadAll();
 +
    break;
 
</nowiki></pre>
 
</nowiki></pre>
  
Now add the following three functions:
+
Now add the following six functions:
  
 
<pre><nowiki>
 
<pre><nowiki>
 +
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) {
 
   handleDeleteAllResponse: function (event) {
 
         //check to see if there are more items to delete.
 
         //check to see if there are more items to delete.
        this.deleteAll();
+
this.deleteAll();
 
   },
 
   },
  
 
   deleteAll: function(){
 
   deleteAll: function(){
 
+
   
  var count = this.emailListElement.mojo.getLength();
+
    var count = this.emailListElement.mojo.getLength();
 +
     
 +
var id;
 +
             
 +
if(count > 0)
 +
{
 +
      var i;
  
        var id;
+
      //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(count > 0)
+
if(item !== undefined)
        {
+
{
                var i;
+
id = item.id;
  
                //Since the list is loaded dynamically we may have the count of all emails but not all of the data
+
if(id)
                //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
+
if(i === 0)
                for(i=count-1; i>=0; i--)
+
{
                {
+
this.controller.serviceRequest(Email.identifier, {
                        var item = this.emailListElement.mojo.getNodeByIndex(i);
+
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
 +
  },
  
                        if(item !== undefined)
+
  handleReadAllResponse: function (event) {
                        {
+
  },
                                id = item.id;
 
  
                                if(id)
+
  readAll: function(tleft){
                                {
+
  var count = this.emailListElement.mojo.getLength();
                                        if(i==0)
+
var id;
                                        {
+
while(tleft > 0)  
                                                this.controller.serviceRequest(Email.identifier, {
+
{
                                                        method: 'setDeleted',
+
var item = this.emailListElement.mojo.getNodeByIndex((tleft - 1));
                                                        parameters: {'message':id, 'value': true },
+
if(item !== undefined)
                                                        onSuccess: this.handleDeleteAllResponse.bind(this),
+
{
                                                        onFailure: this.handleDeleteAllResponse.bind(this)
+
  id = item.id;
                                                        });
+
  if(id)
                                        }
+
  {
                                        else
+
this.controller.serviceRequest(Email.identifier, {
                                        {
+
        method: 'setRead',
                                                this.controller.serviceRequest(Email.identifier, {
+
                parameters: {'message':id, 'value': true },
                                                        method: 'setDeleted',
+
                onSuccess: this.handleReadAllResponse.bind(this),
                                                        parameters: {'message':id, 'value': true },
+
                onFailure: this.handleReadAllResponse.bind(this)
                                                        onSuccess: undefined,
+
            });
                                                        onFailure: undefined
+
    }
                                                        });
+
   
                                        }
+
    tleft = tleft - 1;
                                }//if(id)
+
}
                        }//if item !== undefined
+
else
                        else
+
{
                        {
+
tleft = tleft - 1;
                                if(i==0)
+
}
                                {
+
}
                                        //item was undefined probably because it is currently marked for delete
 
                                        this.deleteAll();
 
                                }
 
                        }
 
                }//for
 
        }//count > 0
 
 
   },
 
   },
 +
 
  
   handleDeleteAll: function (event) {
+
   handleReadAll: function (event) {
 
+
  var totalCount = 0;
var totalCount = 0;
+
totalCount = this.emailListElement.mojo.getLength();
+
if (totalCount > 0) {
totalCount = this.emailListElement.mojo.getLength();
+
this.controller.showAlertDialog({
+
            onChoose: function(value) {
this.controller.showAlertDialog({
+
          if(value == 'yes') {
                            onChoose: function(value) {
+
          var tleft = totalCount;
                                if(value == 'yes') {
+
this.readAll(tleft);
//Delete all items in this folder
+
              }
this.deleteAll();
+
},
                                }
+
              title: '<b>' + $L('All Read') + '</b>',
},
+
                message: $L('Are you sure you want to mark ') + "<b>" + totalCount + "</b>" + $L(' items in this folder read?'),
                                title: '<b>' + $L('Delete All') + '</b>',
+
                    choices: [
                      message: $L('Are you sure you want to delete all ') + "<b>" + totalCount + "</b>" + $L(' items in this folder?'),
+
                    {label:$L('Yes'), value:'yes', type:'affirmative'},
                      choices: [
+
                        {label:$L('No'), value:'no', type:'alert'}
                              {label:$L('Yes'), value:'yes', type:'affirmative'},
+
                    ]
                                    {label:$L('No'), value:'no', type:'alert'}
+
        });
                                                ]
+
  }
                });
 
 
   },
 
   },
 
</nowiki></pre>
 
</nowiki></pre>

Latest revision as of 03:41, 15 October 2009


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