dojo.provide("autocompletion");
dojo.require("dojox.data.QueryReadStore");
dojo.declare(
    "autocompletion",
    dojox.data.QueryReadStore, {
        fetch:function(request){
            if (request.query.id){
                request.serverQuery={
                    id:request.query.id.replace("*",""),
                    limit:request.count,
                    offset:request.start
                };
            } else {
                request.serverQuery={
                    match:request.query.description,
                    limit:request.count,
                    offset:request.start
                };
            }

            
            /*console.log("here");
            console.log(request);
            console.log(request.query);
            console.log(request.serverQuery);*/
            return this.inherited(arguments);
        }
    }
    
);

function ac_parent_set_value(widget, value) {
    if (value){
    node=widget.domNode.parentNode;

    console.log(dojo.query('.rum-autocompletion-set-value-here', node));
   /* dojo.query('.rum-autocompletion-set-value-here', node).forEach(
        function(input_node,i){
            console.log(input_node);
            dojo._destroyElement(input_node);
            //dojo.attr(input_node,"value",value);
        }
    );*/
    dojo.query('.rum-autocompletion-set-value-here', node).forEach(
        function(input_node,i){
            dojox.data.dom.removeChildren(input_node);
            dojo.place(document.createTextNode(value), input_node, "last");
            //dojo.attr(input_node,"value",value);
        }
    );
}
}