corrade-nucleus-nucleons – Diff between revs 15 and 16

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 15 Rev 16
Line 285... Line 285...
285 }, 285 },
286 'dnd': { 286 'dnd': {
287 // Do not copy items. 287 // Do not copy items.
288 'copy': false, 288 'copy': false,
289 // Do not execute the check callback whilst dragging. 289 // Do not execute the check callback whilst dragging.
290 'check_while_dragging': false 290 'check_while_dragging': true
291 }, 291 },
292 'sort': function(a, b) { 292 'sort': function(a, b) {
293 return Date.parse(this.get_node(a).data.time) < -  
294 Date.parse(this.get_node(b).data.time) ? 1 : -1; 293 return this.get_node(a).data.time < this.get_node(b).data.time ? 1 : -1;
295 }, 294 },
296 'core': { 295 'core': {
297 'check_callback': function(operation, node, parent, position, more) { 296 'check_callback': function(operation, node, parent, position, more) {
-   297 // Only allow move operations
-   298 if (operation !== 'move_node' ||
-   299 // Do not move system folders.
-   300 node.data.system !== false ||
298 // Do not allow moves above the root node. 301 // Do not allow moves above the root node.
299 if (parent.id === "#") 302 parent.id === "#" ||
-   303 // Do not allow moving an item over another item.
-   304 (node.data.type !== 'folder' && parent.data.type !== 'folder'))
300 return false; 305 return false;
Line 301... Line 306...
301 306
302 var source = node.id; 307 var source = node.id;
Line 308... Line 313...
308 313
309 if(target === '#') 314 if(target === '#')
Line 310... Line 315...
310 target = '/'; 315 target = '/';
311 316
Line 312... Line 317...
312 if(source == '/' && target == '/') 317 if(source == '/' && target == '/')
313 return; 318 return false;
314 319
315 // Check if source path is sane. 320 // Check if source path is sane.
316 if(source.split('/').some( 321 if(source.split('/').some(
317 function(part) { 322 function(part) {
318 return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/.test(part); 323 return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/.test(part);
Line 319... Line 324...
319 })) { 324 })) {
320 return; 325 return false;
321 } 326 }
322 327
323 // Check if target path is sane. 328 // Check if target path is sane.
324 if(target.split('/').some( -  
325 function(part) { -  
326 return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/.test(part); -  
327 })) { -  
328 return; -  
329 } -  
330 -  
331 // Check that the source and target items are not system folders. -  
332 var data = {}; -  
333 [ { type: 'source', value: source }, -  
334 { type: 'target', value: target }].forEach(function(e) { -  
335 $.ajax({ -  
336 //async: false, -  
337 type: 'POST', -  
338 url: '/', -  
339 dataType: 'json', -  
340 async: false, -  
341 data: { -  
342 command: 'getinventorydata', -  
343 item: e.value, -  
344 data: wasArrayToCSV([ -  
345 'InventoryType', -  
346 'PreferredType' -  
347 ]) -  
348 } -  
349 }).done(function(response) { -  
350 if(response.success !== 'True') { -  
351 return; -  
352 } -  
353 data[e.type] = wasKeyValueObjectify( -  
354 wasCSVToArray( -  
355 response.data -  
356 ) -  
357 ); -  
358 }); -  
359 }); -  
360 -  
361 // Do not move the item if: -  
362 // ... the retrieved data is empty. -  
363 if($.isEmptyObject(data) || -  
364 // ... we are trying to move a system folder. 329 if(target.split('/').some(
-   330 function(part) {
Line 365... Line -...
365 ('PreferredType' in data['source'] && data['source'].PreferredType !== 'Unknown') || -  
366 // ... we are trying to move an inventory item over an inventory item. -  
367 ('InventoryType' in data['source'] && 'InventoryType' in data['target'])) -  
368 return false; -  
369 -  
370 // Move the inventory item. -  
371 var moved = false; -  
372 $.ajax({ -  
373 //async: false, -  
374 type: 'POST', -  
375 url: '/', -  
376 dataType: 'json', -  
377 async: false, -  
378 data: { -  
379 command: 'inventory', -  
380 action: 'mv', -  
381 source: source, -  
382 target: target -  
383 } -  
384 }).done(function(response) { -  
385 if(response.success !== 'True') { -  
386 return; 331 return /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/.test(part);
387 } 332 })) {
388 moved = true; 333 return false;
389 }); 334 }
390 335
391 return moved; 336 return true;
392 }, 337 },
393 data: function(node, callback) { 338 data: function(node, callback) {
394 if(node.id === '#') { 339 if(node.id === '#') {
395 callback.call(this, [ 340 callback.call(this, [
396 { 341 {
-   342 "id" : "/My Inventory",
397 "id" : "/My Inventory", 343 "parent" : "#",
398 "parent" : "#", 344 "text" : "My Inventory",
399 "text" : "My Inventory", 345 "data" : {
400 "data" : { 346 "type" : "folder",
401 "type" : 347 'time' : Date.now(),
402 "folder" 348 'system' : true
403 }, 349 },
404 "children" : true, 350 "children" : true,
405 "opened" : false 351 "opened" : false
406 }, 352 },
407 { 353 {
-   354 "id" : "/Library",
408 "id" : "/Library", 355 "parent" : "#",
409 "parent" : "#", 356 "text" : "Library",
410 "text" : "Library", 357 "data" : {
411 "data" : { 358 "type" : "folder",
412 "type" : 359 'time' : Date.now(),
413 "folder" 360 'system' : true
Line 429... Line 376...
429 path: node.id 376 path: node.id
430 } 377 }
431 }).done(function(response) { 378 }).done(function(response) {
432 var list = []; 379 var list = [];
433 $.each(wasCSVToArray(response.data) 380 $.each(wasCSVToArray(response.data)
-   381 .chunk(10),
434 .chunk(10), function(i, e) { 382 function(i, e) {
435 e = wasKeyValueObjectify(e); 383 e = wasKeyValueObjectify(e);
-   384 //alert(node.id + " to " + JSON.stringify(e, 4, null));
436 list.push({ 385 list.push({
437 'id' : node.id === '/' ? '/' + e['item'] : node.id + '/' + e['item'], 386 'id' : node.id === '/' ? '/' + e['item'] : node.id + '/' + e['item'],
438 'parent' : node.id, 387 'parent' : node.id,
439 'data' : { 388 'data' : {
440 'type' : e['type'], 389 'type' : e['type'],
441 'time' : e['time'] 390 'time' : Date.parse(e['time']),
-   391 // Check if this folder is a system folder.
-   392 'system' : node.id === '/My Inventory' && (
-   393 e['name'] === 'Trash' ||
-   394 e['name'] === 'Notecards' ||
-   395 e['name'] === 'Scripts' ||
-   396 e['name'] === 'Lost And Found' ||
-   397 e['name'] === 'Landmarks' ||
-   398 e['name'] === 'Current Outfit' ||
-   399 e['name'] === 'Calling Cards' ||
-   400 e['name'] === 'Textures' ||
-   401 e['name'] === 'Objects' ||
-   402 e['name'] === 'My Outfits' ||
-   403 e['name'] === 'Clothing' ||
-   404 e['name'] === 'Body Parts' ||
-   405 e['name'] === 'Photo Album' ||
-   406 e['name'] === 'Favorites' ||
-   407 e['name'] === 'Gestures' ||
-   408 e['name'] === 'Animations'
-   409 )
442 }, 410 },
443 'text' : e['name'], 411 'text' : e['name'],
444 'children' : e['type'] === 'folder', 412 'children' : e['type'] === 'folder',
445 'icon' : '/pack-rat/img/icons/' + e['type'] + '.png', 413 'icon' : '/pack-rat/img/icons/' + e['type'] + '.gif',
446 'opened' : 'false' 414 'opened' : 'false'
447 }); 415 });
448 }); 416 });
449 callback.call(this, list); 417 callback.call(this, list);
450 }); 418 });
451 } 419 }
452 } 420 }
453 }).bind('move_node.jstree', function(e, data) { 421 }).bind('move_node.jstree', function(e, data) {
-   422 $.ajax({
-   423 //async: false,
-   424 type: 'POST',
-   425 url: '/',
-   426 dataType: 'json',
-   427 data: {
-   428 command: 'inventory',
-   429 action: 'mv',
-   430 source: data.node.id,
-   431 target: data.parent
-   432 }
-   433 }).done(function(response) {
-   434 if(response.success !== 'True') {
-   435 alert('Error moving item: ' + response.error);
-   436 }
-   437 });
454 // Once the node is moved, update the node ID to reflect the path change. 438 // Once the node is moved, update the node ID to reflect the path change.
455 var parentPath = data.parent != '/' ? data.parent : ""; 439 var parentPath = data.parent != '/' ? data.parent : "";
456 var item = data.node.id.split(/[\/]+/).pop(); 440 var item = data.node.id.split(/[\/]+/).pop();
457 data.instance.set_id(data.node, parentPath + '/' + item); 441 data.instance.set_id(data.node, parentPath + '/' + item);
458 }); 442 });