Welcome Guest, Not a member yet? Register   Sign In
Problem using Starbox with Code Igniner
#2

[eluser]geshan[/eluser]
So I got 50 views in a day but no Reply hope some are facing the same problem but can't find a solution well I've got the solution myself here.

Code:
[b]The JS Code[/b]

function get_rating_box(no,a,t){
    //new Starbox('rating_place_'+no, 2, { stars: 10, buttons: 20, max: 10 });
    new Starbox('rating_place_'+no, a, { /*notice a in place of average passed from the call which take a value form the database */
                                        stars: 5,
                                        className : 'default',
                                        buttons: 10,
                                        max: 5,
                                        overlay: 'big.png',
                                        indicator: '#{average}/#{max} out of #{total} votes',
                                        identity: no,
                                        ghosting: true,
                                        total: t, /*t is passed here from a php call that gets total value from the database */                
                                         rerate: false
                                        
    
     $('rating_place_'+no).observe('starbox:rated', starboxThankYou);
    
}//function get_rating_box_close


function starboxThankYou(event) {
/* Here's how to show a simple thank you message,
Some demos use it using the custom event 'starbox:rated', but this could also be used on onRate.

You could use the same technique to show error/success using the callback function in your Ajax.Request:*/
para=event.memo;
p= event.memo.rated;
gid=event.memo.identity;
/*new Ajax.Request('savestar.php', {
    parameters: event.memo,
    onComplete: function() { ... }
  );
}*/

new Ajax.Request('/xyz/index.php/ratcom/add_rating', { /* ratcom is a model handling rating and comments*/
                  parameters: event.memo,
                  method: 'post',
     onSuccess: function() {  
        var msg = $('rating_msg_'+gid);
        msg.update('Rating Added successfully.').setStyle({ background: '#dfd' });
        window.setTimeout(function() { msg.update("") }, 2000);
         },
     onFailure: function() {
         var msg = $('rating_msg_'+gid);
         msg.update('Rating Add Failed.').setStyle({ background: '#ff0' });
         window.setTimeout(function() { msg.update("") }, 2000);
         },
     onLoading: function() {
          var msg = $('rating_msg_'+gid);
         msg.update('Adding Rating.');
         }
    
    });

/* More on Ajax.Request: http://www.prototypejs.org/api/ajax/request
*/
var indicator = event.element().down('.indicator');
var restore = indicator[removed];
indicator.update('Thanks for voting');
window.setTimeout(function() { indicator.update(restore) }, 2000);
}


[b]The call form .php [/b]

<div id="rating_place_&lt;?php echo $id; ?&gt;" onDblClick="get_rating_box(&lt;?php echo $id; ?&gt;,&lt;?php echo $a; ?&gt;,&lt;?php echo $t; ?&gt;);">Double click here to Rate...</div>    
        <div id="notify" style="display:none">
                   <div class="message"> You have clicked <span class="element"></span> <span class="rated"></span>
              </div>        
       </div>&lt;!-- Div notify close--&gt;
       <div id="rating_msg_&lt;?php echo $id; ?&gt;"></div> &lt;?php /* id is the id of the things to be rated */ ?&gt;

An important tip don't call "new starbox( parameters); " on OnMouseOver or even OnClick.
Happy coding and using Starbox with CI.


Messages In This Thread
Problem using Starbox with Code Igniner - by El Forum - 03-29-2008, 11:34 PM
Problem using Starbox with Code Igniner - by El Forum - 03-31-2008, 02:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB