Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

handler.js 3.1 KiB

13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. return 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(arg && typeof arg!='string') arg = JSON.stringify(arg);
  35. args = {
  36. cmd:'runserverobj',
  37. args: arg,
  38. method: method
  39. };
  40. if(typeof doclist=='string')
  41. args.doctype = doclist;
  42. else
  43. args.docs = wn.model.compress(doclist)
  44. return wn.request.call({
  45. args: args,
  46. success: callback,
  47. btn: btn,
  48. freeze: freeze_msg,
  49. show_spinner: !no_spinner
  50. });
  51. }
  52. // For call a page metho
  53. function $c_page(module, page, method, arg, callback, no_spinner, freeze_msg, btn) {
  54. if(arg && typeof arg!='string') arg = JSON.stringify(arg);
  55. return wn.request.call({
  56. args: {
  57. cmd: module+'.page.'+page+'.'+page+'.'+method,
  58. arg: arg,
  59. method: method
  60. },
  61. success: callback,
  62. btn: btn,
  63. freeze: freeze_msg,
  64. show_spinner: !no_spinner
  65. });
  66. }
  67. // For calling an for output as csv
  68. function $c_obj_csv(doclist, method, arg) {
  69. // single
  70. var args = {}
  71. args.cmd = 'runserverobj';
  72. args.as_csv = 1;
  73. args.method = method;
  74. args.arg = arg;
  75. if(doclist.substr)
  76. args.doctype = doclist;
  77. else
  78. args.docs = wn.model.compress(doclist);
  79. // open
  80. open_url_post(wn.request.url, args);
  81. }
  82. // call a url as POST
  83. function open_url_post(URL, PARAMS, new_window) {
  84. var temp=document.createElement("form");
  85. temp.action=URL;
  86. temp.method="POST";
  87. temp.style.display="none";
  88. if(new_window){
  89. temp.target = '_blank';
  90. }
  91. for(var x in PARAMS) {
  92. var opt=document.createElement("textarea");
  93. opt.name=x;
  94. var val = PARAMS[x];
  95. if(typeof val!='string')
  96. val = JSON.stringify(val);
  97. opt.value=val;
  98. temp.appendChild(opt);
  99. }
  100. document.body.appendChild(temp);
  101. temp.submit();
  102. return temp;
  103. }