UNPKG

1password

Version:
128 lines (102 loc) 3.63 kB
// Generated by CoffeeScript 1.6.3 (function() { var $, Vent, Views, template, _ref, _ref1, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; $ = require('./dom'); template = function(id) { return _.template($.id("" + id + "-template").innerHTML); }; Vent = _.extend(Backbone.Events); Views = { Item: (function(_super) { __extends(_Class, _super); function _Class() { this.render = __bind(this.render, this); this.select = __bind(this.select, this); _ref = _Class.__super__.constructor.apply(this, arguments); return _ref; } _Class.prototype.tagName = 'li'; _Class.prototype.template = template('item'); _Class.prototype.events = { 'click': 'select' }; _Class.prototype.select = function() { if (!this.model.detailsUnlocked) { this.model.unlock('details'); } return Vent.trigger('selectItem', this.model); }; _Class.prototype.render = function() { this.$el.html(this.template({ item: this.model })); return this; }; return _Class; })(Backbone.View), Main: (function(_super) { __extends(_Class, _super); function _Class() { this.listItems = __bind(this.listItems, this); this.showItem = __bind(this.showItem, this); this.keydown = __bind(this.keydown, this); _ref1 = _Class.__super__.constructor.apply(this, arguments); return _ref1; } _Class.prototype.el = $('.container'); _Class.prototype.template = template('item-info'); _Class.prototype.events = { 'keydown .locked input': 'keydown' }; _Class.prototype.initialize = function(keychain) { var _this = this; this.keychain = keychain; this.input = $('input.unlock'); this.table = $('.items'); this.content = $('.item-info'); Vent.on('selectItem', this.showItem); this.keychain.event.on('lock:after', function() { return $.addClass(_this.el, 'keychain-locked'); }); return this.keychain.event.on('unlock', function() { $.removeClass(_this.el, 'keychain-locked'); return _this.listItems(); }); }; _Class.prototype.keydown = function(e) { if (e.keyCode === 13) { return this.unlock(); } }; _Class.prototype.unlock = function() { var password; password = this.input.value; this.keychain.unlock(password); return this.input.value = ''; }; _Class.prototype.showItem = function(item) { this.keychain.rescheduleAutoLock(); return this.content.innerHTML = this.template({ item: item }); }; _Class.prototype.listItems = function() { var _this = this; this.table.innerHTML = ''; return this.keychain.eachItem(function(item) { var view; item.unlock('overview'); view = new Views.Item({ model: item }); return _this.table.appendChild(view.render().el); }); }; return _Class; })(Backbone.View) }; module.exports = Views; }).call(this);