Manage multiple screen parts and add home screen
Benjamin Renard

Benjamin Renard commited on 2014-01-12 19:11:40
Showing 2 changed files, with 79 additions and 4 deletions.

... ...
@@ -67,6 +67,57 @@ navbar_collapse_hide=function() {
67 67
   }
68 68
 }
69 69
 
70
+/****************
71
+ * Parts
72
+ ****************/
73
+
74
+view_part=function(part) {
75
+  $('.part').each(function(idx,div) {
76
+    $(div).css('display','none');
77
+  });
78
+  $(part).css('display','block');
79
+}
80
+
81
+view_home=function() {
82
+  if (user) {
83
+    $('#view-home #title').html('Bonjour '+user.name);
84
+  }
85
+  else {
86
+    $('#view-home #title').html('Bonjour');
87
+  }
88
+  if (groups.count()>0) {
89
+    tbody=$('#view-home #mybalances tbody');
90
+    tbody.html('');
91
+    balances=groups.balances();
92
+    var sum=0;
93
+    for (g in balances) {
94
+      if (jQuery.type(balances[g]['balance'][user.name])!='undefined') {
95
+        if (balances[g]['balance'][user.name]['diff']<0) {
96
+          sum+=balances[g]['balance'][user.name]['diff'];
97
+          diff='<td class="negative">'+balances[g]['balance'][user.name]['diff'].toFixed(2)+'</td>';
98
+        }
99
+        else {
100
+          value=balances[g]['balance'][user.name]['total']-balances[g]['min'];
101
+          sum+=value;
102
+          diff='<td class="positive">+'+value.toFixed(2)+' €</td>';
103
+        }
104
+        tbody.html(tbody.html()+'<tr><td>'+g+'</td>'+diff+'</tr>');
105
+      }
106
+    }
107
+    if (sum<0) {
108
+      $('#view-home #mybalances #total-value').html('<span class="negative">'+sum.toFixed(2)+' €</span>');
109
+    }
110
+    else {
111
+      $('#view-home #mybalances #total-value').html('<span class="positive">'+(sum==0?'':'+')+sum.toFixed(2)+' €</span>');
112
+    }
113
+    $('#view-home #mybalances').css('display','block');
114
+  }
115
+  else {
116
+    $('#view-home #mybalances').css('display','none');
117
+  }
118
+  view_part('#view-home');
119
+}
120
+
70 121
 /****************
71 122
  * View group
72 123
  ****************/
... ...
@@ -75,7 +126,7 @@ view_group=function(group) {
75 126
   $('#view-group #group_name')[0].value=group.name;
76 127
   set_contributors(group);
77 128
   on_contributor_change();
78
-  $('#view-group').css('display','block');
129
+  view_part('#view-group');
79 130
 }
80 131
 
81 132
 set_contributors=function(group) {
... ...
@@ -535,4 +586,5 @@ $( document ).ready( function() {
535 586
   $("#display_balance_btn").bind('click',on_display_balance_btn_click);
536 587
 
537 588
   $('#remove_group_btn').bind('click',on_remove_group_btn_click);
589
+  view_home();
538 590
 } );
... ...
@@ -37,11 +37,15 @@ body{
37 37
   font-weight: bold;
38 38
 }
39 39
 
40
-.late {
40
+.positive {
41
+  color: green;
42
+}
43
+
44
+.negative {
41 45
   color: red;
42 46
 }
43 47
 
44
-.hidden-part {
48
+.part {
45 49
   display: none;
46 50
 }
47 51
 
... ...
@@ -84,7 +88,26 @@ body{
84 88
     </div>
85 89
 <div class="container">
86 90
 
87
-<div id='view-group' class='part hidden-part'>
91
+<div id='view-home' class='part'>
92
+  <h1 id='title'></h1>
93
+  <table class="table table-striped" id='mybalances'>
94
+    <thead>
95
+      <tr>
96
+        <th>Groupe</th>
97
+        <th>Balance</th>
98
+      </tr>
99
+    </thead>
100
+    <tbody></tbody>
101
+    <tfoot>
102
+      <tr>
103
+        <td id='total-label'>Total :</td>
104
+        <td id='total-value'></td>
105
+      </tr>
106
+    </tfoot>
107
+  </table>
108
+</div>
109
+
110
+<div id='view-group' class='part'>
88 111
   <h1><span>Noël</span><small><span id='edit_group_btn' class='glyphicon glyphicon-edit btn btn-sm'></span></small></h1>
89 112
   <form class="form-horizontal" role="form">
90 113
     <input type='hidden' id='group_name' value='Noël'/>
91 114