/themes/default/views/pages/settings/plugins.php

https://github.com/ushahidi/SwiftRiver · PHP · 103 lines · 86 code · 17 blank · 0 comment · 5 complexity · b9b3d4eecf83a82a1107c6426590a774 MD5 · raw file

  1. <?php echo Form::open(); ?>
  2. <input type="hidden" name="action" value="">
  3. <input type="hidden" name="id" value="">
  4. <div class="settings-toolbar"></div>
  5. <?php echo Form::close(); ?>
  6. <script type="text/template" id="plugin_item_template">
  7. <header class="cf">
  8. <div class="actions">
  9. <% if (plugin_enabled && plugin_settings) { %>
  10. <p class="button-blue button-small">
  11. <a href="<?php echo URL::site('settings')?>/<%= plugin_path %>">Settings</a>
  12. </p>
  13. <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
  14. <% } %>
  15. <% var link_title = (plugin_enabled)
  16. ? "<?php echo __('deactivated plugin'); ?>"
  17. : "<?php echo __('activated plugin'); ?>";
  18. var selected = (plugin_enabled)? "selected" : "";
  19. %>
  20. <a href="#" title="<%= link_title %>" class="<%= selected %>"><span class="icon-checkmark"></span><span class="nodisplay"><%= link_title %></span></a>
  21. </div>
  22. </header>
  23. <section class="property-parameters">
  24. <div class="parameter">
  25. <p><%= plugin_description %></p>
  26. </div>
  27. </section>
  28. </script>
  29. <script type="text/javascript">
  30. $(function() {
  31. var PluginItem = Backbone.Model.extend({
  32. toggleActivation: function(target) {
  33. this.save({
  34. plugin_enabled: this.get("plugin_enabled")? 0: 1
  35. },
  36. {
  37. wait: true,
  38. success: function(model, response) {
  39. if (model.get("plugin_enabled") == 1) {
  40. $(target).addClass("selected");
  41. } else {
  42. $(target).removeClass("selected");
  43. }
  44. }
  45. }
  46. )}
  47. });
  48. var PluginItemList = Backbone.Collection.extend({
  49. model: PluginItem
  50. });
  51. var PluginItemView = Backbone.View.extend({
  52. tagName: "article",
  53. className: "container base",
  54. template: _.template($("#plugin_item_template").html()),
  55. events: {
  56. "click .button-actions a": "toggleActivation"
  57. },
  58. toggleActivation: function(e) {
  59. targetEl = $(e.currentTarget);
  60. this.model.toggleActivation(targetEl);
  61. return false;
  62. },
  63. render: function() {
  64. this.$el.html(this.template(this.model.toJSON()));
  65. return this;
  66. }
  67. });
  68. var PluginsView = Backbone.View.extend({
  69. initialize: function() {
  70. this.plugins = new PluginItemList;
  71. this.plugins.on("reset", this.addPlugins, this);
  72. this.plugins.on("add", this.addPlugin, this);
  73. },
  74. addPlugin: function(plugin) {
  75. view = new PluginItemView({model: plugin}).render().el;
  76. $("div.settings-toolbar").after(view);
  77. },
  78. addPlugins: function() {
  79. this.plugins.each(this.addPlugin, this);
  80. }
  81. });
  82. var pluginsView = new PluginsView;
  83. pluginsView.plugins.url = "<?php echo $fetch_url; ?>";
  84. pluginsView.plugins.reset(<?php echo $plugins_list; ?>);
  85. });
  86. </script>