From 9ed14ba3b8408a2b7ecd308c6cb1a556a280fae2 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 2 Sep 2014 02:55:03 +0400 Subject: [PATCH] working to simplify the action architecture... Signed-off-by: Alex A. Naanou --- ui (gen4)/actions.js | 11 +++--- ui (gen4)/client.js | 83 +++++++++++++++++++++++++++++++++++++------- ui (gen4)/data.js | 16 +++------ ui (gen4)/images.js | 3 ++ ui (gen4)/ribbons.js | 8 +++-- ui (gen4)/ui.js | 3 ++ 6 files changed, 94 insertions(+), 30 deletions(-) diff --git a/ui (gen4)/actions.js b/ui (gen4)/actions.js index 46ef68e0..2add179d 100755 --- a/ui (gen4)/actions.js +++ b/ui (gen4)/actions.js @@ -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: '', diff --git a/ui (gen4)/client.js b/ui (gen4)/client.js index 8a5a60ec..dfbfc3fd 100755 --- a/ui (gen4)/client.js +++ b/ui (gen4)/client.js @@ -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 + diff --git a/ui (gen4)/data.js b/ui (gen4)/data.js index 405e813e..09e61daa 100755 --- a/ui (gen4)/data.js +++ b/ui (gen4)/data.js @@ -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 }) diff --git a/ui (gen4)/images.js b/ui (gen4)/images.js index e91eeec6..b2e6279c 100755 --- a/ui (gen4)/images.js +++ b/ui (gen4)/images.js @@ -140,6 +140,9 @@ module.calcRelativeRotation = function(from, to){ } + +/*********************************************************************/ + // cmp functions... // XXX is this the right way to seporate these??? diff --git a/ui (gen4)/ribbons.js b/ui (gen4)/ribbons.js index 989ed0a7..6e0d4a95 100755 --- a/ui (gen4)/ribbons.js +++ b/ui (gen4)/ribbons.js @@ -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 diff --git a/ui (gen4)/ui.js b/ui (gen4)/ui.js index e70cec8a..e3eac753 100755 --- a/ui (gen4)/ui.js +++ b/ui (gen4)/ui.js @@ -33,6 +33,9 @@ var ribbons = require('ribbons') var testing = require('testing') +var client = require('client') + + /*********************************************************************/