summaryrefslogtreecommitdiffstats
path: root/funcweb
diff options
context:
space:
mode:
authormakkalot <makkalot@gmail.com>2008-08-06 01:12:51 +0300
committermakkalot <makkalot@gmail.com>2008-08-06 01:12:51 +0300
commit10feb6034a6965022867b9ce9234b60e60aba27e (patch)
tree309ce3f2cd8bf6eb295c8aea2138090cefe02d57 /funcweb
parentfc26441d78582cfb3bb23dd2f37f058a7788962b (diff)
downloadfunc-10feb6034a6965022867b9ce9234b60e60aba27e.tar.gz
func-10feb6034a6965022867b9ce9234b60e60aba27e.tar.xz
func-10feb6034a6965022867b9ce9234b60e60aba27e.zip
developing some global error handling in js side and also getting rid of the jquery we will use Mochikit for all js stuff from now :) sorry jquery fans
Diffstat (limited to 'funcweb')
-rw-r--r--funcweb/funcweb/static/javascript/utils.js122
1 files changed, 122 insertions, 0 deletions
diff --git a/funcweb/funcweb/static/javascript/utils.js b/funcweb/funcweb/static/javascript/utils.js
index aaa6c38..6029502 100644
--- a/funcweb/funcweb/static/javascript/utils.js
+++ b/funcweb/funcweb/static/javascript/utils.js
@@ -23,3 +23,125 @@ function checkController(class_name,check_element){
else
uncheck_all(class_name);
}
+
+/*
+ * Some ajaxian methods here (minion related stuff mostly !)
+ * These methods will replace the jquery and will let the Mochikit
+ * do all the stuff here !
+ */
+
+function list_minion_modules(minion_name){
+ /*
+ * Method that hanles all the stuff on index.html
+ * Therefore when you change something on index.html you should change
+ * that method also if it affects the related div ids below
+ */
+
+ //firstly do some hidings here
+ hideElement(getElement('resultcontent'));
+ hideElement(getElement('widgetcontent'));
+ hideElement(getElement('methotdscontent'));
+ hideElement(getElement('modulescontent'));
+ var base_url = '/funcweb/minion';
+ var data_pack = {'name':minion_name};
+ var div_to_replace = 'modulescontent';
+ //send the JSON request !
+ send_some_JSON(base_url,data_pack,div_to_replace);
+}
+
+function list_module_methods(minion_name,module_name){
+
+ //listing methods for specified module works for modules.html
+
+ hideElement(getElement('widgetcontent'));
+ hideElement(getElement('resultcontent'));
+ hideElement(getElement('methotdscontent'));
+ var base_url = '/funcweb/minion';
+ var data_pack = {
+ 'name':minion_name,
+ 'module':module_name
+ };
+ var div_to_replace = 'methotdscontent';
+ send_some_JSON(base_url,data_pack,div_to_replace);
+
+}
+
+function get_method_widget(minion_name,module_name,method_name){
+
+ // The method widget generator part works for methods.html
+
+ hideElement(getElement('resultcontent'));
+ hideElement(getElement('widgetcontent'));
+ var base_url = '/funcweb/method_display';
+ var data_pack = {
+ 'minion':minion_name,
+ 'module':module_name,
+ 'method':method_name
+ };
+ var div_to_replace = 'widgetcontent';
+ send_some_JSON(base_url,data_pack,div_to_replace);
+}
+
+function send_some_JSON(base_url,data_pack,div_to_replace){
+ /*
+ * A common method that will responsible for sending
+ * simple Http request to server !
+ */
+ var d = doSimpleXMLHttpRequest(base_url, data_pack);
+ //var d = loadJSONDoc(base_url+queryString(data_pack));
+ d.addCallback(replace_div_success,div_to_replace);
+ //The errback will be a common method here !
+ d.addErrback(connection_error);
+
+}
+
+function replace_div_success(div_to_replace,result){
+ /*
+ * The common callback for ajax requests
+ */
+
+ var server_text = result.responseText;
+ var is_error = true;
+ var check_error = null;
+
+ //Because we got a response text it may not be a json object we should control it
+ //we report the errors with tubogears tg_flash variable so the control below
+ //simply tries to convert the response into JSON doc and pull the tg_flash variable's
+ //value. If it is null it seems tobe a normal response !
+ try{
+ check_error = evalJSON(server_text);
+ }
+ catch(e){
+ //There is no error in request
+ is_error = false;
+ }
+
+ if (is_error == true){
+ if (compare(check_error['fg_flash'],null)!=0)
+ connection_error(check_error['tg_flash']);
+ else{
+ is_error = false;
+ alert("I marked it as non error");
+ }
+ }
+
+ if (is_error == false){
+ //Put the result into the target div
+ var replace_div = getElement(div_to_replace);
+ if (replace_div != null){
+ //first make it to appear here
+ showElement(replace_div);
+ replace_div.innerHTML = server_text;
+ }
+ }
+}
+
+function connection_error(error){
+ // The common errback method
+ var error_msg = "Async Request Error : You may try checking your connection and refresh your page! :" + repr(error);
+ alert("We got error in Async Request check the more detailed error report at the TOP of the page !");
+ var error_div = getElement("globalerror");
+ if (error_div != null){
+ error_div.innerHTML = error_msg;
+ }
+}