drupal-client
drupal-client copied to clipboard
Passing arguments to getView function
hello Joe,
Going really well here - just experimenting with a simple messaging functionality with OG and views.
i dont know if this is a bug or not, but i thought id post it here.
i have a view that im passing arguments to and the working and correct link is: http://drupal2-testdrupal.rhcloud.com/restapi/views/chats_details?args=27

when i pass the arguments from the calling function of the app like this:
var viewName = "chats_details"; var args = [27]; var headers = "";
drupal.getView_custom(viewName, args, function(response){ Ti.API.info(JSON.stringify(response) + " this is from within the calling function"); }, function (error) { Ti.API.info(JSON.stringify(error) + " this is error message from the calling function");}, headers); });
to the getView library function
function getView_custom(viewName, args, success, failure, headers) { makeAuthenticatedRequest({ servicePath:"views/" + viewName + ".json?" + encodeUrlString(args), httpMethod:'GET', contentType:"application/json"
}, function(response) {
success(response);
//Ti.API.info(response + " this is response from within the lib function");
}, function(error){
failure(response);
}, headers);
}
the output views array is empty. see the message log screenshots which shows http://drupal2-testdrupal.rhcloud.com/restapi/views/chats_details.json?0=27 as location (0 instead of the term "args").

i am using now a slightly modfified version of the getView function in the library to so that the service path looks like "servicePath:"views/" + viewName + ".json?args=" + args," and this works and the correct view shows up.
If you have a good general solution for improving getView, could you make a pull request?
hello Joe,
I am about to do more complex views with more arguments and see how this generally works out. can you assign this issue to me without giving me access rights? if not, ill try manually not to forget about posting the results here :)
hello Joe,
Finally i can go ahead with Titanium.
Im not sure if im using your library correctly and dont understand the encodeUrlString(args) function in the getView serviePath property.
i have set up two drupal views with one (uid) and two (uid + taxonomy term id) contextual filters coming from the URL (passed as arguments).
ive tried passing one argument for the contextual filter as args to the getView function in drupal.js like this:
//var args = "1"; // does not work - empty return, nothing logged
//var args = ["1"]; // does not work - empty return, nothing logged
//var args = "args=1"; // does not work - empty return, nothing logged
// var args = ["1"];
//var args = ["?args=1"];
nothing did it for me. For some reason the remote/service calls are not tracked in the message log anymore so i cant look into this. can you provide an example what the var args that you pass to getView looks like and that works for you?
i can pass the two arguments (userID stored in AppProperties and taxonomy term with ID 44) to views when i write it like this in the calling function:
var viewName = "multiple_arguments";
var uid = drupal.Settings.getInt("UserID");
var args = "?args[0]=" + uid + "&args[1]=44"; // two arguments for 2 contextual views filter
// var args = "?args=" + uid; // single argument
var headers ="";
drupal.getView_custom(viewName, args, function(response) {
listview (response);
}, function(error) {
}, headers);
};
the service path property in the getView function in drupal.js looks like this:
servicePath:"views/" + viewName + args + ".json",
now this is of course not a very elegant solution and im not even sure if i use your great library correctly so i thought i post this here.