Guest User

Untitled

a guest
May 28th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. // ==========================================================================
  2. // Project: Inc.CheckboxListItemView
  3. // Copyright: ©2010 My Company, Inc.
  4. // ==========================================================================
  5. /*globals Inc */
  6.  
  7. /** @class
  8.  
  9. (Document Your View Here)
  10.  
  11. @extends SC.View
  12. */
  13. Inc.CheckboxListItemView = SC.ListItemView.extend(
  14. /** @scope Inventory.TagListItemView.prototype */ {
  15.  
  16. /**
  17. * You have to overwrite this to suit your needs
  18. */
  19. isChecked: function() {
  20. return NO;
  21. },
  22.  
  23. /**
  24. * Is called when the checkbox gets checked
  25. */
  26. check: function() { },
  27.  
  28. /**
  29. * Is called when the checkbox gets unchecked
  30. */
  31. uncheck: function() { },
  32.  
  33.  
  34. /**
  35. Fills the passed html-array with strings that can be joined to form the
  36. innerHTML of the receiver element. Also populates an array of classNames
  37. to set on the outer element.
  38. This implements some capability to handle the checkbox state.
  39.  
  40. @param {SC.RenderContext} context
  41. @param {Boolean} firstTime
  42. @returns {void}
  43. */
  44. render: function(context, firstTime) {
  45. var content = this.get('content'),
  46. del = this.displayDelegate,
  47. level = this.get('outlineLevel'),
  48. indent = this.get('outlineIndent'),
  49. key, value, working, classArray = [];
  50.  
  51. // add alternating row classes
  52. classArray.push((this.get('contentIndex')%2 === 0) ? 'even' : 'odd');
  53. context.setClass('disabled', !this.get('isEnabled'));
  54.  
  55. // outline level wrapper
  56. working = context.begin("div").addClass("sc-outline");
  57. if (level>=0 && indent>0) working.addStyle("left", indent*(level+1));
  58.  
  59. // handle disclosure triangle
  60. value = this.get('disclosureState');
  61. if (value !== SC.LEAF_NODE) {
  62. this.renderDisclosure(working, value);
  63. classArray.push('has-disclosure');
  64. }
  65.  
  66.  
  67. // handle checkbox
  68. // Always render checkbox
  69. this.renderCheckbox(working, this.get('isChecked'));
  70. classArray.push('has-checkbox');
  71.  
  72. // handle label -- always invoke
  73. key = this.getDelegateProperty('contentValueKey', del) ;
  74. value = (key && content) ? (content.get ? content.get(key) : content[key]) : content ;
  75. if (value && SC.typeOf(value) !== SC.T_STRING) value = value.toString();
  76. if (this.get('escapeHTML')) value = SC.RenderContext.escapeHTML(value);
  77. this.renderLabel(working, value);
  78.  
  79. // handle action
  80. key = this.getDelegateProperty('listItemActionProperty', del) ;
  81. value = (key && content) ? (content.get ? content.get(key) : content[key]) : null ;
  82. if (value) {
  83. this.renderAction(working, value);
  84. classArray.push('has-action');
  85. }
  86.  
  87. context.addClass(classArray);
  88. context = working.end();
  89. },
  90.  
  91. /** @private
  92. Returns YES if the list item has a checkbox and the event occurred
  93. inside of it.
  94. */
  95. _isInsideCheckbox: function(evt) {
  96. return this._isInsideElementWithClassName('sc-checkbox-view', evt);
  97. },
  98.  
  99. mouseUp: function(evt) {
  100. var ret= NO, del, checkboxKey, content, state, idx, set;
  101.  
  102. // if mouse was down in checkbox -- then handle mouse up, otherwise
  103. // allow parent view to handle event.
  104. if (this._isMouseDownOnCheckbox) {
  105.  
  106. // update only if mouse inside on mouse up...
  107. if (this._isInsideCheckbox(evt)) {
  108. del = this.displayDelegate ;
  109. checkboxKey = this.getDelegateProperty('contentCheckboxKey', del);
  110. content = this.get('content') ;
  111. if (content && content.get) {
  112. if (!this.get('isChecked')) {
  113. this.check();
  114. }
  115. else {
  116. this.uncheck();
  117. }
  118. this.displayDidChange(); // repaint view...
  119. }
  120. }
  121.  
  122. this._removeCheckboxActiveState() ;
  123. ret = YES ;
  124.  
  125. // if mouse as down on disclosure -- handle mosue up. otherwise pass on
  126. // to parent.
  127. } else if (this._isMouseDownOnDisclosure) {
  128. this._removeDisclosureActiveState();
  129. ret = YES ;
  130. // if mouse was down in right icon -- then handle mouse up, otherwise
  131. // allow parent view to handle event.
  132. } else if (this._isMouseDownOnRightIcon) {
  133. this._removeRightIconActiveState() ;
  134. ret = YES ;
  135. }
  136.  
  137. // clear cached info
  138. this._isMouseInsideCheckbox = this._isMouseDownOnCheckbox = NO ;
  139. this._isMouseDownOnDisclosure = this._isMouseInsideDisclosure = NO ;
  140. this._isMouseInsideRightIcon = this._isMouseDownOnRightIcon = NO ;
  141. return ret ;
  142. }
  143.  
  144. });
Add Comment
Please, Sign In to add comment