timesheet source code
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

106 Zeilen
3.4KB

  1. (function ($) {
  2. $(function () {
  3. /*____________________________________________________________________________________*/
  4. class People{
  5. constructor(selector, data){
  6. this.selector = selector;
  7. this.data = data;
  8. this.template = '#people_template';
  9. // this.sample_people = {
  10. // login: '01515b52-6936-46b2-a000-9ad4cd7a5b50',
  11. // firstname: "first",
  12. // lastname: "last",
  13. // phone: '041122221',
  14. // email: 'abc@gmail.com',
  15. // pay: 0,
  16. // hour: 12,
  17. // OT: 3,
  18. // petrol: 50,
  19. // rating: 1,
  20. // };
  21. this.load_data(this.data);
  22. }
  23. load_data(data){
  24. var template = $(this.template).html();
  25. var html = Mustache.render(template, data);
  26. $(this.selector).html(html);
  27. //save it
  28. $(this.selector).data(data);
  29. //draw rating star
  30. this.set_ratings(this.data.rating);
  31. this.set_unconfirmed_job(this.data.unconfirmedjob);
  32. }
  33. set_ratings(num){
  34. for (var i=1; i<= 5; i++){
  35. if (i <=num){
  36. $(this.selector + " div[name='rating'] span:nth-child(" +i+ ")").addClass('checked');
  37. }else{
  38. $(this.selector + " div[name='rating'] span:nth-child(" +i+ ")").removeClass('checked');
  39. }
  40. }
  41. this.data.rating = num;
  42. }
  43. set_unconfirmed_job(num){
  44. if( num == 0 )
  45. $(this.selector + " span[name='badge']").hide();
  46. else
  47. $(this.selector + " span[name='badge']").show();
  48. this.data.unconfirmedjob = num;
  49. }
  50. }//end of class People
  51. function bts_people_html(data){
  52. var template = $('#people_template').html();
  53. var head = '<div class="peopleitem" id="p'+ data.login +'">';
  54. r = head + '</div>' ;
  55. return r;
  56. }
  57. function sample_staff(){
  58. for (var i=1; i<100; i++){
  59. var sample_people = {
  60. login: '01515b52-6936-46b2-a000-9ad4cd7a5b50' +i,
  61. firstname: "first"+i,
  62. lastname: "last",
  63. mobile: '041122221' +i,
  64. email: 'abc@gmail.com' + i,
  65. wages: 0,
  66. hour: i,
  67. OT: 3,
  68. petrol: 50 +i,
  69. rating: Math.floor(Math.random() * Math.floor(5)),
  70. unconfirmedjob: Math.floor(Math.random() * Math.floor(30)),
  71. };
  72. var html = bts_people_html(sample_people);
  73. jQuery('div.stafflist').append(html);
  74. new People("#p" + sample_people.login, sample_people);
  75. }
  76. }
  77. function list_staff() {
  78. $.post(bts().ajax_url, { // POST request
  79. _ajax_nonce: bts().nonce, // nonce
  80. action: "list_staff", // action
  81. }, function(response, status, xhr){
  82. if (response.status =='success'){
  83. response.staff.forEach(function(staff){
  84. var html = bts_people_html(staff);
  85. jQuery('div.stafflist').append(html);
  86. new People("#p" + staff.login, staff);
  87. });
  88. }else{
  89. alert('error getting staff list');
  90. }
  91. });
  92. }
  93. function init_ts(){
  94. list_staff();
  95. }
  96. init_ts();
  97. /*________________________________________________________________________*/
  98. });
  99. })(jQuery);