3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js">Ext.onReady(function(){
\r
10 Ext.QuickTips.init();
\r
13 var tb = new Ext.Toolbar({
\r
16 iconCls: 'album-btn',
\r
17 handler: function(){
\r
18 var node = root.appendChild(new Ext.tree.TreeNode({
\r
19 text:'Album ' + (++newIndex),
\r
23 tree.getSelectionModel().select(node);
\r
24 setTimeout(function(){
\r
26 ge.startEdit(node.ui.textNode);
\r
32 // set up the Album tree
\r
33 var tree = new Ext.tree.TreePanel({
\r
37 containerScroll: true,
\r
38 ddGroup: 'organizerDD',
\r
51 var root = new Ext.tree.TreeNode({
\r
56 tree.setRootNode(root);
\r
59 new Ext.tree.TreeNode({text:'Album 1', cls:'album-node', allowDrag:false}),
\r
60 new Ext.tree.TreeNode({text:'Album 2', cls:'album-node', allowDrag:false}),
\r
61 new Ext.tree.TreeNode({text:'Album 3', cls:'album-node', allowDrag:false})
\r
64 // add an inline editor for the nodes
\r
65 var ge = new Ext.tree.TreeEditor(tree, {/* fieldconfig here */ }, {
\r
67 blankText:'A name is required',
\r
71 // Set up images view
\r
73 var view = new Ext.DataView({
\r
74 itemSelector: 'div.thumb-wrap',
\r
75 style:'overflow:auto',
\r
77 plugins: new Ext.DataView.DragSelector({dragSafe:true}),
\r
78 store: new Ext.data.JsonStore({
\r
79 url: '../view/get-images.php',
\r
85 {name: 'shortName', mapping: 'name', convert: shortName}
\r
88 tpl: new Ext.XTemplate(
\r
90 '<div class="thumb-wrap" id="{name}">',
\r
91 '<div class="thumb"><img src="../view/{url}" class="thumb-img"></div>',
\r
92 '<span>{shortName}</span></div>',
\r
97 var images = new Ext.Panel({
\r
101 margins: '5 5 5 0',
\r
107 var layout = new Ext.Panel({
\r
111 items: [tree, images]
\r
114 layout.render('layout');
\r
116 var dragZone = new ImageDragZone(view, {containerScroll:true,
\r
117 ddGroup: 'organizerDD'});
\r
122 <div id="method-App.user.FormPanel-ImageDragZone"></div>/**
\r
123 * Create a DragZone instance for our JsonView
\r
125 ImageDragZone = function(view, config){
\r
127 ImageDragZone.superclass.constructor.call(this, view.getEl(), config);
\r
129 Ext.extend(ImageDragZone, Ext.dd.DragZone, {
\r
130 // We don't want to register our image elements, so let's
\r
131 // override the default registry lookup to fetch the image
\r
132 // from the event instead
\r
133 getDragData : function(e){
\r
134 var target = e.getTarget('.thumb-wrap');
\r
136 var view = this.view;
\r
137 if(!view.isSelected(target)){
\r
140 var selNodes = view.getSelectedNodes();
\r
144 if(selNodes.length == 1){
\r
145 dragData.ddel = target;
\r
146 dragData.single = true;
\r
148 var div = document.createElement('div'); // create the multi element drag "ghost"
\r
149 div.className = 'multi-proxy';
\r
150 for(var i = 0, len = selNodes.length; i < len; i++){
\r
151 div.appendChild(selNodes[i].firstChild.firstChild.cloneNode(true)); // image nodes only
\r
152 if((i+1) % 3 == 0){
\r
153 div.appendChild(document.createElement('br'));
\r
156 var count = document.createElement('div'); // selected image count
\r
157 count.innerHTML = i + ' images selected';
\r
158 div.appendChild(count);
\r
160 dragData.ddel = div;
\r
161 dragData.multi = true;
\r
168 // this method is called by the TreeDropZone after a node drop
\r
169 // to get the new tree node (there are also other way, but this is easiest)
\r
170 getTreeNode : function(){
\r
171 var treeNodes = [];
\r
172 var nodeData = this.view.getRecords(this.dragData.nodes);
\r
173 for(var i = 0, len = nodeData.length; i < len; i++){
\r
174 var data = nodeData[i].data;
\r
175 treeNodes.push(new Ext.tree.TreeNode({
\r
177 icon: '../view/'+data.url,
\r
186 // the default action is to "highlight" after a bad drop
\r
187 // but since an image can't be highlighted, let's frame it
\r
188 afterRepair:function(){
\r
189 for(var i = 0, len = this.dragData.nodes.length; i < len; i++){
\r
190 Ext.fly(this.dragData.nodes[i]).frame('#8db2e3', 1);
\r
192 this.dragging = false;
\r
195 // override the default repairXY with one offset for the margins and padding
\r
196 getRepairXY : function(e){
\r
197 if(!this.dragData.multi){
\r
198 var xy = Ext.Element.fly(this.dragData.ddel).getXY();
\r
206 // Utility functions
\r
208 function shortName(name){
\r
209 if(name.length > 15){
\r
210 return name.substr(0, 12) + '...';
\r