From: Jordan Augé Date: Thu, 8 Aug 2013 10:17:25 +0000 (+0200) Subject: plugins: reworked the framework using inheritance + added active_filters X-Git-Tag: myslice-0.2-1~71 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=a953233a34580bc72aa8b6b03c017ff94f9eee7d plugins: reworked the framework using inheritance + added active_filters --- diff --git a/manifold/js/class.js b/manifold/js/class.js new file mode 100644 index 00000000..63b570c3 --- /dev/null +++ b/manifold/js/class.js @@ -0,0 +1,64 @@ +/* Simple JavaScript Inheritance + * By John Resig http://ejohn.org/ + * MIT Licensed. + */ +// Inspired by base2 and Prototype +(function(){ + var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; + + // The base Class implementation (does nothing) + this.Class = function(){}; + + // Create a new Class that inherits from this class + Class.extend = function(prop) { + var _super = this.prototype; + + // Instantiate a base class (but only create the instance, + // don't run the init constructor) + initializing = true; + var prototype = new this(); + initializing = false; + + // Copy the properties over onto the new prototype + for (var name in prop) { + // Check if we're overwriting an existing function + prototype[name] = typeof prop[name] == "function" && + typeof _super[name] == "function" && fnTest.test(prop[name]) ? + (function(name, fn){ + return function() { + var tmp = this._super; + + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; + + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; + + return ret; + }; + })(name, prop[name]) : + prop[name]; + } + + // The dummy class constructor + function Class() { + // All construction is actually done in the init method + if ( !initializing && this.init ) + this.init.apply(this, arguments); + } + + // Populate our constructed prototype object + Class.prototype = prototype; + + // Enforce the constructor to be what we expect + Class.prototype.constructor = Class; + + // And make this class extendable + Class.extend = arguments.callee; + + return Class; + }; +})(); diff --git a/manifold/js/manifold.js b/manifold/js/manifold.js index ef492f71..01c55310 100644 --- a/manifold/js/manifold.js +++ b/manifold/js/manifold.js @@ -440,12 +440,6 @@ var manifold = { // XXX When is an update query associated ? // XXX main_update_query.select(value); - // We need to inform about changes in these queries to the respective plugins - // Note: query, main_query & update_query have the same UUID - manifold.raise_query_event(query_uuid, event_type, value); - // We are targeting the same object with get and update - // The notion of query is bad, we should have a notion of destination, and issue queries on the destination - // NOTE: Editing a subquery == editing a local view on the destination break; case FIELD_REMOVED: @@ -460,6 +454,13 @@ var manifold = { manifold.raise_query_event(query_uuid, event_type, value); break; } + // We need to inform about changes in these queries to the respective plugins + // Note: query, main_query & update_query have the same UUID + manifold.raise_query_event(query_uuid, event_type, value); + // We are targeting the same object with get and update + // The notion of query is bad, we should have a notion of destination, and issue queries on the destination + // NOTE: Editing a subquery == editing a local view on the destination + // XXX We might need to run the new query again and manage the plugins in the meantime with spinners... // For the time being, we will collect all columns during the first query }, diff --git a/manifold/js/plugin-sample.html b/manifold/js/plugin-sample.html new file mode 100644 index 00000000..975270ff --- /dev/null +++ b/manifold/js/plugin-sample.html @@ -0,0 +1,103 @@ + + + + + Extensible jQuery + + + + + +{{ header_prelude }} +{% block head %} {% endblock head %} +{# let's add these ones no matter what #} +{# not yet needed {% insert_str prelude "css/layout-unfold1.css" %} #} +{% insert_str prelude "js/jquery.min.js" %} +{% insert_str prelude "js/jquery.html5storage.min.js" %} +{% insert_str prelude "js/messages-runtime.js" %} +{% insert_str prelude "js/class.js" %} +{% insert_str prelude "js/plugin_helper.js" %} +{% insert_str prelude "js/plugin.js" %} +{% insert_str prelude "js/manifold.js" %} + +{% block container %} +
+ {% block topmenu %} + {% include 'widget-topmenu.html' %} + {% endblock topmenu %} +{% include 'messages.html' %} +
+
+ + {% block base_content%}{% endblock %} + +
+
+{% endblock container %} + + diff --git a/views/templates/layout-unfold1.html b/views/templates/layout-unfold1.html index ba1c01bd..851de44b 100644 --- a/views/templates/layout-unfold1.html +++ b/views/templates/layout-unfold1.html @@ -1,35 +1,9 @@ -{# This is required by insert_above #}{% insert_handler %} - - MySlice - {{ title }} - -{# This is where insert_str will end up #}{% media_container prelude %} -{% include 'messages-header.html' %} - - -{{ header_prelude }} -{% block head %} {% endblock head %} -{# let's add these ones no matter what #} -{# not yet needed {% insert_str prelude "css/layout-unfold1.css" %} #} -{% insert_str prelude "js/jquery.min.js" %} -{% insert_str prelude "js/jquery.html5storage.min.js" %} -{% insert_str prelude "js/messages-runtime.js" %} -{% insert_str prelude "js/plugin.js" %} - -{% block container %} -
- {% block topmenu %} - {% include 'widget-topmenu.html' %} - {% endblock topmenu %} -{% include 'messages.html' %} -
-
+{% extends "base.html" %} + +{% block base_content %}
{% block unfold1_main %} "The main content area (define block 'unfold1_main')" {% endblock unfold1_main %}
-
-
-{% endblock container %} - - +{% endblock %} diff --git a/views/templates/layout-unfold2.html b/views/templates/layout-unfold2.html index b107b552..4754fa1c 100644 --- a/views/templates/layout-unfold2.html +++ b/views/templates/layout-unfold2.html @@ -1,25 +1,6 @@ -{# This is required by insert_above #}{% insert_handler %} - - MySlice - {{ title }} - -{# This is where insert_str will end up #}{% media_container prelude %} - - -{{ header_prelude }} -{# let's add these ones no matter what #} -{% insert_str prelude "css/layout-unfold2.css" %} -{% insert_str prelude "js/jquery.min.js" %} -{% insert_str prelude "js/jquery.html5storage.min.js" %} -{% insert_str prelude "js/messages-runtime.js" %} -{% insert_str prelude "js/plugin.js" %} - -{% block container %} -
- {% block topmenu %} - {% include 'widget-topmenu.html' %} - {% endblock topmenu %} -
-
+{% extends "base.html" %} + +{% block base_content %}
{% block unfold2_main %} "The main content area (define block 'unfold2_main')" @@ -30,8 +11,4 @@ "The related content area (define block 'related_main')" {% endblock unfold2_margin %}
-
-
-{% endblock container %} - - +{% endblock %}