Posted by: Wildan Maulana | April 3, 2009

Code for Maintain OFC Portlet Metadata

Is there any other way which is more effective than the following code ?

// Licensed : MIT License, Wildan
//hash object for maintain portlet metadata - actually it's just key value pair 
// key : portletID 
// value : serialized form on the dialog box that will be send to the server and 
//         then repaint the OFC instance 

var hash = {
	storedHash: {"data": []},
	
	updateHash: function(portletID, param) {
        //maintain storedHash
        
         var newObj = {'portletID':portletID,'param':param} ;

         if(hash.storedHash.data.length == 0) {
        	 hash.storedHash.data.push(newObj);
         } else { 
        	 for(var i = hash.storedHash.data.length - 1; i >= 0; --i) {
        		if(hash.hiPortletID(portletID)) {
            		if(hash.storedHash.data[i].portletID == portletID) {
        			  hash.storedHash.data[i].param = param;
            		}
        		} else {
               	   hash.storedHash.data.push(newObj);
        		}
        	 }
         }                   
	},

	//check if there is same portletID found 
    hiPortletID: function(portletID) {
    	for(var i = hash.storedHash.data.length - 1; i >= 0; --i) {
        	if(hash.storedHash.data[i].portletID == portletID) {
            	return   true ;
        	}
    	}

    	return false ;
    },    	
	
};

hash.updateHash("portlet_1","param_one");
hash.updateHash("portlet_2","param_two");
hash.updateHash("portlet_1","param_one_update");


alert(JSON.stringify(hash.storedHash.data));
Test Result

Test Result


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: