dashboard.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * Author: Abdullah A Almsaeed
  3. * Date: 4 Jan 2014
  4. * Description:
  5. * This is a demo file used only for the main dashboard (index.html)
  6. **/
  7. $(function() {
  8. "use strict";
  9. //Make the dashboard widgets sortable Using jquery UI
  10. $(".connectedSortable").sortable({
  11. placeholder: "sort-highlight",
  12. connectWith: ".connectedSortable",
  13. handle: ".box-header, .nav-tabs",
  14. forcePlaceholderSize: true,
  15. zIndex: 999999
  16. }).disableSelection();
  17. $(".box-header, .nav-tabs").css("cursor","move");
  18. //jQuery UI sortable for the todo list
  19. $(".todo-list").sortable({
  20. placeholder: "sort-highlight",
  21. handle: ".handle",
  22. forcePlaceholderSize: true,
  23. zIndex: 999999
  24. }).disableSelection();;
  25. //bootstrap WYSIHTML5 - text editor
  26. $(".textarea").wysihtml5();
  27. $('.daterange').daterangepicker(
  28. {
  29. ranges: {
  30. 'Today': [moment(), moment()],
  31. 'Yesterday': [moment().subtract('days', 1), moment().subtract('days', 1)],
  32. 'Last 7 Days': [moment().subtract('days', 6), moment()],
  33. 'Last 30 Days': [moment().subtract('days', 29), moment()],
  34. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  35. 'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
  36. },
  37. startDate: moment().subtract('days', 29),
  38. endDate: moment()
  39. },
  40. function(start, end) {
  41. alert("You chose: " + start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
  42. });
  43. /* jQueryKnob */
  44. $(".knob").knob();
  45. //jvectormap data
  46. var visitorsData = {
  47. "US": 398, //USA
  48. "SA": 400, //Saudi Arabia
  49. "CA": 1000, //Canada
  50. "DE": 500, //Germany
  51. "FR": 760, //France
  52. "CN": 300, //China
  53. "AU": 700, //Australia
  54. "BR": 600, //Brazil
  55. "IN": 800, //India
  56. "GB": 320, //Great Britain
  57. "RU": 3000 //Russia
  58. };
  59. //World map by jvectormap
  60. $('#world-map').vectorMap({
  61. map: 'world_mill_en',
  62. backgroundColor: "#fff",
  63. regionStyle: {
  64. initial: {
  65. fill: '#e4e4e4',
  66. "fill-opacity": 1,
  67. stroke: 'none',
  68. "stroke-width": 0,
  69. "stroke-opacity": 1
  70. }
  71. },
  72. series: {
  73. regions: [{
  74. values: visitorsData,
  75. scale: ["#3c8dbc", "#2D79A6"], //['#3E5E6B', '#A6BAC2'],
  76. normalizeFunction: 'polynomial'
  77. }]
  78. },
  79. onRegionLabelShow: function(e, el, code) {
  80. if (typeof visitorsData[code] != "undefined")
  81. el.html(el.html() + ': ' + visitorsData[code] + ' new visitors');
  82. }
  83. });
  84. //Sparkline charts
  85. var myvalues = [15, 19, 20, -22, -33, 27, 31, 27, 19, 30, 21];
  86. $('#sparkline-1').sparkline(myvalues, {
  87. type: 'bar',
  88. barColor: '#00a65a',
  89. negBarColor: "#f56954",
  90. height: '20px'
  91. });
  92. myvalues = [15, 19, 20, 22, -2, -10, -7, 27, 19, 30, 21];
  93. $('#sparkline-2').sparkline(myvalues, {
  94. type: 'bar',
  95. barColor: '#00a65a',
  96. negBarColor: "#f56954",
  97. height: '20px'
  98. });
  99. myvalues = [15, -19, -20, 22, 33, 27, 31, 27, 19, 30, 21];
  100. $('#sparkline-3').sparkline(myvalues, {
  101. type: 'bar',
  102. barColor: '#00a65a',
  103. negBarColor: "#f56954",
  104. height: '20px'
  105. });
  106. myvalues = [15, 19, 20, 22, 33, -27, -31, 27, 19, 30, 21];
  107. $('#sparkline-4').sparkline(myvalues, {
  108. type: 'bar',
  109. barColor: '#00a65a',
  110. negBarColor: "#f56954",
  111. height: '20px'
  112. });
  113. myvalues = [15, 19, 20, 22, 33, 27, 31, -27, -19, 30, 21];
  114. $('#sparkline-5').sparkline(myvalues, {
  115. type: 'bar',
  116. barColor: '#00a65a',
  117. negBarColor: "#f56954",
  118. height: '20px'
  119. });
  120. myvalues = [15, 19, -20, 22, -13, 27, 31, 27, 19, 30, 21];
  121. $('#sparkline-6').sparkline(myvalues, {
  122. type: 'bar',
  123. barColor: '#00a65a',
  124. negBarColor: "#f56954",
  125. height: '20px'
  126. });
  127. //Date for the calendar events (dummy data)
  128. var date = new Date();
  129. var d = date.getDate(),
  130. m = date.getMonth(),
  131. y = date.getFullYear();
  132. //Calendar
  133. $('#calendar').fullCalendar({
  134. editable: true, //Enable drag and drop
  135. events: [
  136. {
  137. title: 'All Day Event',
  138. start: new Date(y, m, 1),
  139. backgroundColor: "#3c8dbc", //light-blue
  140. borderColor: "#3c8dbc" //light-blue
  141. },
  142. {
  143. title: 'Long Event',
  144. start: new Date(y, m, d - 5),
  145. end: new Date(y, m, d - 2),
  146. backgroundColor: "#f39c12", //yellow
  147. borderColor: "#f39c12" //yellow
  148. },
  149. {
  150. title: 'Meeting',
  151. start: new Date(y, m, d, 10, 30),
  152. allDay: false,
  153. backgroundColor: "#0073b7", //Blue
  154. borderColor: "#0073b7" //Blue
  155. },
  156. {
  157. title: 'Lunch',
  158. start: new Date(y, m, d, 12, 0),
  159. end: new Date(y, m, d, 14, 0),
  160. allDay: false,
  161. backgroundColor: "#00c0ef", //Info (aqua)
  162. borderColor: "#00c0ef" //Info (aqua)
  163. },
  164. {
  165. title: 'Birthday Party',
  166. start: new Date(y, m, d + 1, 19, 0),
  167. end: new Date(y, m, d + 1, 22, 30),
  168. allDay: false,
  169. backgroundColor: "#00a65a", //Success (green)
  170. borderColor: "#00a65a" //Success (green)
  171. },
  172. {
  173. title: 'Click for Google',
  174. start: new Date(y, m, 28),
  175. end: new Date(y, m, 29),
  176. url: 'http://google.com/',
  177. backgroundColor: "#f56954", //red
  178. borderColor: "#f56954" //red
  179. }
  180. ],
  181. buttonText: {//This is to add icons to the visible buttons
  182. prev: "<span class='fa fa-caret-left'></span>",
  183. next: "<span class='fa fa-caret-right'></span>",
  184. today: 'today',
  185. month: 'month',
  186. week: 'week',
  187. day: 'day'
  188. },
  189. header: {
  190. left: 'title',
  191. center: '',
  192. right: 'prev,next'
  193. }
  194. });
  195. //SLIMSCROLL FOR CHAT WIDGET
  196. $('#chat-box').slimScroll({
  197. height: '250px'
  198. });
  199. /* Morris.js Charts */
  200. // Sales chart
  201. var area = new Morris.Area({
  202. element: 'revenue-chart',
  203. resize: true,
  204. data: [
  205. {y: '2011 Q1', item1: 2666, item2: 2666},
  206. {y: '2011 Q2', item1: 2778, item2: 2294},
  207. {y: '2011 Q3', item1: 4912, item2: 1969},
  208. {y: '2011 Q4', item1: 3767, item2: 3597},
  209. {y: '2012 Q1', item1: 6810, item2: 1914},
  210. {y: '2012 Q2', item1: 5670, item2: 4293},
  211. {y: '2012 Q3', item1: 4820, item2: 3795},
  212. {y: '2012 Q4', item1: 15073, item2: 5967},
  213. {y: '2013 Q1', item1: 10687, item2: 4460},
  214. {y: '2013 Q2', item1: 8432, item2: 5713}
  215. ],
  216. xkey: 'y',
  217. ykeys: ['item1', 'item2'],
  218. labels: ['Item 1', 'Item 2'],
  219. lineColors: ['#a0d0e0', '#3c8dbc'],
  220. hideHover: 'auto'
  221. });
  222. //Donut Chart
  223. var donut = new Morris.Donut({
  224. element: 'sales-chart',
  225. resize: true,
  226. colors: ["#3c8dbc", "#f56954", "#00a65a"],
  227. data: [
  228. {label: "Download Sales", value: 12},
  229. {label: "In-Store Sales", value: 30},
  230. {label: "Mail-Order Sales", value: 20}
  231. ],
  232. hideHover: 'auto'
  233. });
  234. //Bar chart
  235. var bar = new Morris.Bar({
  236. element: 'bar-chart',
  237. resize: true,
  238. data: [
  239. {y: '2006', a: 100, b: 90},
  240. {y: '2007', a: 75, b: 65},
  241. {y: '2008', a: 50, b: 40},
  242. {y: '2009', a: 75, b: 65},
  243. {y: '2010', a: 50, b: 40},
  244. {y: '2011', a: 75, b: 65},
  245. {y: '2012', a: 100, b: 90}
  246. ],
  247. barColors: ['#00a65a', '#f56954'],
  248. xkey: 'y',
  249. ykeys: ['a', 'b'],
  250. labels: ['CPU', 'DISK'],
  251. hideHover: 'auto'
  252. });
  253. //Fix for charts under tabs
  254. $('.box ul.nav a').on('shown.bs.tab', function(e) {
  255. area.redraw();
  256. donut.redraw();
  257. });
  258. /* BOX REFRESH PLUGIN EXAMPLE (usage with morris charts) */
  259. $("#loading-example").boxRefresh({
  260. source: "ajax/dashboard-boxrefresh-demo.php",
  261. onLoadDone: function(box) {
  262. bar = new Morris.Bar({
  263. element: 'bar-chart',
  264. resize: true,
  265. data: [
  266. {y: '2006', a: 100, b: 90},
  267. {y: '2007', a: 75, b: 65},
  268. {y: '2008', a: 50, b: 40},
  269. {y: '2009', a: 75, b: 65},
  270. {y: '2010', a: 50, b: 40},
  271. {y: '2011', a: 75, b: 65},
  272. {y: '2012', a: 100, b: 90}
  273. ],
  274. barColors: ['#00a65a', '#f56954'],
  275. xkey: 'y',
  276. ykeys: ['a', 'b'],
  277. labels: ['CPU', 'DISK'],
  278. hideHover: 'auto'
  279. });
  280. }
  281. });
  282. /* The todo list plugin */
  283. $(".todo-list").todolist({
  284. onCheck: function(ele) {
  285. //console.log("The element has been checked")
  286. },
  287. onUncheck: function(ele) {
  288. //console.log("The element has been unchecked")
  289. }
  290. });
  291. });