readonly.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @fileOverview
  3. *
  4. * 只读模式支持
  5. *
  6. * @author: techird
  7. * @copyright: Baidu FEX, 2014
  8. */
  9. define(function(require, exports, module) {
  10. var kity = require('./kity');
  11. var Minder = require('./minder');
  12. var MinderEvent = require('./event');
  13. Minder.registerInitHook(function(options) {
  14. if (options.readOnly) {
  15. this.setDisabled();
  16. }
  17. });
  18. kity.extendClass(Minder, {
  19. disable: function() {
  20. var me = this;
  21. //禁用命令
  22. me.bkqueryCommandState = me.queryCommandState;
  23. me.bkqueryCommandValue = me.queryCommandValue;
  24. me.queryCommandState = function(type) {
  25. var cmd = this._getCommand(type);
  26. if (cmd && cmd.enableReadOnly) {
  27. return me.bkqueryCommandState.apply(me, arguments);
  28. }
  29. return -1;
  30. };
  31. me.queryCommandValue = function(type) {
  32. var cmd = this._getCommand(type);
  33. if (cmd && cmd.enableReadOnly) {
  34. return me.bkqueryCommandValue.apply(me, arguments);
  35. }
  36. return null;
  37. };
  38. this.setStatus('readonly');
  39. me._interactChange();
  40. },
  41. enable: function() {
  42. var me = this;
  43. if (me.bkqueryCommandState) {
  44. me.queryCommandState = me.bkqueryCommandState;
  45. delete me.bkqueryCommandState;
  46. }
  47. if (me.bkqueryCommandValue) {
  48. me.queryCommandValue = me.bkqueryCommandValue;
  49. delete me.bkqueryCommandValue;
  50. }
  51. this.setStatus('normal');
  52. me._interactChange();
  53. }
  54. });
  55. });