Assembla home | Assembla project page
 

Changeset 221

Show
Ignore:
Timestamp:
03/01/09 13:13:14 (1 year ago)
Author:
aprice30
Message:

Fixed the dashboard JS code so moved widgets are positioned correctly. Also moved around some dashboard code so its all in a single module, Closes #64

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/assets/admin/js/dashboard.js

    r114 r221  
    1212        // Get the current dashboard settings from the cookie 
    1313        // and position the widgets accordingly 
     14        // 
     15        // When the widgets are saved there are saved in a string with the following 
     16        // format 
     17        // 
     18        // {region}[]={widget_id}&...&{widget_id}[]=visible/hidden 
     19        // 
     20        // Where the following variables exist: 
     21        //      {region}        = The dashboard region, either topsection, leftsection or rightsection 
     22        //      {widget_id} = The widget md5 name hash 
     23        // 
     24        // The actual widgets have ID of something like widget_98321j3ky98123jk213 but only ever 
     25        // the bit after widget_ is stored 
    1426        var arr = $.cookie('bep_dashboard'); 
    1527        if( arr != null) 
     
    2941                                // We have a visibility cmd 
    3042                                if(cmd[1] == 'hidden') 
    31                                         $('#'+cmd[0],regions).hide(); 
     43                                        $('#widget_'+cmd[0],regions).hide(); 
    3244                        } 
    33                 }       
     45                }   
    3446         } 
    3547   
     
    93105        // Save the order which the widgets are in 
    94106        regions.each(function(){ 
    95                 cookie = cookie + "&" + $(this).sortable("serialize").replace(/widget/g, $(this).attr('id')); 
     107                var widget = $(this).sortable("serialize").replace(/widget/g, $(this).attr('id')); 
     108                 
     109                // If no widgets in region, move to next region 
     110                if(widget == "") return true; 
     111                 
     112                if(cookie == "") cookie = widget; 
     113                else cookie = cookie + "&" + widget; 
    96114        }); 
    97115         
     
    99117        // If it isn't meant to be shown hide the widget 
    100118        widgets.each(function(){ 
     119                newID = $(this).attr('id').replace(/widget_/g, ''); 
    101120                if($('div.action img:visible',this).hasClass('db-hidden')){ 
    102121                        // Cross is showing 
    103                         cookie = cookie + "&" + $(this).attr('id') + "[]=hidden"; 
     122                        cookie = cookie + "&" + newID + "[]=hidden"; 
    104123                        $(this).hide(); 
    105124                } 
    106125                else{ 
    107126                        // Tick is showing 
    108                         cookie = cookie + "&" + $(this).attr('id') + "[]=visible"; 
     127                        cookie = cookie + "&" + newID + "[]=visible"; 
    109128                } 
    110129        }); 
    111130         
    112131        // Save cookie 
    113         $.cookie('bep_dashboard',cookie.substring(1),{expires: 31}); 
     132        $.cookie('bep_dashboard',cookie,{expires: 31}); 
    114133         
    115134        // Hide the button and display the edit button 
  • trunk/modules/dashboard/language/english/dashboard_lang.php

    • Property svn:mergeinfo set
    r215 r221  
    3636 
    3737/* End of file dashboard_lang.php */ 
    38 /* Location: ./system/application/language/english/dashboard_lang.php */ 
     38/* Location: ./modules/dashboard/language/english/dashboard_lang.php */ 
  • trunk/modules/dashboard/libraries/Dashboard.php

    • Property svn:mergeinfo set
    r204 r221  
    1414 
    1515// --------------------------------------------------------------------------- 
     16 
     17include_once("Widget.php"); 
    1618 
    1719/** 
     
    3234         */ 
    3335        var $widgets = array(); 
     36 
     37        function Dashboard() 
     38        { 
     39                $this->CI =& get_instance(); 
     40 
     41                $this->CI->lang->load('dashboard'); 
     42        } 
    3443 
    3544        /** 
     
    8594} 
    8695 
    87 /** 
    88  * Widget class allows widgets to be created for the Dashboard class 
    89  * 
    90  * @package                     BackendPro 
    91  * @subpackage          Libraries 
    92  */ 
    93 class Widget 
    94 { 
    95         /** 
    96          * Name of widget 
    97          * 
    98          * @var string 
    99          */ 
    100         var $name; 
    101  
    102         /** 
    103          * Body contents of widget 
    104          * 
    105          * @var string 
    106          */ 
    107         var $body; 
    108  
    109         var $CI; 
    110  
    111         /** 
    112          * Constructor 
    113          * 
    114          * @access public 
    115          * @param string $name Name of widget 
    116          * @param string $body Body contents of widget 
    117          * @return boolean 
    118          */ 
    119         function widget($name = NULL, $body = NULL) 
    120         { 
    121                 $this->CI = get_instance(); 
    122                 if( is_null($name)) 
    123                 { 
    124                         return FALSE; 
    125                 } 
    126  
    127                 $this->name = $name; 
    128                 $this->body = $body; 
    129                 return TRUE; 
    130         } 
    131  
    132         /** 
    133          * Output widget code 
    134          * 
    135          * @access public 
    136          * @return string 
    137          */ 
    138         function output() 
    139         { 
    140                 $output = '<div class="widget" id="widget_' . $this->_name_convert() . '">'; 
    141                 $output.= '<div class="action">' . $this->CI->page->icon('tick') . $this->CI->page->icon('cross') .'</div>'; 
    142                 $output.= '<div class="header">'.$this->name.'</div>'; 
    143                 $output.= '<div class="body">'.$this->body.'</div>'; 
    144                 $output.= '</div>'; 
    145                 return $output; 
    146         } 
    147  
    148         /** 
    149          * Covert Widget name 
    150          * 
    151          * Coverts the widget name so it dosn't contain any spaces and is lower case. 
    152          * 
    153          * @access private 
    154          * @return string 
    155          */ 
    156         function _name_convert() 
    157         { 
    158                 return preg_replace("/ /","_",strtolower($this->name)); 
    159         } 
    160 } 
    16196/* End of file Dashboard.php */ 
    162 /* Location: ./system/application/libraries/Dashboard.php */ 
     97/* Location: ./modules/dashboard/libraries/Dashboard.php */ 
  • trunk/modules/dashboard/views/admin/dashboard

    • Property svn:mergeinfo set
  • trunk/system/application/controllers/admin/home.php

    r204 r221  
    2727                parent::Admin_Controller(); 
    2828 
    29                 // Load dashboard language file 
    30                 $this->lang->load('dashboard'); 
    31  
    3229                log_message('debug','BackendPro : Home class loaded'); 
    3330        } 
    3431 
    35        function index() 
    36        
    37                // Include dashboard Javascript code 
    38                $this->page->set_asset('admin','js','dashboard.js'); 
     32function index() 
     33
     34        // Include dashboard Javascript code 
     35        $this->page->set_asset('admin','js','dashboard.js'); 
    3936 
    40                // Load the dashboard library 
    41                $this->load->library('dashboard'); 
     37        // Load the dashboard library 
     38        $this->load->module_library('dashboard','dashboard'); 
    4239 
    43                 // Assign widgets to dashboard 
    44                 $this->dashboard->assign_widget(new widget($this->lang->line('dashboard_example'),$this->lang->line('dashboard_example_body')),'left'); 
    45                 $this->dashboard->assign_widget(new widget($this->lang->line('dashboard_statistics'),$this->_widget_statistics()),'right'); 
     40        // Load any widget libraries 
     41        $this->load->module_library('dashboard','Statistic_widget'); 
    4642 
    47                 // Load dashboard onto page 
    48                 $data['dashboard'] = $this->dashboard->output(); 
     43        // Assign widgets to dashboard 
     44        $this->dashboard->assign_widget(new widget($this->lang->line('dashboard_example'),$this->lang->line('dashboard_example_body')),'left'); 
     45        $this->dashboard->assign_widget(new widget($this->lang->line('dashboard_statistics'),$this->statistic_widget->create()),'right'); 
    4946 
    50                 // Display Page 
    51                 $data['header'] = $this->lang->line('backendpro_dashboard'); 
    52                 $data['page'] = $this->config->item('backendpro_template_admin') . "home"; 
    53                 $this->load->view($this->_container,$data); 
    54         } 
     47        // Load dashboard onto page 
     48        $data['dashboard'] = $this->dashboard->output(); 
    5549 
    56         /** 
    57          * Generate Statistics Code 
    58          * 
    59          * Generate the contents of the statistics widget and return it as a string. 
    60          * 
    61          * @access private 
    62          * @return string 
    63          */ 
    64         function _widget_statistics() 
    65         { 
    66                 $this->load->module_model('auth','user_model'); 
    67  
    68                 // Get total number of members 
    69                 $query = $this->user_model->getUsers(); 
    70                 $data['total_members'] = $query->num_rows(); 
    71  
    72                 // Get total number of unactivated members 
    73                 $query = $this->user_model->getUsers(array('users.active'=>'0')); 
    74                 $data['total_unactivated_members'] = $query->num_rows(); 
    75  
    76                 $data['system_status'] = ($this->preference->item('maintenance_mode')) ? '<font color="red">'.$this->lang->line('dashboard_statistics_offline').'</font>' : '<font color="green">'.$this->lang->line('dashboard_statistics_online').'</font>'; 
    77                 $data['user_registration'] = ($this->preference->item('allow_user_registration')) ? '<font color="green">'.$this->lang->line('dashboard_statistics_online').'</font>' : '<font color="red">'.$this->lang->line('dashboard_statistics_offline').'</font>'; 
    78  
    79                 return $this->load->view($this->config->item('backendpro_template_admin') . 'dashboard/statistics',$data,TRUE); 
    80         } 
     50        // Display Page 
     51        $data['header'] = $this->lang->line('backendpro_dashboard'); 
     52        $data['page'] = $this->config->item('backendpro_template_admin') . "home"; 
     53        $this->load->view($this->_container,$data); 
     54
    8155} 
    8256/* End of file home.php */ 
  • trunk/user_guide/features/dashboard.html

    r179 r221  
    6969<code> 
    7070function&nbsp;index()<br /> 
    71 {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> 
    72 &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;<kbd>1.</kbd>&nbsp;Include&nbsp;dashboard&nbsp;Javascript&nbsp;code<br /> 
    73 &nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;page-&gt;set_asset('admin','js','dashboard.js');<br /> 
     71{<br /> 
     72&nbsp;&nbsp;&nbsp;&nbsp;// <var>1</var> &nbsp;Include&nbsp;dashboard&nbsp;Javascript&nbsp;code<br /> 
     73&nbsp;&nbsp;&nbsp;&nbsp;$this->page->set_asset('admin','js','dashboard.js');<br /> 
    7474<br /> 
    75 &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;<kbd>2.</kbd>&nbsp;Load&nbsp;the&nbsp;dashboard&nbsp;library<br /> 
    76 &nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;load-&gt;library('dashboard');<br /> 
    77 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> 
    78 &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;<kbd>3.</kbd>&nbsp;Assign&nbsp;widgets&nbsp;to&nbsp;dashboard<br /> 
    79 &nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;dashboard-&gt;assign_widget(new&nbsp;widget($this-&gt;lang-&gt;line('dashboard_example'),$this-&gt;lang-&gt;line('dashboard_example_body')),'left');<br /> 
    80 &nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;dashboard-&gt;assign_widget(new&nbsp;widget($this-&gt;lang-&gt;line('dashboard_statistics'),<dfn>$this-&gt;_widget_statistics()</dfn>),'right');<br /> 
     75&nbsp;&nbsp;&nbsp;&nbsp;// <var>2</var> &nbsp;Load&nbsp;the&nbsp;dashboard&nbsp;library<br /> 
     76&nbsp;&nbsp;&nbsp;&nbsp;$this->load->module_library('dashboard','dashboard');<br /> 
    8177<br /> 
    82 &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;<kbd>4.</kbd>&nbsp;Load&nbsp;dashboard&nbsp;onto&nbsp;page<br /> 
    83 &nbsp;&nbsp;&nbsp;&nbsp;$data['dashboard']&nbsp;=&nbsp;$this-&gt;dashboard-&gt;output();<br /> 
     78&nbsp;&nbsp;&nbsp;&nbsp;// <var>3</var> &nbsp;Load&nbsp;any&nbsp;widget&nbsp;libraries<br /> 
     79&nbsp;&nbsp;&nbsp;&nbsp;$this->load->module_library('dashboard','Statistic_widget');<br /> 
     80<br /> 
     81&nbsp;&nbsp;&nbsp;&nbsp;// <var>4</var> &nbsp;Assign&nbsp;widgets&nbsp;to&nbsp;dashboard<br /> 
     82&nbsp;&nbsp;&nbsp;&nbsp;$this->dashboard->assign_widget(new&nbsp;widget($this->lang->line('dashboard_example'),$this->lang->line('dashboard_example_body')),'left');<br /> 
     83&nbsp;&nbsp;&nbsp;&nbsp;$this->dashboard->assign_widget(new&nbsp;widget($this->lang->line('dashboard_statistics'),$this->statistic_widget->create()),'right');<br /> 
     84<br /> 
     85&nbsp;&nbsp;&nbsp;&nbsp;// <var>5</var> &nbsp;Load&nbsp;dashboard&nbsp;onto&nbsp;page<br /> 
     86&nbsp;&nbsp;&nbsp;&nbsp;$data['dashboard']&nbsp;=&nbsp;$this->dashboard->output();<br /> 
    8487<br /> 
    8588&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Display&nbsp;Page<br /> 
    86 &nbsp;&nbsp;&nbsp;&nbsp;$data['header']&nbsp;=&nbsp;$this-&gt;lang-&gt;line('backendpro_dashboard');<br /> 
    87 &nbsp;&nbsp;&nbsp;&nbsp;$data['page']&nbsp;=&nbsp;$this-&gt;config-&gt;item('backendpro_template_admin')&nbsp;.&nbsp;&quot;home&quot;;<br /> 
    88 &nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;load-&gt;view($this-&gt;_container,$data);<br /> 
    89 }<br /> 
    90 <br /> 
    91 function&nbsp;<dfn>_widget_statistics()</dfn><br /> 
    92 {<br /> 
    93 &nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Generate&nbsp;widget&nbsp;contents,&nbsp;e.g&nbsp;table&nbsp;of&nbsp;data<br /> 
    94 &nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;$contents;<br /> 
     89&nbsp;&nbsp;&nbsp;&nbsp;$data['header']&nbsp;=&nbsp;$this->lang->line('backendpro_dashboard');<br /> 
     90&nbsp;&nbsp;&nbsp;&nbsp;$data['page']&nbsp;=&nbsp;$this->config->item('backendpro_template_admin')&nbsp;.&nbsp;"home";<br /> 
     91&nbsp;&nbsp;&nbsp;&nbsp;$this->load->view($this->_container,$data);<br /> 
    9592} 
    9693</code> 
     
    105102        of the <a href="#dashboard">Dashboard class</a>, storing it in <dfn>$this-&gt;dashboard</dfn>.</li> 
    106103         
     104        <li>Here we load any widget classes. These basicly contain code to create the view for the widget. 
     105        The advantage of having them in their own classes is to improve code readability. Please see <dfn>modules/dashboard/libraries/Statistics_widget.php</dfn> 
     106        for an example. I would advise creating a similar class for every widget.</li> 
     107         
    107108        <li>This section is where I create and assign widgets to the dashboard. As you can see two widgets are created  
    108         and assigned to the dashboard object. More details of the class methods used can be found below.</li> 
     109        and assigned to the dashboard object.</li> 
    109110         
    110111        <li>This last section generates the dashboard code.</li> 
    111112</ol> 
    112  
    113 <p>You will notice a private function in the example above called <dfn>_widget_statistics()</dfn>. This function  
    114 is used to generate the body contents of the statistics widget. The reason the code is in a function instead of inline  
    115 with the rest of the dashboard code is just to make it easier to read. <strong>I would advise you also put widget body  
    116 creation code inside their own functions to make your script more readable.</strong></p> 
    117113 
    118114<h2>Guarding a Widget</h2> 
  • trunk/user_guide/general/changelog.html

    r220 r221  
    6363<h3>Modifications</h3> 
    6464<ul> 
     65        <li>Moved some of the dashboard files into their own module to tidy the file system up a bit. Also have created a new class to store to Statistics Widget creation code it.</li> 
    6566        <li>Improved the <dfn>is_user()</dfn> method so if <dfn>$config['sess_use_database']</dfn> is <var>FALSE</var> then extra user checks are performed. For this to work the value returned by validateLogin() has changed, See <a href="http://trac2.assembla.com/backendpro/ticket/80">Enhancement #80</a></li> 
    6667        <li>Removed PHP short tags from files, See <a href="http://trac2.assembla.com/backendpro/ticket/42">Task #42</a></li> 
     
    7374<h3>Bug Fixes</h3> 
    7475<ul> 
     76        <li>The dashboard widget system now restores moved widgets, See <a href="http://trac2.assembla.com/backendpro/ticket/64">Bug #64</a></li> 
    7577        <li>The BackendPro tree menu in the admin panel now saves its open/closes status rather than it being lost between different pages, See Bugs <a href="http://trac2.assembla.com/backendpro/ticket/15">#15</a> and <a href="http://trac2.assembla.com/backendpro/ticket/45">#145</a></li> 
    7678        <li>Redirection upon login is now fixed, See <a href="http://trac2.assembla.com/backendpro/ticket/100">Bug #100</a></li> 
  • trunk/user_guide/upgrades/upgrade_050.html

    r187 r221  
    6565<p class="important"><strong>Note:</strong> If you have any custom developed files in these folders please make copies of them first. This may include customer user authentication and custom website preference forms.</p> 
    6666 
    67 <h3>Step 3: Upgrade the database</h3> 
     67<h3>Step 2: Upgrade the database</h3> 
    6868<p>Due to some changes between this version and the last you will needs to run some queries on your 
    6969database. Run the following queries seperatly on the database containing your BackendPro data</p> 
     
    7272</code> 
    7373  
    74 <h2>Step 2: Update your user guide</h2> 
     74<h3>Step 3: File System Changes</h3> 
     75<p>In this upgrade several files have been moved around so the old files can be removed. Details of changes are 
     76listed below:</p> 
     77<ul> 
     78        <li><strong>Dashboard Files</strong> - The dashboard files have now been moved to their own module. This is to tidy up 
     79        their file structure. This means <dfn>system/application/libraries/Dashboard.php</dfn>, <dfn>system/application/languages/english/dashboard_dashboard.php</dfn> 
     80        and <dfn>system/application/views/admin/dashboard/statistics.php</dfn> can be removed. If you have made any changes to these files you will want to relocate them to their 
     81        new respective files in <dfn>modules/dashboard/</dfn>. 
     82</ul> 
     83  
     84<h2>Step 4: Update your user guide</h2> 
    7585<p>Please replace your local copy of the user guide with the new version, including the image files.</p>  
    7686</div>