1 // ========================================================================== 2 // SC.pageItemView 3 // ========================================================================== 4 /*globals SC */ 5 6 /** 7 This View is used by Greenhouse when application is in design mode 8 Used for displaying page items 9 10 @extends SC.ListItemVIew 11 @author Mike Ball 12 13 */ 14 15 SC.pageItemView = SC.ListItemView.extend({ 16 isDropTarget: YES, 17 18 dragEntered: function(drag, evt) { 19 this.$().addClass('highlight'); 20 }, 21 22 dragExited: function(drag, evt) { 23 this.$().removeClass('highlight'); 24 25 }, 26 27 dragEnded: function(drag, evt) { 28 this.$().removeClass('highlight'); 29 30 }, 31 32 /** 33 Called when the drag needs to determine which drag operations are 34 valid in a given area. 35 36 Override this method to return an OR'd mask of the allowed drag 37 operations. If the user drags over a droppable area within another 38 droppable area, the drag will latch onto the deepest view that returns one 39 or more available operations. 40 41 The default implementation returns `SC.DRAG_NONE` 42 43 @param {SC.Drag} drag The current drag object 44 @param {SC.Event} evt The most recent mouse move event. Use to get 45 location 46 @returns {DragOps} A mask of all the drag operations allowed or 47 SC.DRAG_NONE 48 */ 49 computeDragOperations: function(drag, evt) { 50 if(drag.hasDataType('SC.Binding')){ 51 return SC.DRAG_LINK; 52 } 53 return SC.DRAG_NONE; 54 }, 55 56 /** 57 Called when the user releases the mouse. 58 59 This method gives your drop target one last opportunity to choose to 60 accept the proposed drop operation. You might use this method to 61 perform fine-grained checks on the drop location, for example. 62 Return true to accept the drop operation. 63 64 The default implementation returns `YES`. 65 66 @param {SC.Drag} drag The drag instance managing this drag 67 @param {DragOp} op The proposed drag operation. A drag constant 68 69 @return {Boolean} YES if operation is OK, NO to cancel. 70 */ 71 acceptDragOperation: function(drag, op) { return YES; }, 72 73 /** 74 Called to actually perform the drag operation. 75 76 Override this method to actually perform the drag operation. This method 77 is only called if you returned `YES` in `acceptDragOperation()`. 78 79 Return the operation that was actually performed or `SC.DRAG_NONE` if the 80 operation was aborted. 81 82 The default implementation returns `SC.DRAG_NONE` 83 84 @param {SC.Drag} drag The drag instance managing this drag 85 @param {DragOp} op The proposed drag operation. A drag constant. 86 87 @return {DragOp} Drag Operation actually performed 88 */ 89 performDragOperation: function(drag, op) { 90 var data = drag.dataForType('SC.Binding'), that = this; 91 if(data && SC._Greenhouse){ 92 var actionObj = SC.Object.create({ 93 type: 'Binding', 94 source: data, 95 target: that.get('content'), 96 addItem: function(from, to, designAttrs){ 97 var view = this.getPath('source'); 98 var value = that._propertyPathForProp(this.getPath('target.view.page'),this.getPath('target.view')); 99 view[from+"Binding"] = designAttrs[from+"Binding"] = value+"."+to; 100 view.propertyDidChange(from+"Binding"); 101 102 var designer = view.get('designer'); 103 if(designer){ 104 designer.designProperties.pushObject(from+"Binding"); 105 designer.propertyDidChange('editableProperties'); 106 } 107 if(view.displayDidChange) view.displayDidChange(); 108 } 109 }); 110 111 SC._Greenhouse.sendAction('newBindingPopup', actionObj); 112 113 return SC.DRAG_LINK; 114 } 115 else{ 116 return SC.DRAG_NONE; 117 } 118 }, 119 120 _propertyPathForProp: function(page, prop){ 121 for(var key in page){ 122 if(page.hasOwnProperty(key)){ 123 if(page[key] === prop) return page.get('pageName')+"."+key.toString(); 124 } 125 } 126 } 127 128 }); 129 130