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.
 
 
 
 
 
 

46 lines
1.1 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. // MIT License. See license.txt
  3. wn.ui.Button = function(args) {
  4. var me = this;
  5. $.extend(this, {
  6. make: function() {
  7. me.btn = wn.dom.add(args.parent, 'button', 'btn ' + (args.css_class || 'btn-default'));
  8. me.btn.args = args;
  9. // ajax loading
  10. me.loading_img = wn.dom.add(me.btn.args.parent,'img','',{margin:'0px 4px -2px 4px', display:'none'});
  11. me.loading_img.src= 'assets/webnotes/images/ui/button-load.gif';
  12. // label
  13. me.btn.innerHTML = args.label;
  14. // onclick
  15. me.btn.user_onclick = args.onclick;
  16. $(me.btn).bind('click', function() {
  17. if(!this.disabled && this.user_onclick)
  18. this.user_onclick(this);
  19. })
  20. // bc
  21. me.btn.set_working = me.set_working;
  22. me.btn.done_working = me.done_working;
  23. // style
  24. if(me.btn.args.style)
  25. wn.dom.css(me.btn, args.style);
  26. },
  27. set_working: function() {
  28. me.btn.disabled = 'disabled';
  29. $(me.loading_img).css('display','inline');
  30. },
  31. done_working: function() {
  32. me.btn.disabled = false;
  33. $(me.loading_img).toggle(false);
  34. }
  35. });
  36. this.make();
  37. }