You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

104 lines
2.8 KiB

  1. // Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
  2. //
  3. // MIT License (MIT)
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a
  6. // copy of this software and associated documentation files (the "Software"),
  7. // to deal in the Software without restriction, including without limitation
  8. // the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. // and/or sell copies of the Software, and to permit persons to whom the
  10. // Software is furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  17. // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  20. // OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. //
  22. function $c(command, args, callback, error, no_spinner, freeze_msg, btn) {
  23. wn.request.call({
  24. args: $.extend(args, {cmd: command}),
  25. success: callback,
  26. error: error,
  27. btn: btn,
  28. freeze: freeze_msg,
  29. show_spinner: !no_spinner
  30. })
  31. }
  32. // For calling an object
  33. function $c_obj(doclist, method, arg, callback, no_spinner, freeze_msg, btn) {
  34. if(typeof arg=='string') arg = JSON.stringify(arg);
  35. wn.request.call({
  36. args: {
  37. cmd:'runserverobj',
  38. arg: arg,
  39. method: method
  40. },
  41. success: callback,
  42. btn: btn,
  43. freeze: freeze_msg,
  44. show_spinner: !no_spinner
  45. });
  46. }
  47. // For call a page metho
  48. function $c_page(module, page, method, arg, callback, no_spinner, freeze_msg, btn) {
  49. if(typeof arg=='string') arg = JSON.stringify(arg);
  50. wn.request.call({
  51. args: {
  52. cmd: module+'.page.'+page+'.'+page+'.'+method,
  53. arg: arg,
  54. method: method
  55. },
  56. success: callback,
  57. error: error,
  58. btn: btn,
  59. freeze: freeze_msg,
  60. show_spinner: !no_spinner
  61. });
  62. }
  63. // For calling an for output as csv
  64. function $c_obj_csv(doclist, method, arg) {
  65. // single
  66. var args = {}
  67. args.cmd = 'runserverobj';
  68. args.as_csv = 1;
  69. args.method = method;
  70. args.arg = arg;
  71. if(doclist.substr)
  72. args.doctype = doclist;
  73. else
  74. args.docs = compress_doclist(doclist);
  75. // open
  76. open_url_post(outUrl, args);
  77. }
  78. // call a url as POST
  79. function open_url_post(URL, PARAMS, new_window) {
  80. var temp=document.createElement("form");
  81. temp.action=URL;
  82. temp.method="POST";
  83. temp.style.display="none";
  84. if(new_window){
  85. temp.target = '_blank';
  86. }
  87. for(var x in PARAMS) {
  88. var opt=document.createElement("textarea");
  89. opt.name=x;
  90. opt.value=PARAMS[x];
  91. temp.appendChild(opt);
  92. }
  93. document.body.appendChild(temp);
  94. temp.submit();
  95. return temp;
  96. }