PageRenderTime 36ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Nancy/Diagnostics/Resources/Modules/interactive/methods.js

http://github.com/NancyFx/Nancy
JavaScript | 100 lines | 75 code | 25 blank | 0 comment | 2 complexity | c417e9503d2615e05fdca57eb845ade2 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-3.0, Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.0, BSD-3-Clause
  1. (function (Method) {
  2. var app = diagnostics.app;
  3. Method.Model = Backbone.Model.extend({});
  4. Method.Collection = Backbone.Collection.extend({
  5. model: Method.Model,
  6. initialize: function (opts) {
  7. this.providerName = opts.providerName;
  8. },
  9. url: function () {
  10. return Nancy.config.basePath + "interactive/providers/" + this.providerName;
  11. }
  12. });
  13. Method.Views.List = Backbone.View.extend({
  14. el: '#main',
  15. events: {
  16. 'click #back': 'back'
  17. },
  18. initialize: function () {
  19. this.router = app.router;
  20. this.template = $("#methodList").html();
  21. this.providerName = this.model.providerName;
  22. },
  23. render: function () {
  24. var methods = this.model.toJSON();
  25. var html = Handlebars.compile(this.template)({ collection: methods });
  26. $(this.el).html(html);
  27. _.each(methods, this.renderItem, this);
  28. },
  29. renderItem: function (model) {
  30. var itemView = new Method.Views.Item({ model: model, providerName: this.providerName });
  31. this.$('#root').append(itemView.el);
  32. },
  33. back: function () {
  34. this.router.navigate("", true);
  35. }
  36. });
  37. Method.Views.Item = Backbone.View.extend({
  38. tagName: 'li',
  39. events: {
  40. 'focus .method-argument input': 'showTooltip',
  41. 'blur .method-argument input': 'hideTooltip',
  42. 'click input[type=button]': 'executeMethod'
  43. },
  44. initialize: function (args) {
  45. this.providerName = args.providerName;
  46. this.app = app;
  47. this.router = app.router;
  48. this.template = $("#method").html();
  49. this.render();
  50. },
  51. render: function () {
  52. var html = Handlebars.compile(this.template)({ model: this.model });
  53. $(this.el).append(html);
  54. },
  55. showTooltip: function (e) {
  56. $(e.currentTarget).parent('.tooltip').addClass("tooltip-showing");
  57. },
  58. hideTooltip: function (e) {
  59. $(e.currentTarget).parent('.tooltip').removeClass("tooltip-showing");
  60. },
  61. executeMethod: function () {
  62. var parameters = this.$("input");
  63. var executionContext = {};
  64. executionContext.providerName = this.providerName;
  65. executionContext.methodName = this.model.methodName;
  66. executionContext.arguments = [];
  67. _.each(parameters, function (input) {
  68. if (input.type !== "submit" && input.type !== "button") {
  69. executionContext.arguments.push({ name: input.id, value: this.$(input).val() });
  70. }
  71. }, this);
  72. this.app.trigger("execute", executionContext);
  73. }
  74. });
  75. })(diagnostics.module("method"));