Commits

Anonymous committed 067a800

new widget and switched to a saner, django-staticfiles-friendly media path

Comments (0)

Files changed (6)

autocomplete/media/autocomplete/js/jquery_autocomplete.js

+function bassistance_autocomplete(name, ac_url, force_selection) {
+    $(document).ready(function () {
+        var input = $('#id_' + name);
+        var hidden_input = $('#id_hidden_' + name);
+        input.autocomplete(ac_url, {
+            limit: 10,
+            matchSubset: false,
+            dataType: 'json',
+            parse: function(data) {
+                var parsed = [];
+                for (var i in data) {
+                    row = {
+                        data: data[i][1]+'|'+data[i][0],
+                        value: data[i][0],
+                        result: data[i][1]
+                    };
+                    parsed[parsed.length] = row;
+                }
+                return parsed;
+            },    
+            formatItem: function(data, i, total) {
+                return data.split('|')[0];
+            }
+        });
+        input.result(function(event, data, formatted) {
+            hidden_input.val(data.split('|')[1]);
+        });
+        form = $("form:first");
+        form.submit(function() {
+            if (hidden_input.val() != input.val() && !force_selection) {
+                hidden_input.val(input.val());
+            }
+        });
+    });
+}
+
+
+function jquery_autocomplete(name, ac_url, force_selection) {
+
+    this.name = name;
+    this.ac_url = ac_url;
+    this.force_selection = force_selection;
+
+    this.source = function (request, response) {
+        function success(data) {
+            var parsed = [];
+            for (var i in data) {
+                parsed[parsed.length] = {
+                    id: data[i][0],
+                    value: data[i][1],
+                    label: data[i][1],
+                };
+            }
+            response(parsed);
+        };
+        $.ajax({
+            url: this.ac_url,
+            dataType: "json",
+            data: {q: request.term},
+            success: success
+        });
+    };
+
+    this.select = function (event, ui) {
+        // set the hidden input field.
+        this.last_item = ui.item;
+        this.hidden_input.val(ui.item.id);
+    };
+
+    this.close = function (event, ui) {
+        alert(ui.toSource());  
+    };
+
+    this.setup = function () {
+        this.input = $("#id_" + this.name);
+        this.hidden_input = $("#id_hidden_" + this.name);
+        this.last_item = {};
+        this.input.autocomplete({
+            // minLength: 2,
+            source: jQuery.proxy(this.source, this),
+            select: jQuery.proxy(this.select, this),
+        });
+        this.input.closest("form").submit(jQuery.proxy(function () {
+            if ((!this.input.val()) || (this.hidden_input.val() != this.input.val()
+                && !this.force_selection)) {
+                this.hidden_input.val(this.input.val());
+            }
+        }, this));
+        if (this.force_selection) {
+            this.input.focusout(jQuery.proxy(function (event) {
+                if (this.input.val() != this.last_item.value)
+                    this.input.val("");
+            }, this));
+        }
+    };
+
+    $(document).ready(jQuery.proxy(this.setup, this));
+};
+
+autocomplete = jquery_autocomplete;

autocomplete/media/autocomplete/js/jquery_ui_multiple_autocomplete.js

+function autocomplete(name, ac_url) {
+    this.name = name;
+    this.ac_url = ac_url;
+
+    this.source = function (request, response) {
+        $.getJSON(this.ac_url, {
+            term: request.term.split(/,\s*/).pop(),
+        }, response);
+    };
+
+    this.search = function() {
+        var term = this.input.val().split(/,\s*/).pop();
+	if (term.length < 2) {
+	    return false;
+	}
+    };
+
+    this.focus = function() {
+        return false;
+    };
+
+    this.select = function (event, ui) {
+        var terms = this.input.val().split(/,\s*/);
+	terms.pop();
+	terms.push(ui.item.value);
+	terms.push('');
+	this.input.val(terms.join(", "));
+        this.hidden_input.val(this.input.val());
+	return false;
+    };
+
+    this.setup = function () {
+        this.input = $("#id_" + this.name);
+        this.hidden_input = $("#id_hidden_" + this.name);
+
+        this.input.autocomplete({
+            source: jQuery.proxy(this.source, this),
+            select: jQuery.proxy(this.select, this),
+            search: jQuery.proxy(this.search, this),
+            focus: jQuery.proxy(this.focus, this)
+        });
+    };
+
+    $(document).ready(jQuery.proxy(this.setup, this));
+};

autocomplete/media/autocomplete/js/yui_autocomplete.js

+function yui_autocomplete(name, ac_url, force_selection) {
+
+    this.name = name;
+    this.ac_url = ac_url;
+    this.force_selection = force_selection;
+
+    this.setup = function () {
+        var datasource = new YAHOO.util.XHRDataSource(ac_url);
+        datasource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
+        datasource.responseSchema = {
+            resultsList: "result",
+            fields: ["label", "id"]
+        };
+
+        datasource.doBeforeParseData = function (request, original, callback) {
+            var parsed = {"result": []};
+            for (var i in original)
+                parsed.result.push({"id": original[i][0], "label": original[i][1]});
+            return parsed;
+        };
+        datasource.resultTypeList = false;
+
+        var input = document.getElementById("id_"+name);
+        var container = document.createElement("div");
+        YAHOO.util.Dom.insertAfter(container, input);
+        if (!YAHOO.util.Dom.hasClass(document.body, "yui-skin-sam"))
+            YAHOO.util.Dom.addClass(document.body, "yui-skin-sam");
+
+        var autocomplete = new YAHOO.widget.AutoComplete(input, container, datasource);
+        autocomplete.resultTypeList = false;
+        autocomplete.queryDelay = .5;
+        autocomplete.forceSelection = force_selection;
+        autocomplete.generateRequest = function(sQuery) {
+            return "?q="+sQuery;
+        };
+
+        var hidden = document.getElementById("id_hidden_"+name);
+        this.selected_item = {label: input.value, id: hidden.value};
+        autocomplete.itemSelectEvent.subscribe(function (type, args) {
+            this.selected_item = args[2];
+            hidden.value = this.selected_item.id;
+        });
+        form = document.getElementsByTagName("form")[0];
+        YAHOO.util.Event.addListener(form, "submit", function (event, form) {
+            if ((!input.value) || (this.selected_item.label != input.value && !force_selection))
+                hidden.value = input.value;
+        });
+        this.datasource = datasource;
+        this.autocomplete = autocomplete;
+    };
+    YAHOO.util.Event.onDOMReady(this.setup, null, this);
+};
+
+autocomplete = yui_autocomplete;

autocomplete/media/js/jquery_autocomplete.js

-function bassistance_autocomplete(name, ac_url, force_selection) {
-    $(document).ready(function () {
-        var input = $('#id_' + name);
-        var hidden_input = $('#id_hidden_' + name);
-        input.autocomplete(ac_url, {
-            limit: 10,
-            matchSubset: false,
-            dataType: 'json',
-            parse: function(data) {
-                var parsed = [];
-                for (var i in data) {
-                    row = {
-                        data: data[i][1]+'|'+data[i][0],
-                        value: data[i][0],
-                        result: data[i][1]
-                    };
-                    parsed[parsed.length] = row;
-                }
-                return parsed;
-            },    
-            formatItem: function(data, i, total) {
-                return data.split('|')[0];
-            }
-        });
-        input.result(function(event, data, formatted) {
-            hidden_input.val(data.split('|')[1]);
-        });
-        form = $("form:first");
-        form.submit(function() {
-            if (hidden_input.val() != input.val() && !force_selection) {
-                hidden_input.val(input.val());
-            }
-        });
-    });
-}
-
-
-function jquery_autocomplete(name, ac_url, force_selection) {
-
-    this.name = name;
-    this.ac_url = ac_url;
-    this.force_selection = force_selection;
-
-    this.source = function (request, response) {
-        function success(data) {
-            var parsed = [];
-            for (var i in data) {
-                parsed[parsed.length] = {
-                    id: data[i][0],
-                    value: data[i][1],
-                    label: data[i][1],
-                };
-            }
-            response(parsed);
-        };
-        $.ajax({
-            url: this.ac_url,
-            dataType: "json",
-            data: {q: request.term},
-            success: success
-        });
-    };
-
-    this.select = function (event, ui) {
-        // set the hidden input field.
-        this.last_item = ui.item;
-        this.hidden_input.val(ui.item.id);
-    };
-
-    this.close = function (event, ui) {
-        alert(ui.toSource());  
-    };
-
-    this.setup = function () {
-        this.input = $("#id_" + this.name);
-        this.hidden_input = $("#id_hidden_" + this.name);
-        this.last_item = {};
-        this.input.autocomplete({
-            // minLength: 2,
-            source: jQuery.proxy(this.source, this),
-            select: jQuery.proxy(this.select, this),
-        });
-        this.input.closest("form").submit(jQuery.proxy(function () {
-            if ((!this.input.val()) || (this.hidden_input.val() != this.input.val()
-                && !this.force_selection)) {
-                this.hidden_input.val(this.input.val());
-            }
-        }, this));
-        if (this.force_selection) {
-            this.input.focusout(jQuery.proxy(function (event) {
-                if (this.input.val() != this.last_item.value)
-                    this.input.val("");
-            }, this));
-        }
-    };
-
-    $(document).ready(jQuery.proxy(this.setup, this));
-};
-
-autocomplete = jquery_autocomplete;

autocomplete/media/js/yui_autocomplete.js

-function yui_autocomplete(name, ac_url, force_selection) {
-
-    this.name = name;
-    this.ac_url = ac_url;
-    this.force_selection = force_selection;
-
-    this.setup = function () {
-        var datasource = new YAHOO.util.XHRDataSource(ac_url);
-        datasource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
-        datasource.responseSchema = {
-            resultsList: "result",
-            fields: ["label", "id"]
-        };
-
-        datasource.doBeforeParseData = function (request, original, callback) {
-            var parsed = {"result": []};
-            for (var i in original)
-                parsed.result.push({"id": original[i][0], "label": original[i][1]});
-            return parsed;
-        };
-        datasource.resultTypeList = false;
-
-        var input = document.getElementById("id_"+name);
-        var container = document.createElement("div");
-        YAHOO.util.Dom.insertAfter(container, input);
-        if (!YAHOO.util.Dom.hasClass(document.body, "yui-skin-sam"))
-            YAHOO.util.Dom.addClass(document.body, "yui-skin-sam");
-
-        var autocomplete = new YAHOO.widget.AutoComplete(input, container, datasource);
-        autocomplete.resultTypeList = false;
-        autocomplete.queryDelay = .5;
-        autocomplete.forceSelection = force_selection;
-        autocomplete.generateRequest = function(sQuery) {
-            return "?q="+sQuery;
-        };
-
-        var hidden = document.getElementById("id_hidden_"+name);
-        this.selected_item = {label: input.value, id: hidden.value};
-        autocomplete.itemSelectEvent.subscribe(function (type, args) {
-            this.selected_item = args[2];
-            hidden.value = this.selected_item.id;
-        });
-        form = document.getElementsByTagName("form")[0];
-        YAHOO.util.Event.addListener(form, "submit", function (event, form) {
-            if ((!input.value) || (this.selected_item.label != input.value && !force_selection))
-                hidden.value = input.value;
-        });
-        this.datasource = datasource;
-        this.autocomplete = autocomplete;
-    };
-    YAHOO.util.Event.onDOMReady(this.setup, null, this);
-};
-
-autocomplete = yui_autocomplete;

autocomplete/widgets.py

               '&2.6.0/build/connection/connection-min.js'
               '&2.6.0/build/datasource/datasource-min.js'
               '&2.6.0/build/autocomplete/autocomplete-min.js',
-              'js/yui_autocomplete.js')
+              'autocomplete/js/yui_autocomplete.js')
 
     def __init__(self, ac_name, force_selection=True, reverse_label=True,
                  view=autocomplete, attrs=None):
             value = hidden_value = force_unicode(value)
         attrs = flatatt(self.build_attrs(attrs))
         return mark_safe(self.AC_TEMPLATE % locals())
+
+class JQueryUIMultipleAutoCompleteWidget(AutoCompleteWidget):
+    """
+    This widget uses JQuery served from Google AJAX CDN. It's meant to
+    be used in CharFields or TextFields.
+    """
+
+    class Media:
+        extend = False
+        css = {
+            'all': ('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css',),
+            }
+        js = (
+            'http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js',
+            'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js',
+            'autocomplete/js/jquery_ui_multiple_autocomplete.js',)
+    
+    def __init__(self, ac_name, force_selection=False, reverse_label=False,
+                 view=autocomplete, attrs={}):
+
+        attrs['style'] = 'width: 72.5%;';
+        super(JQueryUIMultipleAutoCompleteWidget, self).__init__(
+            ac_name,
+            force_selection=force_selection,
+            reverse_label=reverse_label,
+            view=view,
+            attrs=attrs)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.