working to simplify the action architecture...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-09-02 02:55:03 +04:00
parent cf6273fbe4
commit 9ed14ba3b8
6 changed files with 94 additions and 30 deletions

View File

@ -182,14 +182,17 @@ module.BASE_ACTIONS = {
shiftImageDown:
'Shift image to the ribbon below current, creating one if '
+'it does not exist',
shiftImageUpNewRibbon: '',
shiftImageDownNewRibbon: '',
shiftImageUpNewRibbon:
'Create an empty ribbon above and shift the image into it',
shiftImageDownNewRibbon:
'Create an empty ribbon below and shift the image into it',
shiftImageLeft: 'Shift image to the left',
shiftImageRight: 'Shift image to the right',
moveRibbonUp: 'Move current ribbon one position up',
moveRibbonDown: 'Move current ribbon one position down',
shiftRibbonUp: 'Move current ribbon one position up',
shiftRibbonDown: 'Move current ribbon one position down',
// XXX
sortImages: '',
reverseImages: '',
setAsBaseRibbon: '',

View File

@ -7,41 +7,100 @@
//var DEBUG = DEBUG != null ? DEBUG : true
define(function(require){ var module = {}
console.log('>>> ui')
console.log('>>> client')
doc = require('keyboard').doc
doc = require('lib/keyboard').doc
data = require('data')
/*********************************************************************/
// XXX add a callback here...
function proxy(attr, name){
return function(){
this[attr][name].apply(this[attr], arguments)
attr = this[attr]
attr[name].apply(attr, arguments)
return this
}
}
function proxyMethods(obj, map){
var txt = ''
for(var attr in map){
var methods = map[attr]
for(var name in methods){
var txt = methods[name]
if(txt == null){
obj[name] = proxy(attr, name)
} else {
obj[name] = doc(txt, proxy(attr, name))
}
}
}
return obj
}
/*********************************************************************/
var CLIENT_ACTIONS = {
// This will:
// - provide an abstraction layer to data (proxy)
// - provide API docs usable for doc generation...
// - provide callbacks (???)
//
var ClientClassPrototype = {
}
var ClientPrototype = {
// this expects the folowing attrs:
//
// .data
//
focusImage: doc('Focus Image',
proxy('data', 'focusImage')),
focusRibbon: doc('Focus ribbon',
proxy('data', 'focusRibbon')),
firstImage: doc('',
proxy('data', 'firstImage')),
lastImage: doc('',
proxy('data', 'lastImage')),
// XXX client-specific API...
// XXX
}
// setup the proxy methods...
var ClientPrototype = proxyMethods(
ClientPrototype,
{
data: {
focusImage: 'Focus image',
focusRibbon: 'Focus ribbon',
firstImage: 'Focus first image in current ribbon',
lastImage: 'Focus last image in current ribbon',
},
})
/*********************************************************************/
var Client =
module.Client =
function Client(){
// in case this is called as a function (without new)...
if(this.constructor.name != 'Client'){
return new Client()
}
// XXX setup initial state...
return this
}
Client.__proto__ = ClientClassPrototype
Client.prototype = ClientPrototype
Client.prototype.constructor = Client

View File

@ -721,6 +721,9 @@ module.DataPrototype = {
return this
},
// Focus a ribbon -- focus an image in that ribbon
//
// NOTE: target must be .getRibbon(..) compatible.
focusRibbon: function(target){
var cur = this.getRibbonOrder()
var ribbon = this.getRibbon(target)
@ -737,6 +740,7 @@ module.DataPrototype = {
var img = this.getImage(ribbon, direction)
// first/last image...
if(img == null){
img = direction == 'before'
? this.getImage('first', ribbon)
@ -837,6 +841,7 @@ module.DataPrototype = {
// Sort images in ribbons via .order...
//
// NOTE: this sorts in-place
// NOTE: this will not change image order
sortImages: function(){
var ribbons = this.ribbons
for(k in ribbons){
@ -1512,17 +1517,6 @@ Data.prototype.constructor = Data
/*********************************************************************/
// XXX keep this here or move this to a different module???
module.setupActionHandlers = function(context){
// XXX
context.on('focusImage', function(evt, img){
})
}
/**********************************************************************
* vim:set ts=4 sw=4 : */
return module })

View File

@ -140,6 +140,9 @@ module.calcRelativeRotation = function(from, to){
}
/*********************************************************************/
// cmp functions...
// XXX is this the right way to seporate these???

View File

@ -272,7 +272,7 @@ module.RibbonsPrototype = {
},
// Like .getRibbon(..) but returns ribbon index instead of the actual
// ribbon object...
getRibbonIndex: function(target){
getRibbonOrder: function(target){
return this.viewer.find('.ribbon').index(this.getRibbon(target))
},
@ -411,7 +411,7 @@ module.RibbonsPrototype = {
placeRibbon: function(target, position){
// get create the ribbon...
var ribbon = this.getRibbon(target)
var i = this.getRibbonIndex(ribbon)
var i = this.getRibbonOrder(ribbon)
ribbon = ribbon.length == 0 ? this.createRibbon(target) : ribbon
var ribbons = this.viewer.find('.ribbon')
@ -420,7 +420,7 @@ module.RibbonsPrototype = {
position = position < 0 ? ribbons.length + position + 1 : position
position = position < 0 ? 0 : position
} else {
var p = this.getRibbonIndex(position)
var p = this.getRibbonOrder(position)
// XXX what do we do if the target does not exist, i.e. p == -1 ????
}
@ -544,6 +544,8 @@ module.RibbonsPrototype = {
// If this is set to true image previews will be loaded synchronously...
load_img_sync: false,
//
// XXX this depends on .images...
// ...a good candidate to move to images, but not yet sure...
updateImage: function(image, gid, size, sync){
image = (image == '*' ? this.viewer.find('.image')
: image == null

View File

@ -33,6 +33,9 @@ var ribbons = require('ribbons')
var testing = require('testing')
var client = require('client')
/*********************************************************************/