api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
Ви не можете вибрати більше 25 тем Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client_handlebars_compiled.html 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <html>
  2. <head>
  3. <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.runtime.js"></script>
  4. <script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.1.6/zepto.min.js"></script>
  5. <script src="../lib/php_crud_api_transform.js"></script>
  6. <script>
  7. var PostListTemplate = {"1":function(container,depth0,helpers,partials,data) {
  8. var helper;
  9. return " <li>\n <span class=\"id\">"
  10. + container.escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"id","hash":{},"data":data}) : helper)))
  11. + "</span>, <span class=\"content\">"
  12. + container.escapeExpression(((helper = (helper = helpers.content || (depth0 != null ? depth0.content : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},{"name":"content","hash":{},"data":data}) : helper)))
  13. + "</span>\n <a href=\"javascript:void(0)\" class=\"edit\">edit</a>\n <a href=\"javascript:void(0)\" class=\"delete\">del</a>\n </li>\n";
  14. },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
  15. var stack1, helper, options, buffer =
  16. "\n<ul>\n";
  17. stack1 = ((helper = (helper = helpers.posts || (depth0 != null ? depth0.posts : depth0)) != null ? helper : helpers.helperMissing),(options={"name":"posts","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data}),(typeof helper === "function" ? helper.call(depth0 != null ? depth0 : {},options) : helper));
  18. if (!helpers.posts) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
  19. if (stack1 != null) { buffer += stack1; }
  20. return buffer + " <li>\n <form>\n <input name=\"content\"/>\n </form>\n </li>\n</ul>\n";
  21. },"useData":true}
  22. </script>
  23. <script>
  24. function PostList(element, template) {
  25. var self = this;
  26. var url = '../api.php/posts';
  27. self.edit = function() {
  28. var li = $(this).parent('li');
  29. var id = li.find('span.id').text();
  30. var content = li.find('span.content').text();
  31. content = prompt('Value',content);
  32. if (content!==null) {
  33. $.ajax({url:url+'/'+id, type: 'PUT', data: {content:content}, success:self.update});
  34. }
  35. };
  36. self.delete = function() {
  37. var li = $(this).parent('li');
  38. var id = li.find('span.id').text();
  39. if (confirm("Deleting #"+id+". Continue?")) {
  40. $.ajax({url:url+'/'+id, type: 'DELETE', success:self.update});
  41. }
  42. };
  43. self.submit = function(e) {
  44. e.preventDefault();
  45. var content = $(this).find('input[name="content"]').val();
  46. $.post(url, {user_id:1,category_id:1,content:content}, self.update);
  47. };
  48. self.render = function(data) {
  49. element.html(Handlebars.template(PostListTemplate)(php_crud_api_transform(data)));
  50. };
  51. self.update = function() {
  52. $.get(url, self.render);
  53. };
  54. self.post = function() {
  55. $.post(url, {user_id:1,category_id:1,content:"from handlebars_compiled"}, self.update);
  56. };
  57. element.on('submit','form',self.submit);
  58. element.on('click','a.edit',self.edit)
  59. element.on('click','a.delete',self.delete)
  60. self.post();
  61. };
  62. $(function(){ new PostList($('#PostListDiv'),$('#PostListTemplate')); });
  63. </script>
  64. </head>
  65. <body>
  66. <div id="PostListDiv">Loading...</div>
  67. </body>
  68. </html>