Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

13 роки тому
12 роки тому
13 роки тому
14 роки тому
13 роки тому
14 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. // short hand functions for setting up
  23. // rich text editor tinymce
  24. wn.tinymce = {
  25. add_simple: function(ele, height) {
  26. if(ele.myid) {
  27. tinyMCE.execCommand( 'mceAddControl', true, ele.myid);
  28. return;
  29. }
  30. // no create
  31. ele.myid = wn.dom.set_unique_id(ele);
  32. $(ele).tinymce({
  33. // Location of TinyMCE script
  34. script_url : 'js/lib/tiny_mce_3.5.7/tiny_mce.js',
  35. height: height ? height : '200px',
  36. // General options
  37. theme : "advanced",
  38. theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,outdent,indent,link,unlink,forecolor,backcolor,code,",
  39. theme_advanced_buttons2 : "",
  40. theme_advanced_buttons3 : "",
  41. theme_advanced_toolbar_location : "top",
  42. theme_advanced_toolbar_align : "left",
  43. theme_advanced_path : false,
  44. theme_advanced_resizing : false
  45. });
  46. },
  47. remove: function(ele) {
  48. tinyMCE.execCommand( 'mceRemoveControl', true, ele.myid);
  49. },
  50. get_value: function(ele) {
  51. return tinymce.get(ele.myid).getContent();
  52. }
  53. }
  54. wn.ele = {
  55. link: function(args) {
  56. var span = $a(args.parent, 'span', 'link_type', args.style);
  57. span.loading_img = $a(args.parent,'img','',{margin:'0px 4px -2px 4px', display:'none'});
  58. span.loading_img.src= 'lib/images/ui/button-load.gif';
  59. span.innerHTML = args.label;
  60. span.user_onclick = args.onclick;
  61. span.onclick = function() { if(!this.disabled) this.user_onclick(this); }
  62. // working
  63. span.set_working = function() {
  64. this.disabled = 1;
  65. $di(this.loading_img);
  66. }
  67. span.done_working = function() {
  68. this.disabled = 0;
  69. $dh(this.loading_img);
  70. }
  71. return span;
  72. }
  73. }
  74. function $ln(parent, label, onclick, style) {
  75. return wn.ele.link({parent:parent, label:label, onclick:onclick, style:style})
  76. }
  77. function $btn(parent, label, onclick, style, css_class, is_ajax) {
  78. if(css_class==='green') css_class='btn-info';
  79. return new wn.ui.Button(
  80. {parent:parent, label:label, onclick:onclick, style:style, is_ajax: is_ajax, css_class: css_class}
  81. ).btn;
  82. }
  83. // item (for tabs and triggers)
  84. // ====================================
  85. $item_normal = function(ele) {
  86. $y(ele, {padding:'6px 8px',cursor:'pointer',marginRight:'8px', whiteSpace:'nowrap',overflow:'hidden',borderBottom:'1px solid #DDD'});
  87. $bg(ele,'#FFF'); $fg(ele,'#000');
  88. }
  89. $item_active = function(ele) {
  90. $bg(ele,'#FE8'); $fg(ele,'#000');
  91. }
  92. $item_selected = function(ele) {
  93. $bg(ele,'#777'); $fg(ele,'#FFF');
  94. }
  95. $item_pressed = function(ele) {
  96. $bg(ele,'#F90'); $fg(ele,'#FFF');
  97. };
  98. // set out of 100
  99. function set_opacity(ele, ieop) {
  100. var op = ieop / 100;
  101. if (ele.filters) { // internet explorer
  102. try {
  103. ele.filters.item("DXImageTransform.Microsoft.Alpha").opacity = ieop;
  104. } catch (e) {
  105. ele.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ieop+')';
  106. }
  107. } else { // other browsers
  108. ele.style.opacity = op;
  109. }
  110. }
  111. // border radius
  112. // ====================================
  113. $br = function(ele, r, corners) {
  114. if(corners) {
  115. var cl = ['top-left', 'top-right', 'bottom-right' , 'bottom-left'];
  116. for(var i=0; i<4; i++) {
  117. if(corners[i]) {
  118. $(ele).css('-moz-border-radius-'+cl[i].replace('-',''),r).css('-webkit-'+cl[i]+'-border-radius',r);
  119. }
  120. }
  121. } else {
  122. $(ele).css('-moz-border-radius',r).css('-webkit-border-radius',r).css('border-radius',r);
  123. }
  124. }
  125. $bs = function(ele, r) { $(ele).css('-moz-box-shadow',r).css('-webkit-box-shadow',r).css('box-shadow',r); }
  126. // Select
  127. // ====================================
  128. function SelectWidget(parent, options, width, editable, bg_color) {
  129. var me = this;
  130. // native select
  131. this.inp = $a(parent, 'select');
  132. if(options) add_sel_options(this.inp, options);
  133. if(width) $y(this.inp, {width:width});
  134. this.set_width = function(w) { $y(this.inp, {width:w}) };
  135. this.set_options = function(o) { add_sel_options(this.inp, o); }
  136. this.inp.onchange = function() {
  137. if(me.onchange)me.onchange(this);
  138. }
  139. return;
  140. }
  141. function empty_select(s) {
  142. if(s.custom_select) { s.empty(); return; }
  143. if(s.inp)s = s.inp;
  144. if(s) {
  145. var tmplen = s.length; for(var i=0;i<tmplen; i++) s.options[0] = null;
  146. }
  147. }
  148. function sel_val(s) {
  149. if(s.custom_select) {
  150. return s.inp.value ? s.inp.value : '';
  151. }
  152. if(s.inp)s = s.inp;
  153. try {
  154. if(s.selectedIndex<s.options.length) return s.options[s.selectedIndex].value;
  155. else return '';
  156. } catch(err) { return ''; /* IE fix */ }
  157. }
  158. function add_sel_options(s, list, sel_val, o_style) {
  159. if(s.custom_select) {
  160. s.set_options(list)
  161. if(sel_val) s.inp.value = sel_val;
  162. return;
  163. }
  164. if(s.inp)s = s.inp;
  165. for(var i=0, len=list.length; i<len; i++) {
  166. var o = new Option(list[i], list[i], false, (list[i]==sel_val? true : false));
  167. if(o_style) $y(o, o_style);
  168. s.options[s.options.length] = o;
  169. }
  170. }
  171. var $n = '\n';
  172. function set_title(t) {
  173. document.title = (wn.title_prefix ? (wn.title_prefix + ' - ') : '') + t;
  174. }
  175. function $a(parent, newtag, className, cs, innerHTML, onclick) {
  176. if(parent && parent.substr)parent = $i(parent);
  177. var c = document.createElement(newtag);
  178. if(parent)
  179. parent.appendChild(c);
  180. // if image, 3rd parameter is source
  181. if(className) {
  182. if(newtag.toLowerCase()=='img')
  183. c.src = className
  184. else
  185. c.className = className;
  186. }
  187. if(cs)$y(c,cs);
  188. if(innerHTML) c.innerHTML = innerHTML;
  189. if(onclick) c.onclick = onclick;
  190. return c;
  191. }
  192. function $a_input(p, in_type, attributes, cs) {
  193. if(!attributes) attributes = {};
  194. var $input = $(p).append('<input type="'+ in_type +'">').find('input:last');
  195. for(key in attributes)
  196. $input.attr(key, attributes[key]);
  197. var input = $input.get(0);
  198. if(cs)
  199. $y(input,cs);
  200. return input;
  201. }
  202. function $dh(d) {
  203. if(d && d.substr)d=$i(d);
  204. if(d && d.style.display.toLowerCase() != 'none') d.style.display = 'none';
  205. }
  206. function $ds(d) {
  207. if(d && d.substr)d=$i(d);
  208. var t = 'block';
  209. if(d && in_list(['span','img','button'], d.tagName.toLowerCase()))
  210. t = 'inline'
  211. if(d && d.style.display.toLowerCase() != t)
  212. d.style.display = t;
  213. }
  214. function $di(d) { if(d && d.substr)d=$i(d); if(d)d.style.display = 'inline'; }
  215. function $i(id) {
  216. if(!id) return null;
  217. if(id && id.appendChild)return id; // already an element
  218. return document.getElementById(id);
  219. }
  220. function $w(e,w) { if(e && e.style && w)e.style.width = w; }
  221. function $h(e,h) { if(e && e.style && h)e.style.height = h; }
  222. function $bg(e,w) { if(e && e.style && w)e.style.backgroundColor = w; }
  223. function $y(ele, s) {
  224. if(ele && s) {
  225. for(var i in s) ele.style[i]=s[i];
  226. };
  227. return ele;
  228. }
  229. function $yt(tab, r, c, s) { /// set style on tables with wildcards
  230. var rmin = r; var rmax = r;
  231. if(r=='*') { rmin = 0; rmax = tab.rows.length-1; }
  232. if(r.search && r.search('-')!= -1) {
  233. r = r.split('-');
  234. rmin = cint(r[0]); rmax = cint(r[1]);
  235. }
  236. var cmin = c; var cmax = c;
  237. if(c=='*') { cmin = 0; cmax = tab.rows[0].cells.length-1; }
  238. if(c.search && c.search('-')!= -1) {
  239. c = c.split('-');
  240. rmin = cint(c[0]); rmax = cint(c[1]);
  241. }
  242. for(var ri = rmin; ri<=rmax; ri++) {
  243. for(var ci = cmin; ci<=cmax; ci++)
  244. $y($td(tab,ri,ci),s);
  245. }
  246. }
  247. // add css classes etc
  248. function set_style(txt) {
  249. wn.dom.set_style(txt);
  250. }
  251. // Make table
  252. function make_table(parent, nr, nc, table_width, widths, cell_style, table_style) {
  253. var t = $a(parent, 'table');
  254. t.style.borderCollapse = 'collapse';
  255. if(table_width) t.style.width = table_width;
  256. if(cell_style) t.cell_style=cell_style;
  257. for(var ri=0;ri<nr;ri++) {
  258. var r = t.insertRow(ri);
  259. for(var ci=0;ci<nc;ci++) {
  260. var c = r.insertCell(ci);
  261. if(ri==0 && widths && widths[ci]) {
  262. // set widths
  263. c.style.width = widths[ci];
  264. }
  265. if(cell_style) {
  266. for(var s in cell_style) c.style[s] = cell_style[s];
  267. }
  268. }
  269. }
  270. t.append_row = function() { return append_row(this); }
  271. if(table_style) $y(t, table_style);
  272. return t;
  273. }
  274. function append_row(t, at, style) {
  275. var r = t.insertRow(at ? at : t.rows.length);
  276. if(t.rows.length>1) {
  277. for(var i=0;i<t.rows[0].cells.length;i++) {
  278. var c = r.insertCell(i);
  279. if(style) $y(c, style);
  280. }
  281. }
  282. return r
  283. }
  284. function $td(t,r,c) {
  285. if(r<0)r=t.rows.length+r;
  286. if(c<0)c=t.rows[0].cells.length+c;
  287. return t.rows[r].cells[c];
  288. }
  289. // URL utilities
  290. wn.urllib = {
  291. // get argument from url
  292. get_arg: function(name) {
  293. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  294. var regexS = "[\\?&]"+name+"=([^&#]*)";
  295. var regex = new RegExp( regexS );
  296. var results = regex.exec( window.location.href );
  297. if( results == null )
  298. return "";
  299. else
  300. return decodeURIComponent(results[1]);
  301. },
  302. // returns url dictionary
  303. get_dict: function() {
  304. var d = {}
  305. var t = window.location.href.split('?')[1];
  306. if(!t) return d;
  307. if(t.indexOf('#')!=-1) t = t.split('#')[0];
  308. if(!t) return d;
  309. t = t.split('&');
  310. for(var i=0; i<t.length; i++) {
  311. var a = t[i].split('=');
  312. d[decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
  313. }
  314. return d;
  315. },
  316. // returns the base url with http + domain + path (-index.cgi or # or ?)
  317. get_base_url: function() {
  318. var url= window.location.href.split('#')[0].split('?')[0].split('app.html')[0];
  319. if(url.substr(url.length-1, 1)=='/') url = url.substr(0, url.length-1)
  320. return url
  321. },
  322. // return the relative http url for
  323. // a file upload / attachment
  324. // by file id / name
  325. get_file_url: function(file_id) {
  326. return repl('files/%(fn)s', {fn:file_id})
  327. }
  328. }
  329. get_url_arg = wn.urllib.get_arg;
  330. get_url_dict = wn.urllib.get_dict;