Example #1
0
!function(a){function b(a){this.callback=a,this.layer=new c.Layer,this.setUp()}var c,d,e,f=require("grunt");c=d=a.Guirunt={},e=d.GUI=require("nw.gui"),c.window=e.Window.get().window,function(a){a.config={debug:!0,APPPATH:process.cwd()+"/",NODE_PATH:"./bundles/node/bin/node",NPM_PATH:process.cwd()+"/bundles/node/bin/npm",DROP_DESCRIPTION:"Drop Project to add"}}("undefined"!=typeof c?c:this),function(a){"use strict";function b(a){return"function"==typeof a}function c(){}function d(a){return a===h.SUCCESS?"success":a===h.FAIED?"failed":a===h.ABORT?"abort":void 0}function e(a){return a&&"Lazy"===a._interface}function f(a){return a instanceof i?a.lazy:a}function g(a){this.lazy=a}function h(){this.id=++J,this._proceeded=!1,this._appointID=0,this._status=h.SUSPEND,this._message=void 0,this._progress=null,this._pipes={1:null,16:null,17:null},this._callbacks={1:[],16:[],17:[]},this._chain=null,this.signal=new g(this)}function i(a){this.lazy=a}function j(a){return this.send(h.SUCCESS,a)}function k(a){return this.send(h.FAILED,a)}function l(a){return this.send(h.ABORT,a)}function m(a,b){var c=this.lazy;return c._changeStatus(a,b),c}function n(a){return this.lazy._status===h.SUSPEND&&b(this.lazy._progress)&&this.lazy._progress(a),this.lazy}function o(a,b,c){return this._pipes[h.SUCCESS]=a,this._pipes[h.FAILED]=b,this._pipes[h.ABORT]=c,this}function p(a){return this._callbacks[h.SUCCESS].push([a,0]),this.isSuccess()&&this._execute(),this.promise()}function q(){return this._status===h.SUCCESS}function r(a){return this._callbacks[h.FAILED].push([a,0]),this.isFailed()&&this._execute(),this.promise()}function s(){return this._status===h.FAILED}function t(a){return this._callbacks[h.ABORT].push([a,0]),this.isAbort()&&this._execute(),this._promise()}function u(){return this._status===h.ABORT}function v(a){return this._callbacks[h.SUCCESS].push([a,0]),this._callbacks[h.ABORT].push([a,0]),this._callbacks[h.FAILED].push([a,0]),(this.isSuccess()||this.isAbort()||this.isFailed())&&this._execute(),this.promise()}function w(){for(var a,c,d=new h,g=["success","failed","abort"],j=-1;arguments[++j];)a=arguments[j],c=g[j],this[c](function(){var g,h=b(a)?a():a;e(h)?(g=f(h),g[c](function(){d.signal[c].apply(d.signal,arguments)})):d.signal[c]()});return new i(d)}function x(){return this._chain=new h,this._chain}function y(a){this._appointID=a}function z(){return this._message}function A(a,b){this._proceeded||(this._proceeded=!0,this._status=a,this._message=b,this._execute())}function B(a){var c=this,f=-1,g=this._status,h=this._callbacks[g]||[],i=b(this._pipes[g])&&!a?this._pipes[g](this._message):this._message;if(e(i)&&a)return i[d(g)](function(){c._message=i.getMessage(),c._execute(!0)});for(;h[++f];)b(h[f][0])&&0===h[f][1]&&(h[f][1]=1,this.parallel?h[f][0].apply(this,i):h[f][0](i));this._process(g,i)}function C(a,b){this._appointID>0&&this._appointID in K&&K[this._appointID].signal.send(a,b),this._chains&&this._chains[a].signal.send(a,b)}function D(){return new i(this)}function E(a){return this._progress=a,this}function F(a){if(a&&"Lazy"===a._interface)return a.setAppointID(this._appointID),this._lazy[this._lazy.length]=a,this;throw new Error("Argument must be Lazy instance!")}function G(a){var b=!0,c=-1,d=[];if(!this._proceeded){if(a===h.SUCCESS)for(;this._lazy[++c];){if(e(this._lazy[c])&&f(this._lazy[c])._status!=h.SUCCESS){b=!1;break}d.push(this._lazy[c].getMessage())}else for(b=!1;this._lazy[++c];)f(this._lazy[c])._status==h[a]&&(b=!0),d.push(this._lazy[c].getMessage());b===!0&&(this._proceeded=!0,this._status=a,this._message=d,this._execute())}}function H(){delete K[this._appointID]}{var I,J=0,K=[],L=/^is|parallel|promise|then/;Object.prototype.toString}a.Lazy=h,g.prototype={constructor:g,success:j,failed:k,abort:l,send:m,notify:n},h.SUSPEND=0,h.SUCCESS=1,h.FAILED=16,h.ABORT=17,h.make=function(){return new h},h.extend=function(a){return a._interface="Lazy",a},h.prototype={_interface:"Lazy",constructor:h,pipe:o,success:p,isSuccess:q,failed:r,isFailed:s,abort:t,isAbort:u,always:v,then:w,chain:x,setAppointID:y,getMessage:z,_changeStatus:A,_execute:B,_process:C,promise:D,progress:E},h.Parallel=function(){var a,b=-1;for(h.call(this),this._appointID=++J,this._lazy=[],this.parallel=!0;arguments[++b];)a=arguments[b],e(a)&&(a.setAppointID(this._appointID),this._lazy[this._lazy.length]=a);return K[this._appointID]=this,this},h.Parallel.prototype={_interface:"Lazy",constructor:h.Parallel,promise:D,success:p,isSuccess:q,failed:r,isFailed:s,abort:t,chain:x,isAbort:u,pipe:o,getMessage:z,_execute:B,progress:E,_changeStatus:G,append:F,_process:H},i.prototype={_interface:"Lazy",constructor:i,signal:{success:c,failed:c,abort:c,notify:function(a){n.call(this,a)}}};for(I in h.prototype)!I.isPrototypeOf(h.prototype)&&b(h.prototype[I])&&!function(a){i.prototype[a]=function(){var b=h.prototype[a],c=b.apply(this.lazy,arguments);return L.test(a)?c:this}}(I)}("undefined"!=typeof c?c:this),function(a){a.log=function(a){c.config.debug&&console.log(a)}}("undefined"!=typeof c?c:this),function(a){function b(){this.platform=j.platform(),this._linux=!1,this._darwin=!1,this._windows=!1,this.spawnProcessName="",c.log("Env class instanciated. Platform is "+this.platform),this._detect()}function d(){switch(this.platform){case i.LINUX:this._linux=!0,this.spawnProcessName="bash";break;case i.MACOS:this._darwin=!0,this.spawnProcessName="bash";break;case i.FREEBSD:this._linux=!0,this.spawnProcessName="sh";break;case i.WINDOWS32:case i.WINDOWS64:this._windows=!0,this.spawnProcessName="cmd.exe";break;default:throw new Error("Unsupported Platform: "+this.platform)}c.log("Platform detected: "+this.platform)}function e(){return this._linux}function f(){return this._darwin}function g(){return this._windows}function h(){return this.spawnProcessName}var i={LINUX:"linux",FREEBSD:"freebsd",MACOS:"darwin",WINDOWS32:"win32",WINDOWS64:"win64"},j=require("os");b.prototype={constructor:b,_detect:d,isLinux:e,isMac:f,isWindows:g,getSpawnCommand:h},a.env=new b}("undefined"!=typeof c?c:this),function(a){a.util={},a.util.addClass=function(a,b){a.classList.add(b)},a.util.removeClass=function(a,b){a.classList.remove(b)},a.util.hasClass=function(a,b){return a.classList.contains(b)},a.util.toggleClass=function(a,b){a.classList.toggle(b)},a.util.isObject=function(a){return"[object Object]"===Object.prototype.toString.call(a)},a.util.escape=function(a){return a.toString().replace("<","&lt;").replace(">","&gt;").replace('"',"&quot;")},a.util.mixin=function(a,b){return Object.keys(b).forEach(function(c){a[c]=b[c]}),a}}("undefined"!=typeof c?c:this),function(){function a(b){return!this instanceof a?new a(b):(j.call(this),this.commandStack=[],this.proc=null,this._stdoutData="",this._processing=null,c.log("Console class instanciated"),void 0)}function b(){return this.proc||(c.log("Spawn command: "+c.env.getSpawnCommand()),this.proc=i.spawn(c.env.getSpawnCommand()),this.proc.stderr.on("data",this.onStdErr.bind(this)),this.proc.stdout.on("data",this.onStdOut.bind(this)),this.proc.on("close",this.onClose.bind(this))),this.proc}function d(a){var b;return this._processing?(this.commandStack.push(a),c.log("Command is now running. queued: "+a),void 0):(c.log("Command is accepted: "+a),this._processing=new c.Lazy,b=this._spawn(),b.stdin.write(a),b.stdin.end(),void 0)}function e(a){console.log("err: "+a),this.emit("stderr",a)}function f(a){console.log("out: "+a),this._stdoutData+=a,this.emit("stdout",a)}function g(b){c.log("Process closed. responseCode:  "+b),b===a.CODE_SUCCESS?this._processing.signal.sucess(this._stdoutData):this._processing.signal.failed(),this._stdoutData="",this._processing=null,this.proc.stderr.off("data"),this.proc.stderr.off("data"),this.proc.off("close")}var h,i=require("child_process"),j=require("events").EventEmitter;a.CODE_SUCCESS=0,a.prototype={Constructor:a,_spawn:b,exec:d,onStdErr:e,onStdOut:f,onClose:g};for(h in j)a.prototype[h]=j.prototype[h]}("undefined"!=typeof c?c:this),function(a){function b(){this.storage=localStorage}function c(a,b){var c=this.storage;void 0!==b&&c.setItem(a,b),"[Object object]"===Object.prototype.toString.call(a)&&Object.keys(a).forEach(function(b){c.setItem(b,a[b])})}function d(a){var b=this.storage.getItem(a);return null===b?b:null}function e(a){return this.storage.removeItem(a)}function f(a){var b=this.storage.getItem(a);return null===b?!1:!0}b.prototype={constructor:b,set:c,get:d,remove:e,exists:f},a.storage=new b}("undefined"!=typeof c?c:this),function(a){function b(){}var c=openDatabase("guirunt","1.0","guirunt data storage",2097152);b._initDB=function(){c.transaction(function(a){a.executeSql("CREATE TABLE IF NOT EXISTS projects (project_path TEXT, project_name TEXT);",[],function(){console.log("Create project table success")},function(a,b){console.log("Failed to create table: "+b.message)}),a.executeSql("CREATE TABLE IF NOT EXISTS project_tasks (project_name TEXT, task_name TEXT)",[],function(){console.log("Create project_tasks table success")},function(a,b){console.log("Failed to create table: "+b.message)}),a.executeSql("CREATE TABLE IF NOT EXISTS task_settings (task_name TEXT, setting_data TEXT)",[],function(){console.log("Create task_settings table success")},function(a,b){console.log("Failed to create table: "+b.message)})})},b.query=function(b,d){var e=new a.Lazy,f=d||[];return c.transaction(function(a){transaction=a,a.executeSql(b,f,function(a,c){var d=[],f=0;if(/^insert/i.test(b))e.signal.success(c.insertId);else if(/^(update|delete)/i.test(b))e.signal.success(c.rowAffected);else{for(;f<c.rows.length;++f)d[f]=c.rows.item(f);e.signal.success(d)}},function(a,b){e.signal.failed(b)})}),e},a.db=b}("undefined"!=typeof c?c:this),function(a){function b(b,d){var e=new a.Lazy;return d&&e.success(d),c.get(b,function(a){var b="";return 200!=a.statusCode?(e.signal.failed(a),void 0):(a.setEncoding("utf8"),a.on("data",function(a){b+=a}),a.on("end",function(){e.signal.success(b)}),void 0)}),e.promise()}var c=require("http");a.http=b}("undefined"!=typeof c?c:this),function(a){function b(a){d.util.isObject(a)&&Object.keys(a).forEach(function(b){this[b]=a[b]}.bind(this)),c.call(this),this._listenViews={}}var c=require("events").EventEmitter,e=require("util");a.Model=b,e.inherits(b,c),b.extend=function(a){var b=a||{},c="function"==typeof this?this:this.constructor,d=function(){c.apply(this,arguments),"function"==typeof c.prototype._construct&&c.prototype._construct.call(this),this._construct&&this._construct()};return e.inherits(d,this),Object.keys(b).forEach(function(a){d.prototype[a]=b[a]}),d.extend=this.extend,d},b.prototype.listen=function(a,b){a in this._listenViews||(this._listenViews[a]=[]),this._listenViews[a].push(b)},b.prototype.trigger=function(a,b){a in this._listenViews&&this._listenViews[a].forEach(function(a){a&&a({data:b})})},b.prototype.set=function(a,b){this[a]=b},b.prototype.get=function(a){return this[a]||null}}("undefined"!=typeof c?c:this),function(a){function b(a,b){c.util.isObject(a)?Object.keys(a).forEach(function(b){this[b]=a[b]}.bind(this)):(this.element=a,c.util.isObject(b)&&Object.keys(b).forEach(function(a){this[a]=b[a]}.bind(this))),d.call(this),this._chainView=[]}var d=require("events").EventEmitter,e=require("util");b.make=function(a,b){var c;return c=a instanceof Element?a:(this.element||document).querySelector(a),new this.prototype.constructor(c,b)},b.extend=function(a){var c,d,f=a||{},g="function"==typeof this?this:this.constructor,h=function(){"function"==typeof g.prototype._construct&&g.prototype._construct.apply(this,arguments),this._construct&&this._construct.apply(this,arguments)};return e.inherits(h,this),Object.keys(f).forEach(function(a){h.prototype[a]=f[a]}),h.make=this.make,h.extend=this.extend,d=h.prototype.destroy,h.prototype.destroy=function(){"function"==typeof g.prototype.destroy&&g.prototype.destory.call(),"function"==typeof d&&d.call(this),this._chainView.forEach(function(a){a.destroy()})},c=h.prototype.appendTo,h.prototype.appendTo=function(a){a instanceof b&&(a._chainView.push(this),a=a.element),"function"==typeof c&&c.call(this,a)},h},e.inherits(b,d),b.prototype.listenTo=function(b,c,d){var e;switch(typeof d){case"string":e="function"==typeof this[d]?this[d].bind(this):null;break;case"function":e=d.bind(this);break;default:e=this.handleEvent?this.handleEvent.bind(this):null}b instanceof a.Model&&(b.listen(c,e),this[b.constructor.name]=b)},b.prototype.unlistenTo=function(b,c){b instanceof a.Model&&b.unlistenTo(this,c)},b.prototype.find=function(a){return this.element.querySelector(a)},b.prototype.findAll=function(a){return this.element.querySelectorAll(a)},b.prototype.appendTo=function(a){a.appendChild(this.element)},b.prototype.destroy=function(){},a.View=b}("undefined"!=typeof c?c:this),function(a){function b(){return c?c:(this.layer=null,this.createLayer(),c=this,void 0)}var c;b.prototype.show=function(){this.layer.style.display="block"},b.prototype.hide=function(){this.layer.style.display="none"},b.prototype.createLayer=function(){this.layer=document.createElement("div"),this.layer.setAttribute("id","guirunt-layer"),document.body.appendChild(this.layer)},b.prototype.addEventListener=function(a,b,c){this.layer.addEventListener(a,b,!!c)},b.prototype.removeEventListener=function(a,b){this.layer.removeEventListener(a,b)},a.Layer=b}("undefined"!=typeof c?c:this),d.boot=function(){c.storage.exists("Guirunt_initialized")||(console.log("Application is not initialized."),c.db._initDB(),c.storage.set("Guirunt_initialized",1))},d.initProject=function(a){return f.file.isDir(a)?(c.db.query("INSERT INTO projects VALUES (?)",[a]).success(function(){c.window.alert("Successfully added project.")}).failed(function(a){console.log(a.message)}),void 0):c.window.alert("ディレクトリではありません")},d.currentView=null,d.boot(),function(a){function b(){this.layer=new c.Layer,this.element=this.initModal(),this.message=this.element.querySelector("h3"),this.ok=this.element.getElementsByTagName("button")[0],this.cancel=this.element.getElementsByTagName("button")[1],this.lazy=null,this.blinkTimer=null,this.ok.addEventListener("click",this,!1),this.cancel.addEventListener("click",this,!1),this.layer.addEventListener("click",this,!1)}b.prototype.initModal=function(){var a,b=document,d=b.getElementById("modal");return d||(d=b.createElement("div"),d.setAttribute("id","modal"),a='<h3 class="message"></h3>',a+='<div class="buttons">',a+='<button class="ok widget-button"><span class="icon icon-ok"></span>OK</button>',a+='<button class="cancel widget-button"><span class="icon icon-cancel"></span>Cancel</button>',a+="</div>",d.innerHTML=a,b.body.appendChild(d),c.log("Modal element crated.")),d.style.display="none",d},b.prototype.dialog=function(a){return this.message.innerHTML=c.util.escape(a).replace("¥n","<br>"),this.cancel.style.display="none",this.element.style.display="block",this.layer.show(),this.lazy=new c.Lazy,this.lazy.promise()},b.prototype.confirm=function(a){return this.message.innerHTML=c.util.escape(a).replace("¥n","<br>"),this.cancel.style.display="inline-block",this.element.style.display="block",this.layer.hide(),this.lazy=new c.Lazy,this.lazy.promise()},b.prototype.handleEvent=function(a){this.lazy&&(c.util.hasClass(a.currentTarget,"ok")?(c.log("OK button clikced"),this.lazy.success(),this.element.style.display="none",this.layer.hide(),this.lazy=null):c.util.hasClass(a.currentTarget,"cancel")?(c.log("Cancel button clikced"),this.element.style.display="none",this.layer.hide(),this.lazy.failed(),this.lazy=null):"modalLayer"!==a.currentTarget.id||this.blinkTimer||(c.log("Layer clikced"),c.util.addClass(this.element,"notify"),this.blinkTimer=setTimeout(function(){c.util.removeClass(this.element,"notify"),this.blinkTimer=null}.bind(this),400)))},a.modal=new b}("undefined"!=typeof c?c:this),function(a){function b(a,b){this.width=a,this.height=b,this.box=null,f.call(this)}function d(a,d){this.options=c.util.mixin({filters:!0},d||{}),b.call(this),this.createBox(),this.createView(a)}var e=require("util"),f=require("events").EventEmitter;e.inherits(b,f),b.prototype.createBox=function(){this.box=document.createElement("div"),this.box.className="guirunt-popup",this.box.style.width="string"==typeof this.width?this.width:this.width+"px",this.box.style.height="string"==typeof this.height?this.height:this.height+"px",this.layer=new c.Layer,document.body.appendChild(this.box),this.layer.addEventListener("click",this,!1)},b.prototype.handleEvent=function(){this.layer.removeEventListener("click",this),this.hide()},b.prototype.show=function(){this.layer.show(),this.box.style.display="block"},b.prototype.hide=function(){this.layer.hide(),this.box.style.display="none"},b.prototype.destroy=function(){document.body.removeChild(this.box),this.box=null},b.prototype.insertContents=function(a){this.box.innerHTML=a},e.inherits(d,b),d.prototype.createView=function(a){this.listView=new g(a,{filters:!0}),this.listView.appendTo(this.box)},d.prototype.close=function(){this.listView.destroy(),this.destory()},a.SelectableList=d}("undefined"!=typeof c?c:this);var g=d.View.extend({_construct:function(a,b){this.list=a,this.listParent=null,c.util.mixin(this,b||{}),this.createList(),this.filters&&(this.filterView=new h(this.listParent.childNodes))},createList:function(){var a,b=document,c=b.createDocumentFragment(),d=b.createElement("ul");d.className="guirunt-listview",this.list.forEach(function(d){a=b.createElement("li"),a.appendChild(b.createTextNode(d)),"function"==typeof this.onGenerate&&this.onGenerate(a),c.appendChild(a)}.bind(this)),d.appendChild(c),d.addEventListener("click",this,!1),this.listParent=d},handleEvent:function(a){for(var b=a.target;b!==this.listParent&&!b.webkitMatchesSelector("ul.guirunt-listview > li");)b=b.parentNode;this.onClick&&this.onClick(a)},appendTo:function(a){this.filters&&this.filterView.appendTo(a),a.appendChild(this.listParent)},destroy:function(){this.filters&&this.filterView.destroy(),this.listParent.removeventListner("click",this),this.listParent.parentNote.removeChild(this.listParent)}}),h=d.View.extend({_construct:function(a){this.targets=[],this.factory(a),this.genComponent()},factory:function(a){var b=-1;for(a.length;a[++b];)this.targets.push([a[b].textContent,a[b]])},genComponent:function(){var a=document,b=a.createElement("section"),c=a.createElement("input");b.className="guirunt-listfilter",b.appendChild(c),c.type="text",c.name="q",c.value="",c.addEventListener("keyup",this,!1),this.input=c},handleEvent:function(a){var b,c=a.target.value,d=-1;for(this.targets.length;this.targets[++d];)b=this.targets[d],b[1].style.display=""===c||-1!==b[0].indexOf(c)?"block":"none"},appendTo:function(a){a.appendChild(this.input.parentNode),this.input.focus()},destroy:function(){this.input.removeEventListener("click",this),this.input.parentNode.parentNode.removeChild(this.input.parentNode)}});b.prototype.setUp=function(){var a=document;a.addEventListener("dragenter",this,!1),a.addEventListener("dragover",this,!1),a.addEventListener("dragleave",this,!1),this.layer.addEventListener("dragenter",this.cancelEvent,!1),this.layer.addEventListener("dragover",this.cancelEvent,!1),this.layer.addEventListener("dragleave",this,!1),this.layer.addEventListener("drop",this,!1),c.log("D&D Event setup completed.")},b.prototype.cancelEvent=function(a){a.preventDefault(),a.stopPropagation()},b.prototype.handleEvent=function(a){switch(a.type){case"dragenter":case"dragover":this.dragInit(a);break;case"dragleave":this.dragEnd(a);break;case"drop":this.dropFile(a)}},b.prototype.dragInit=function(){this.layer.show()},b.prototype.dragEnd=function(a){a.preventDefault(),(a.pageX<1||a.pageY<1)&&this.layer.hide()},b.prototype.dropFile=function(a){this.cancelEvent(a),this.layer.hide();for(var b=a.dataTransfer.files,c=-1;b[++c];)this.callback(b[c])};var i=d.Model.extend({_construct:function(){this.ddHandle=new b(this.addProject.bind(this))},addProject:function(a){var b=a.path;return f.file.isDir(b)?(this.checkGruntFile(b),void 0):c.modal.dialogalert("ドロップされたファイルはディレクトリではありません。")},addProjectFromFileSelect:function(a){var b=a.webkitRelativePath,c=a.path.slice(0,a.path.indexOf(b)),d=b.slice(0,b.indexOf("/"));this.addProject({path:c+d})},handleEvent:function(a){switch(a.type){case"change":this.addProjectFromFileSelect(a.target.files[0])}},checkGruntFile:function(a){f.file.exists(a+"/Gruntfile.js")?c.modal.confirm("すでにGruntfile.jsが存在します。¥n設定をインポートしますか?").success(function(){d.importConfig(require(a+"/Gruntfile.js")),this.checkPackageJSON(a)}.bind(this)).failed(function(){this.checkPackageJSON(a)}.bind(this)):this.checkPackageJSON(a)},checkPackageJSON:function(a){f.file.exists(a+"/package.json")?c.modal.dialog("package.jsonが見つかりました。¥n依存パッケージをインストールします。").success(function(){var b=new c.console;b.exec("npm install --prefix="+a).success(function(){this.createProject(a)}.bind(this))}.bind(this)):(c.log("TODO: implement intialize package.json"),this.createProject(a))},createProject:function(a){var b=require("path").basename(a);c.db.query("INSERT INTO projects (project_path, project_name) VALUES (?, ?)",[a,b]).success(function(){this.trigger("addProject",b),c.modal.dialog("Successfully added project.")}.bind(this)).failed(function(a){console.log(a.message)})},changeProject:function(a){this.currentProject=a,this.trigger("changeProject",a.getAttribute("data-projectname"))},getCurrentProject:function(){return this.currentProject},loadProjects:function(){var a=this;c.db.query("SELECT * FROM projects;").success(function(b){console.log(b),b.forEach(function(b){a.trigger("addProject",b.project_name)})})}}),j=new i,k=d.View.extend({_construct:function(){d.View.apply(this,arguments),this.trigger.addEventListener("change",this.switchView.bind(this),!1)},switchView:function(){c.util.addClass(this.element,"active"),d.currentView&&c.util.removeClass(d.currentView.element,"active"),d.currentView=this}});k.buttons=document.querySelectorAll(".widget-navi input[type=radio]");var l=(k.extend({_construct:function(){}}).make("#"+k.buttons[4].value,{trigger:k.buttons[4]}),k.extend({_construct:function(){}}));consoleView=new l(document.getElementById(k.buttons[3].value),{trigger:k.buttons[3]});var m=k.extend({_construct:function(){}}),n=(new m(document.getElementById(k.buttons[2].value),{trigger:k.buttons[2]}),k.extend({_construct:function(){this.head=this.element.querySelector("h1"),this.taskList=this.element.querySelector(".widget-task-list"),this.addTask=this.element.querySelector('button[data-role="addtask"]'),this.delTask=this.element.querySelector('button[data-role="deltask"]'),this.initialize()},initialize:function(){this.listenTo(j,"changeProject","handleChangeProject"),this.addTask.addEventListener("click",this.handleAddTask.bind(this),!1)},handleChangeProject:function(a){this.head.innerHTML='<span class="project-name">'+a.data+"</span> のタスク",c.db.query("SELECT task_name FROM project_tasks WHERE project_name = ?",[a.data]).success(function(a){this.createTaskList(a)}.bind(this)).failed(function(){this.createTaskList([])}.bind(this))},handleAddTask:function(){var a=new c.SelectableList(["hoge","huga","piyo"]),b=j.getCurrentProject();return b?(console.log(a),a.show(),void 0):a.destroy()},createTaskList:function(a){for(var b,c,d,e=this.taskList,f=document;e.firstChild;)e.removeChild(e.firstChild);a.forEach(function(a){b=f.createElement("label"),c=f.createElement("span"),d=f.createElement("input"),d.setAttribute("name","task"),d.setAttribute("type","radio"),c.className="label",c.appendChild(f.createTextNode(a)),b.appendChild(d),b.appendChild(c),b.setAttribute("data-taskname",a),e.appendChild(b)})}})),o=(new n(document.getElementById(k.buttons[1].value),{trigger:k.buttons[1]}),k.extend({_construct:function(){this.projectList=this.element.querySelector(".widget-project-list"),this.addProjectInput=this.element.querySelector("#add-project-btn"),this.listenTo(this.model,"addProject",function(a){this.createProjectNode(a.data)}.bind(this)),this.projectList.addEventListener("click",this.setProject.bind(this),!1),this.model.loadProjects(),this.initAddProjectEvent()},initAddProjectEvent:function(){var a=this.element.querySelector('button[data-role="addproject"]');this.addProjectInput.addEventListener("change",this.model,!1),a.addEventListener("click",this.selectFile.bind(this),!1)},selectFile:function(){var a=document.createEvent("MouseEvent");a.initEvent("click",!1,!1,!1),this.addProjectInput.dispatchEvent(a)},setProject:function(a){var b=a.target;/INPUT|SPAN/.test(b.tagName)&&(b=b.parentNode),this.model.set("currentProject",b)},createProjectNode:function(a){var b=document.createElement("label"),c=document.createElement("input"),d=document.createElement("span");c.type="radio",c.name="project",c.value=a,d.className="label",d.appendChild(document.createTextNode(a)),b.appendChild(c),b.appendChild(d),b.setAttribute("data-projectname",a),this.projectList.appendChild(b),1===this.projectList.childNodes.length&&this.model.changeProject(b)}})),p=new o(document.getElementById(k.buttons[0].value),{trigger:k.buttons[0],model:j});p.switchView(),d.boot()}(this);