From 7d2fe8fd04b106ab643a13846ee34ecc22093706 Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Wed, 21 Mar 2012 22:06:16 +0100 Subject: [PATCH 01/15] colorpicker working for one predefined lamp --- src/main/webapp/WEB-INF/jsp/index.jsp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index 2add903..204d0ea 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -9,7 +9,7 @@ " rel="stylesheet" /> " rel="stylesheet" /> - " rel="stylesheet" /> + " rel="stylesheet" /> @@ -22,12 +22,13 @@ function() { var dataChanged = false; var par56eins = $.parseJSON('{"deviceId":1, "options": {"red":0,"blue":0,"green":0} }'); + var par56null = $.parseJSON('{"deviceId":0, "options": {"red":0,"blue":0,"green":0} }'); var volumes = $.parseJSON('{"room1":0,"room2":0,"room3":0,"room4":0}'); function sendData(data) { $.ajax({ type: 'POST', - url: "/control/devices/1", + url: "/control/devices/0", contentType: "application/json", dataType: "json", data: JSON.stringify(data) @@ -37,13 +38,16 @@ var senden = function sendOutAllDevices() { if(dataChanged) { dataChanged = false; - sendData(par56eins); + sendData(par56null); + console.log("send data"); } + console.log("set new interval for sending"); + window.setTimeout(senden, 200); }; // vielleicht baut man lieber was mit setTimeout und setzt das jeweils neu wenn man daten ändert // das könnte den Browser entlasten, sofern den das 200ms Aufrufen überhaupt stört :D - window.setInterval(senden, 200); + senden(); $("#slider1").slider({ min: 0, max: 100, slide: function(event, ui) { volumes.room1 = ui.value; @@ -84,7 +88,18 @@ } }); var colorpicker_raum1 = new jQuery.ColorPicker('#colorpicker-raum1', { - imagepath: '/resources/images/colorpicker/' + imagepath: '/resources/images/colorpicker/', + change: function(hexcolor) { + red = hexcolor.substr(1,2); + green = hexcolor.substr(3,2); + blue = hexcolor.substr(5,2); + par56null.options.red = parseInt(red, 16); + par56null.options.blue = parseInt(blue, 16); + par56null.options.green = parseInt(green, 16); + console.log("data changed"); + dataChanged = true; + + } }); }); } From e60ffe63601578b7feb2af441e52ca13f81226a0 Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Wed, 21 Mar 2012 22:35:03 +0100 Subject: [PATCH 02/15] sending reorganized, dynamically create the first select of par56 --- src/main/webapp/WEB-INF/jsp/index.jsp | 92 +++++++++++++-------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index 204d0ea..1916e1e 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -20,15 +20,20 @@ @@ -132,9 +155,6 @@
@@ -142,10 +162,6 @@ Zu
-
- Auf - -
@@ -155,10 +171,10 @@
  • Lampel
  • -
    - - +
    @@ -180,29 +196,6 @@
    -
    - -
    -
    - -
    - -
    - -
    - -
    - -
    - -
    - - - - -
    - - \ No newline at end of file From 67d82c4af6b6cfb1a25f478f101bd3133ca13918 Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Thu, 22 Mar 2012 14:57:18 +0100 Subject: [PATCH 06/15] some code removed --- src/main/webapp/WEB-INF/jsp/index.jsp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index 551c3e2..b1f509c 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -63,21 +63,6 @@ volumes.room1 = ui.value; dataChanged = true; } }); - - $("#slider2").slider({ min: 0, max: 100, slide: function(event, ui) { - volumes.room2 = ui.value; - dataChanged = true; - } }); - - $("#slider3").slider({ min: 0, max: 100, slide: function(event, ui) { - volumes.room3 = ui.value; - dataChanged = true; - } }); - - $("#slider4").slider({ min: 0, max: 100, slide: function(event, ui) { - volumes.room4 = ui.value; - dataChanged = true; - } }); $("#tabs").tabs(); $("#v-tabs").tabs().addClass('ui-tabs-vertical'); $(".lampel .circle").click(function() { @@ -106,7 +91,7 @@ $.getJSON('/control/devices', function(data) { devices = data; for(var i=0;i" + devices[i].deviceName + ""); } } From 594e545080ad58e3723220bb761aa6496ce70af2 Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Thu, 22 Mar 2012 14:58:09 +0100 Subject: [PATCH 07/15] rooms.json added, it includes sample json for a roomlist --- src/main/webapp/resources/json/rooms.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/webapp/resources/json/rooms.json diff --git a/src/main/webapp/resources/json/rooms.json b/src/main/webapp/resources/json/rooms.json new file mode 100644 index 0000000..82daf04 --- /dev/null +++ b/src/main/webapp/resources/json/rooms.json @@ -0,0 +1,7 @@ +[ + {"roomId": 0, "roomName": "Global"}, + {"roomId": 1, "roomName": "Raum 1"}, + {"roomId": 2, "roomName": "Raum 2"}, + {"roomId": 3, "roomName": "Raum 3"}, + {"roomId": 4, "roomName": "Raum 4"}, +] \ No newline at end of file From c0782344e74f60abfe8f95a1d2f6cebc09dda49d Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Fri, 23 Mar 2012 00:41:02 +0100 Subject: [PATCH 08/15] added handlebars.js templating system --- src/main/webapp/resources/js/handlebars.js | 1550 ++++++++++++++++++++ 1 file changed, 1550 insertions(+) create mode 100644 src/main/webapp/resources/js/handlebars.js diff --git a/src/main/webapp/resources/js/handlebars.js b/src/main/webapp/resources/js/handlebars.js new file mode 100644 index 0000000..95dcc5e --- /dev/null +++ b/src/main/webapp/resources/js/handlebars.js @@ -0,0 +1,1550 @@ +// lib/handlebars/base.js +var Handlebars = {}; + +Handlebars.VERSION = "1.0.beta.6"; + +Handlebars.helpers = {}; +Handlebars.partials = {}; + +Handlebars.registerHelper = function(name, fn, inverse) { + if(inverse) { fn.not = inverse; } + this.helpers[name] = fn; +}; + +Handlebars.registerPartial = function(name, str) { + this.partials[name] = str; +}; + +Handlebars.registerHelper('helperMissing', function(arg) { + if(arguments.length === 2) { + return undefined; + } else { + throw new Error("Could not find property '" + arg + "'"); + } +}); + +var toString = Object.prototype.toString, functionType = "[object Function]"; + +Handlebars.registerHelper('blockHelperMissing', function(context, options) { + var inverse = options.inverse || function() {}, fn = options.fn; + + + var ret = ""; + var type = toString.call(context); + + if(type === functionType) { context = context.call(this); } + + if(context === true) { + return fn(this); + } else if(context === false || context == null) { + return inverse(this); + } else if(type === "[object Array]") { + if(context.length > 0) { + for(var i=0, j=context.length; i 0) { + for(var i=0, j=context.length; i 2) { + expected.push("'" + this.terminals_[p] + "'"); + } + var errStr = ""; + if (this.lexer.showPosition) { + errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + this.terminals_[symbol] + "'"; + } else { + errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'"); + } + this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected}); + } + } + if (action[0] instanceof Array && action.length > 1) { + throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol); + } + switch (action[0]) { + case 1: + stack.push(symbol); + vstack.push(this.lexer.yytext); + lstack.push(this.lexer.yylloc); + stack.push(action[1]); + symbol = null; + if (!preErrorSymbol) { + yyleng = this.lexer.yyleng; + yytext = this.lexer.yytext; + yylineno = this.lexer.yylineno; + yyloc = this.lexer.yylloc; + if (recovering > 0) + recovering--; + } else { + symbol = preErrorSymbol; + preErrorSymbol = null; + } + break; + case 2: + len = this.productions_[action[1]][1]; + yyval.$ = vstack[vstack.length - len]; + yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column}; + r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); + if (typeof r !== "undefined") { + return r; + } + if (len) { + stack = stack.slice(0, -1 * len * 2); + vstack = vstack.slice(0, -1 * len); + lstack = lstack.slice(0, -1 * len); + } + stack.push(this.productions_[action[1]][0]); + vstack.push(yyval.$); + lstack.push(yyval._$); + newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; + stack.push(newState); + break; + case 3: + return true; + } + } + return true; + } + };/* Jison generated lexer */ + var lexer = (function(){ + + var lexer = ({EOF:1, + parseError:function parseError(str, hash) { + if (this.yy.parseError) { + this.yy.parseError(str, hash); + } else { + throw new Error(str); + } + }, + setInput:function (input) { + this._input = input; + this._more = this._less = this.done = false; + this.yylineno = this.yyleng = 0; + this.yytext = this.matched = this.match = ''; + this.conditionStack = ['INITIAL']; + this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0}; + return this; + }, + input:function () { + var ch = this._input[0]; + this.yytext+=ch; + this.yyleng++; + this.match+=ch; + this.matched+=ch; + var lines = ch.match(/\n/); + if (lines) this.yylineno++; + this._input = this._input.slice(1); + return ch; + }, + unput:function (ch) { + this._input = ch + this._input; + return this; + }, + more:function () { + this._more = true; + return this; + }, + pastInput:function () { + var past = this.matched.substr(0, this.matched.length - this.match.length); + return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, ""); + }, + upcomingInput:function () { + var next = this.match; + if (next.length < 20) { + next += this._input.substr(0, 20-next.length); + } + return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, ""); + }, + showPosition:function () { + var pre = this.pastInput(); + var c = new Array(pre.length + 1).join("-"); + return pre + this.upcomingInput() + "\n" + c+"^"; + }, + next:function () { + if (this.done) { + return this.EOF; + } + if (!this._input) this.done = true; + + var token, + match, + col, + lines; + if (!this._more) { + this.yytext = ''; + this.match = ''; + } + var rules = this._currentRules(); + for (var i=0;i < rules.length; i++) { + match = this._input.match(this.rules[rules[i]]); + if (match) { + lines = match[0].match(/\n.*/g); + if (lines) this.yylineno += lines.length; + this.yylloc = {first_line: this.yylloc.last_line, + last_line: this.yylineno+1, + first_column: this.yylloc.last_column, + last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length} + this.yytext += match[0]; + this.match += match[0]; + this.matches = match; + this.yyleng = this.yytext.length; + this._more = false; + this._input = this._input.slice(match[0].length); + this.matched += match[0]; + token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]); + if (token) return token; + else return; + } + } + if (this._input === "") { + return this.EOF; + } else { + this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(), + {text: "", token: null, line: this.yylineno}); + } + }, + lex:function lex() { + var r = this.next(); + if (typeof r !== 'undefined') { + return r; + } else { + return this.lex(); + } + }, + begin:function begin(condition) { + this.conditionStack.push(condition); + }, + popState:function popState() { + return this.conditionStack.pop(); + }, + _currentRules:function _currentRules() { + return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules; + }, + topState:function () { + return this.conditionStack[this.conditionStack.length-2]; + }, + pushState:function begin(condition) { + this.begin(condition); + }}); + lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { + + var YYSTATE=YY_START + switch($avoiding_name_collisions) { + case 0: + if(yy_.yytext.slice(-1) !== "\\") this.begin("mu"); + if(yy_.yytext.slice(-1) === "\\") yy_.yytext = yy_.yytext.substr(0,yy_.yyleng-1), this.begin("emu"); + if(yy_.yytext) return 14; + + break; + case 1: return 14; + break; + case 2: this.popState(); return 14; + break; + case 3: return 24; + break; + case 4: return 16; + break; + case 5: return 20; + break; + case 6: return 19; + break; + case 7: return 19; + break; + case 8: return 23; + break; + case 9: return 23; + break; + case 10: yy_.yytext = yy_.yytext.substr(3,yy_.yyleng-5); this.popState(); return 15; + break; + case 11: return 22; + break; + case 12: return 34; + break; + case 13: return 33; + break; + case 14: return 33; + break; + case 15: return 36; + break; + case 16: /*ignore whitespace*/ + break; + case 17: this.popState(); return 18; + break; + case 18: this.popState(); return 18; + break; + case 19: yy_.yytext = yy_.yytext.substr(1,yy_.yyleng-2).replace(/\\"/g,'"'); return 28; + break; + case 20: return 30; + break; + case 21: return 30; + break; + case 22: return 29; + break; + case 23: return 33; + break; + case 24: yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 33; + break; + case 25: return 'INVALID'; + break; + case 26: return 5; + break; + } + }; + lexer.rules = [/^[^\x00]*?(?=(\{\{))/,/^[^\x00]+/,/^[^\x00]{2,}?(?=(\{\{))/,/^\{\{>/,/^\{\{#/,/^\{\{\//,/^\{\{\^/,/^\{\{\s*else\b/,/^\{\{\{/,/^\{\{&/,/^\{\{![\s\S]*?\}\}/,/^\{\{/,/^=/,/^\.(?=[} ])/,/^\.\./,/^[\/.]/,/^\s+/,/^\}\}\}/,/^\}\}/,/^"(\\["]|[^"])*"/,/^true(?=[}\s])/,/^false(?=[}\s])/,/^[0-9]+(?=[}\s])/,/^[a-zA-Z0-9_$-]+(?=[=}\s\/.])/,/^\[[^\]]*\]/,/^./,/^$/]; + lexer.conditions = {"mu":{"rules":[3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"INITIAL":{"rules":[0,1,26],"inclusive":true}};return lexer;})() + parser.lexer = lexer; + return parser; +})(); +if (typeof require !== 'undefined' && typeof exports !== 'undefined') { + exports.parser = handlebars; + exports.parse = function () { return handlebars.parse.apply(handlebars, arguments); } + exports.main = function commonjsMain(args) { + if (!args[1]) + throw new Error('Usage: '+args[0]+' FILE'); + if (typeof process !== 'undefined') { + var source = require('fs').readFileSync(require('path').join(process.cwd(), args[1]), "utf8"); + } else { + var cwd = require("file").path(require("file").cwd()); + var source = cwd.join(args[1]).read({charset: "utf-8"}); + } + return exports.parser.parse(source); + } + if (typeof module !== 'undefined' && require.main === module) { + exports.main(typeof process !== 'undefined' ? process.argv.slice(1) : require("system").args); + } +}; +; +// lib/handlebars/compiler/base.js +Handlebars.Parser = handlebars; + +Handlebars.parse = function(string) { + Handlebars.Parser.yy = Handlebars.AST; + return Handlebars.Parser.parse(string); +}; + +Handlebars.print = function(ast) { + return new Handlebars.PrintVisitor().accept(ast); +}; + +Handlebars.logger = { + DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3, level: 3, + + // override in the host environment + log: function(level, str) {} +}; + +Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); }; +; +// lib/handlebars/compiler/ast.js +(function() { + + Handlebars.AST = {}; + + Handlebars.AST.ProgramNode = function(statements, inverse) { + this.type = "program"; + this.statements = statements; + if(inverse) { this.inverse = new Handlebars.AST.ProgramNode(inverse); } + }; + + Handlebars.AST.MustacheNode = function(params, hash, unescaped) { + this.type = "mustache"; + this.id = params[0]; + this.params = params.slice(1); + this.hash = hash; + this.escaped = !unescaped; + }; + + Handlebars.AST.PartialNode = function(id, context) { + this.type = "partial"; + + // TODO: disallow complex IDs + + this.id = id; + this.context = context; + }; + + var verifyMatch = function(open, close) { + if(open.original !== close.original) { + throw new Handlebars.Exception(open.original + " doesn't match " + close.original); + } + }; + + Handlebars.AST.BlockNode = function(mustache, program, close) { + verifyMatch(mustache.id, close); + this.type = "block"; + this.mustache = mustache; + this.program = program; + }; + + Handlebars.AST.InverseNode = function(mustache, program, close) { + verifyMatch(mustache.id, close); + this.type = "inverse"; + this.mustache = mustache; + this.program = program; + }; + + Handlebars.AST.ContentNode = function(string) { + this.type = "content"; + this.string = string; + }; + + Handlebars.AST.HashNode = function(pairs) { + this.type = "hash"; + this.pairs = pairs; + }; + + Handlebars.AST.IdNode = function(parts) { + this.type = "ID"; + this.original = parts.join("."); + + var dig = [], depth = 0; + + for(var i=0,l=parts.length; i": ">", + '"': """, + "'": "'", + "`": "`" + }; + + var badChars = /&(?!\w+;)|[<>"'`]/g; + var possible = /[&<>"'`]/; + + var escapeChar = function(chr) { + return escape[chr] || "&"; + }; + + Handlebars.Utils = { + escapeExpression: function(string) { + // don't escape SafeStrings, since they're already safe + if (string instanceof Handlebars.SafeString) { + return string.toString(); + } else if (string == null || string === false) { + return ""; + } + + if(!possible.test(string)) { return string; } + return string.replace(badChars, escapeChar); + }, + + isEmpty: function(value) { + if (typeof value === "undefined") { + return true; + } else if (value === null) { + return true; + } else if (value === false) { + return true; + } else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) { + return true; + } else { + return false; + } + } + }; +})();; +// lib/handlebars/compiler/compiler.js +Handlebars.Compiler = function() {}; +Handlebars.JavaScriptCompiler = function() {}; + +(function(Compiler, JavaScriptCompiler) { + Compiler.OPCODE_MAP = { + appendContent: 1, + getContext: 2, + lookupWithHelpers: 3, + lookup: 4, + append: 5, + invokeMustache: 6, + appendEscaped: 7, + pushString: 8, + truthyOrFallback: 9, + functionOrFallback: 10, + invokeProgram: 11, + invokePartial: 12, + push: 13, + assignToHash: 15, + pushStringParam: 16 + }; + + Compiler.MULTI_PARAM_OPCODES = { + appendContent: 1, + getContext: 1, + lookupWithHelpers: 2, + lookup: 1, + invokeMustache: 3, + pushString: 1, + truthyOrFallback: 1, + functionOrFallback: 1, + invokeProgram: 3, + invokePartial: 1, + push: 1, + assignToHash: 1, + pushStringParam: 1 + }; + + Compiler.DISASSEMBLE_MAP = {}; + + for(var prop in Compiler.OPCODE_MAP) { + var value = Compiler.OPCODE_MAP[prop]; + Compiler.DISASSEMBLE_MAP[value] = prop; + } + + Compiler.multiParamSize = function(code) { + return Compiler.MULTI_PARAM_OPCODES[Compiler.DISASSEMBLE_MAP[code]]; + }; + + Compiler.prototype = { + compiler: Compiler, + + disassemble: function() { + var opcodes = this.opcodes, opcode, nextCode; + var out = [], str, name, value; + + for(var i=0, l=opcodes.length; i 0) { + this.source[1] = this.source[1] + ", " + locals.join(", "); + } + + // Generate minimizer alias mappings + if (!this.isChild) { + var aliases = [] + for (var alias in this.context.aliases) { + this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias]; + } + } + + if (this.source[1]) { + this.source[1] = "var " + this.source[1].substring(2) + ";"; + } + + // Merge children + if (!this.isChild) { + this.source[1] += '\n' + this.context.programs.join('\n') + '\n'; + } + + if (!this.environment.isSimple) { + this.source.push("return buffer;"); + } + + var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"]; + + for(var i=0, l=this.environment.depths.list.length; i this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); } + return "stack" + this.stackSlot; + }, + + popStack: function() { + return "stack" + this.stackSlot--; + }, + + topStack: function() { + return "stack" + this.stackSlot; + }, + + quotedString: function(str) { + return '"' + str + .replace(/\\/g, '\\\\') + .replace(/"/g, '\\"') + .replace(/\n/g, '\\n') + .replace(/\r/g, '\\r') + '"'; + } + }; + + var reservedWords = ( + "break else new var" + + " case finally return void" + + " catch for switch while" + + " continue function this with" + + " default if throw" + + " delete in try" + + " do instanceof typeof" + + " abstract enum int short" + + " boolean export interface static" + + " byte extends long super" + + " char final native synchronized" + + " class float package throws" + + " const goto private transient" + + " debugger implements protected volatile" + + " double import public let yield" + ).split(" "); + + var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {}; + + for(var i=0, l=reservedWords.length; i Date: Fri, 23 Mar 2012 00:52:33 +0100 Subject: [PATCH 09/15] first two templates added, javascript now in a seperate file --- src/main/webapp/WEB-INF/jsp/index.jsp | 136 ++++------------------ src/main/webapp/resources/js/main.js | 114 ++++++++++++++++++ src/main/webapp/resources/json/rooms.json | 16 +-- 3 files changed, 144 insertions(+), 122 deletions(-) create mode 100644 src/main/webapp/resources/js/main.js diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index b1f509c..3308144 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -14,124 +14,10 @@ + -

    CTDO Raumsteuerung

    @@ -182,5 +68,25 @@ + + + \ No newline at end of file diff --git a/src/main/webapp/resources/js/main.js b/src/main/webapp/resources/js/main.js new file mode 100644 index 0000000..16b827e --- /dev/null +++ b/src/main/webapp/resources/js/main.js @@ -0,0 +1,114 @@ +/** + * Created by IntelliJ IDEA. + * User: henne + * Date: 23.03.12 + * Time: 00:51 + * Main Javascript file + */ +var rooms; +var volumes = {"room1":0,"room2":0,"room3":0,"room4":0}; +var devices; +$(document).ready( + function() { + + + function sendData(data) { + $.ajax({ + type: 'POST', + url: "/control/devices", + contentType: "application/json", + dataType: "json", + data: JSON.stringify(data) + }); + console.log(data); + console.log(JSON.stringify(data)); + } + + var senden = function sendOutAllDevices() { + var changedDevs = new Array(); + for(var i=0;i 0) { + sendData({"timeStamp": Math.round(new Date().getTime()/1000), "updates": changedDevs}); + } + console.log("set new interval for sending"); + + }; + window.setInterval(senden, 100); + + $("#slider1").slider({ min: 0, max: 100, slide: function(event, ui) { + volumes.room1 = ui.value; + dataChanged = true; + } }); + $("#tabs").tabs(); + $("#v-tabs").tabs().addClass('ui-tabs-vertical'); + $(".lampel .circle").click(function() { + if($(this).hasClass('black')){ + $(this).removeClass('black'); + } else { + $(this).addClass('black'); + } + }); + var colorpicker_raum1 = new jQuery.ColorPicker('#colorpicker-raum1', { + imagepath: '/resources/images/colorpicker/', + change: function(hexcolor) { + var red = hexcolor.substr(1,2); + var green = hexcolor.substr(3,2); + var blue = hexcolor.substr(5,2); + $('#par56select option:selected').each(function() { + devices[$(this).attr('name')].red = parseInt(red, 16); + devices[$(this).attr('name')].green = parseInt(green, 16); + devices[$(this).attr('name')].blue = parseInt(blue, 16); + devices[$(this).attr('name')].dirty = true; + }); + console.log("data changed" + hexcolor); + + } + }); + $.getJSON('/control/devices', function(data) { + devices = data; + for(var i=0;i" + devices[i].deviceName + ""); + } + } + + }); + $('.buzzer button').click(function() { + var span = $(this).parent().find('span'); + span + .toggleClass('red') + .toggleClass('green'); + if(span.text() == "Auf") { + span.text("Zu"); + } else { + span.text("Auf"); + } + + }) + $('#par56select').change(function() { + $('#par56select option:selected').each(function() { + var red = devices[$(this).attr('name')].red.toString(16); + var green = devices[$(this).attr('name')].green.toString(16); + var blue = devices[$(this).attr('name')].blue.toString(16); + if(red.length == 1) { + red += red; + } + if(green.length == 1) { + green += green; + } + if(blue.length == 1) { + blue += blue; + } + var hexstring = '#' + red + green + blue; + console.log("lampe:" + hexstring); + colorpicker_raum1.hex(hexstring); + }); + }); + } +); \ No newline at end of file diff --git a/src/main/webapp/resources/json/rooms.json b/src/main/webapp/resources/json/rooms.json index 82daf04..669dc07 100644 --- a/src/main/webapp/resources/json/rooms.json +++ b/src/main/webapp/resources/json/rooms.json @@ -1,7 +1,9 @@ -[ - {"roomId": 0, "roomName": "Global"}, - {"roomId": 1, "roomName": "Raum 1"}, - {"roomId": 2, "roomName": "Raum 2"}, - {"roomId": 3, "roomName": "Raum 3"}, - {"roomId": 4, "roomName": "Raum 4"}, -] \ No newline at end of file +{ + "rooms" : [ + {"roomId": 0, "roomName": "Global"}, + {"roomId": 1, "roomName": "Raum 1"}, + {"roomId": 2, "roomName": "Raum 2"}, + {"roomId": 3, "roomName": "Raum 3"}, + {"roomId": 4, "roomName": "Raum 4"}, + ] +} \ No newline at end of file From efb07b64da45722445e2faeb9772f0d2d5656e12 Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Fri, 23 Mar 2012 00:53:01 +0100 Subject: [PATCH 10/15] main.js included in index.jsp --- src/main/webapp/WEB-INF/jsp/index.jsp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index 3308144..f4bad99 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -15,6 +15,7 @@ + From 274fdf53c1845946b6bacf15cff5aad6353006e6 Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Fri, 23 Mar 2012 00:54:41 +0100 Subject: [PATCH 11/15] prototype javascript removed --- src/main/webapp/resources/js/main.js | 103 --------------------------- 1 file changed, 103 deletions(-) diff --git a/src/main/webapp/resources/js/main.js b/src/main/webapp/resources/js/main.js index 16b827e..8d2e988 100644 --- a/src/main/webapp/resources/js/main.js +++ b/src/main/webapp/resources/js/main.js @@ -8,107 +8,4 @@ var rooms; var volumes = {"room1":0,"room2":0,"room3":0,"room4":0}; var devices; -$(document).ready( - function() { - - function sendData(data) { - $.ajax({ - type: 'POST', - url: "/control/devices", - contentType: "application/json", - dataType: "json", - data: JSON.stringify(data) - }); - console.log(data); - console.log(JSON.stringify(data)); - } - - var senden = function sendOutAllDevices() { - var changedDevs = new Array(); - for(var i=0;i 0) { - sendData({"timeStamp": Math.round(new Date().getTime()/1000), "updates": changedDevs}); - } - console.log("set new interval for sending"); - - }; - window.setInterval(senden, 100); - - $("#slider1").slider({ min: 0, max: 100, slide: function(event, ui) { - volumes.room1 = ui.value; - dataChanged = true; - } }); - $("#tabs").tabs(); - $("#v-tabs").tabs().addClass('ui-tabs-vertical'); - $(".lampel .circle").click(function() { - if($(this).hasClass('black')){ - $(this).removeClass('black'); - } else { - $(this).addClass('black'); - } - }); - var colorpicker_raum1 = new jQuery.ColorPicker('#colorpicker-raum1', { - imagepath: '/resources/images/colorpicker/', - change: function(hexcolor) { - var red = hexcolor.substr(1,2); - var green = hexcolor.substr(3,2); - var blue = hexcolor.substr(5,2); - $('#par56select option:selected').each(function() { - devices[$(this).attr('name')].red = parseInt(red, 16); - devices[$(this).attr('name')].green = parseInt(green, 16); - devices[$(this).attr('name')].blue = parseInt(blue, 16); - devices[$(this).attr('name')].dirty = true; - }); - console.log("data changed" + hexcolor); - - } - }); - $.getJSON('/control/devices', function(data) { - devices = data; - for(var i=0;i" + devices[i].deviceName + ""); - } - } - - }); - $('.buzzer button').click(function() { - var span = $(this).parent().find('span'); - span - .toggleClass('red') - .toggleClass('green'); - if(span.text() == "Auf") { - span.text("Zu"); - } else { - span.text("Auf"); - } - - }) - $('#par56select').change(function() { - $('#par56select option:selected').each(function() { - var red = devices[$(this).attr('name')].red.toString(16); - var green = devices[$(this).attr('name')].green.toString(16); - var blue = devices[$(this).attr('name')].blue.toString(16); - if(red.length == 1) { - red += red; - } - if(green.length == 1) { - green += green; - } - if(blue.length == 1) { - blue += blue; - } - var hexstring = '#' + red + green + blue; - console.log("lampe:" + hexstring); - colorpicker_raum1.hex(hexstring); - }); - }); - } -); \ No newline at end of file From b21670aea2095043e939748b2d95a6b8809146b1 Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Fri, 23 Mar 2012 02:41:15 +0100 Subject: [PATCH 12/15] now using template and json object to generate room tabs --- src/main/webapp/WEB-INF/jsp/index.jsp | 22 ++++--- src/main/webapp/resources/css/styles.css | 2 +- src/main/webapp/resources/js/backbone-min.js | 65 ++++++++++---------- src/main/webapp/resources/js/main.js | 6 ++ src/main/webapp/resources/js/models.js | 4 ++ src/main/webapp/resources/js/underscore.js | 31 ++++++++++ src/main/webapp/resources/json/rooms.json | 8 +-- 7 files changed, 91 insertions(+), 47 deletions(-) create mode 100644 src/main/webapp/resources/js/underscore.js diff --git a/src/main/webapp/WEB-INF/jsp/index.jsp b/src/main/webapp/WEB-INF/jsp/index.jsp index f4bad99..d330ddb 100644 --- a/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/src/main/webapp/WEB-INF/jsp/index.jsp @@ -13,17 +13,21 @@ + + + +

    CTDO Raumsteuerung

    -
    +
    - + + + + \ No newline at end of file From b11e96dc648edf5a4a6f844c130d9bba1e7827aa Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Fri, 23 Mar 2012 02:57:42 +0100 Subject: [PATCH 14/15] first routes added --- src/main/webapp/resources/js/main.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/webapp/resources/js/main.js b/src/main/webapp/resources/js/main.js index 1aabfc2..9fb3d14 100644 --- a/src/main/webapp/resources/js/main.js +++ b/src/main/webapp/resources/js/main.js @@ -5,13 +5,26 @@ * Time: 00:51 * Main Javascript file */ -var rooms; -var volumes = {"room1":0,"room2":0,"room3":0,"room4":0}; -var devices; +Workspace = Backbone.Router.extend({ + routes:{ + "":"home", + ":id":"show_room" + + }, + home: function() { + rooms.fetch(); + }, + show_room: function(id) { + this.home(); + window.roomTabsId = id; + } +}); $(document).ready(function() { - var rooms = new Rooms(); - var roomsView = new RoomsView({collection: rooms}); - rooms.fetch(); + window.rooms = new Rooms(); + window.roomsView = new RoomsView({collection: rooms}); + + window.App = new Workspace(); + Backbone.history.start() }); \ No newline at end of file From 4e267935240de8e380efb75a33d39b9d8fec8e66 Mon Sep 17 00:00:00 2001 From: Hendrik Fellerhoff Date: Fri, 23 Mar 2012 02:59:58 +0100 Subject: [PATCH 15/15] views.js wasn't added to git - dunno why ;D --- src/main/webapp/resources/js/views.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/webapp/resources/js/views.js diff --git a/src/main/webapp/resources/js/views.js b/src/main/webapp/resources/js/views.js new file mode 100644 index 0000000..ce01f0b --- /dev/null +++ b/src/main/webapp/resources/js/views.js @@ -0,0 +1,14 @@ +window.RoomsView = Backbone.View.extend({ + initialize: function() { + this.collection.bind('reset', this.render, this); + }, + render: function() { + this.template = Handlebars.compile($("#room-tabs-template").html()); + var rooms = {'rooms': this.collection.toJSON()}; + $('#room-tabs').html(this.template(rooms)).tabs(); + if(typeof(window.roomTabsId) != "undefined") { + $('#room-tabs').tabs('select', window.roomTabsId); + } + return this; + } +});