timesheet source code
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

83 lines
2.5KB

  1. (function ($) {
  2. $(function () {
  3. class People{
  4. constructor(selector, data){
  5. this.selector = selector;
  6. this.data = data;
  7. this.template = '#people_template';
  8. // this.sample_people = {
  9. // login: '01515b52-6936-46b2-a000-9ad4cd7a5b50',
  10. // firstname: "first",
  11. // lastname: "last",
  12. // phone: '041122221',
  13. // email: 'abc@gmail.com',
  14. // pay: 0,
  15. // hour: 12,
  16. // OT: 3,
  17. // petrol: 50,
  18. // rating: 1,
  19. // };
  20. this.load_data(this.data);
  21. }
  22. load_data(data){
  23. var template = $(this.template).html();
  24. var html = Mustache.render(template, data);
  25. $(this.selector).html(html);
  26. //save it
  27. $(this.selector).data(data);
  28. //draw rating star
  29. this.set_ratings(this.data.rating);
  30. this.set_unconfirmed_job(this.data.unconfirmedjob);
  31. }
  32. set_ratings(num){
  33. for (var i=1; i<= 5; i++){
  34. if (i <=num){
  35. $(this.selector + " div[name='rating'] span:nth-child(" +i+ ")").addClass('checked');
  36. }else{
  37. $(this.selector + " div[name='rating'] span:nth-child(" +i+ ")").removeClass('checked');
  38. }
  39. }
  40. this.data.rating = num;
  41. }
  42. set_unconfirmed_job(num){
  43. if( num == 0 )
  44. $(this.selector + " span[name='badge']").hide();
  45. else
  46. $(this.selector + " span[name='badge']").show();
  47. this.data.unconfirmedjob = num;
  48. }
  49. }//end of class People
  50. function bts_people_html(data){
  51. var template = $('#people_template').html();
  52. var head = '<div class="peopleitem" id="p'+ data.login +'">';
  53. r = head + '</div>' ;
  54. return r;
  55. }
  56. for (var i=1; i<100; i++){
  57. var sample_people = {
  58. login: '01515b52-6936-46b2-a000-9ad4cd7a5b50' +i,
  59. firstname: "first"+i,
  60. lastname: "last",
  61. phone: '041122221' +i,
  62. email: 'abc@gmail.com' + i,
  63. wages: 0,
  64. hour: i,
  65. OT: 3,
  66. petrol: 50 +i,
  67. rating: Math.floor(Math.random() * Math.floor(5)),
  68. unconfirmedjob: Math.floor(Math.random() * Math.floor(30))
  69. };
  70. var html = bts_people_html(sample_people);
  71. jQuery('div.stafflist').append(html);
  72. new People("#p" + sample_people.login, sample_people);
  73. }
  74. });
  75. })(jQuery);