# vim: set tabstop=2 shiftwidth=2 softtabstop=2 expandtab: class CloudKeys constructor: () -> @entities = [] @version = "" @password = '' #todo replace with user password $('#pw').focus().keyup (evt) => `var that = this` if evt.keyCode is 13 @password = $(that).val() $('#loader').removeClass('hide') @fetchData() $('#newEntityLink').click => @showForm() $('#passwordRequest').addClass('hide') $('#search').keyup => `var that = this` @limitItems(@getItems($(that).val())) return $('#search').focus() $(window).keyup (evt) => if evt.altKey is true and evt.keyCode is 66 if typeof window.copyToClipboard is "function" copyToClipboard($('#items li.active .username').val()) else $('#items li.active .username').focus().select() if evt.altKey is true and evt.keyCode is 79 # workaround to copy password very fast if typeof window.copyToClipboard is "function" copyToClipboard($('#items li.active .password').data('toggle')) else $('#items li.active .passwordtoggle em').click() $('#items li.active .password').focus().select() if evt.altKey is true and evt.keyCode is 80 if typeof window.copyToClipboard is "function" copyToClipboard($('#items li.active .password').data('toggle')) else $('#items li.active .password').focus().select() if evt.altKey is true and evt.keyCode is 85 if typeof window.copyToClipboard is "function" copyToClipboard($('#items li.active .url').val()) else $('#items li.active .url').focus().select() import: (xml) -> parsedXML = $.parseXML(xml) for group in $(parsedXML).find('group') tag = $(group).find('>title').text() for entry in $(group).find('entry') e = $(entry) entity = {} entity['title'] = e.find('title').text() entity['username'] = e.find('username').text() entity['password'] = e.find('password').text() entity['url'] = e.find('url').text() entity['comment'] = e.find('comment').text() entity['tags'] = tag @entities.push(entity) @updateData => $('#import').val('') $('#importLink').click() updateData: (callback) -> encrypted = @encrypt(JSON.stringify(@entities)) hash = CryptoJS.SHA1(encrypted).toString() $.post 'ajax', {'version': @version, 'checksum': hash, 'data': encrypted}, (result) => if result.error is true alert "An error occured, please reload and try it again" else if typeof callback isnt "undefined" callback() @updateInformation(result) , "json" fetchData: () -> $.get 'ajax', (data) => @updateInformation(data) , "json" updateInformation: (data) -> @version = data.version if data.data == "" @entities = [] else try @entities = $.parseJSON(@decrypt(data.data)) catch e window.location.reload() @entities.sort(@sortItems) @showItems(@getItems('')) @limitItems(@getItems($('#search').val())) encrypt: (value) -> return CryptoJS.AES.encrypt(value, @password).toString() decrypt: (value) -> return CryptoJS.AES.decrypt(value, @password).toString(CryptoJS.enc.Utf8) getClipboardCode: (value) -> cb = $('
') cb.click (e) -> elem = $("").css({ 'position': 'absolute', 'left': '-9999px', 'readonly': 'readonly', 'top': (window.pageYOffset || document.documentElement.scrollTop) + 'px' }) $("body").append(elem) elem.focus() elem.select() document.execCommand('copy') elem.remove() return return cb limitItems: (items) -> $('#resultdescription span').text(items.length) current = 0 $('#items>li').each (k, v) => item = $(v) item.removeClass('odd') if $.inArray(item.data('num'), items) is -1 item.addClass('hide') else if item.hasClass('hide') item.removeClass('hide') if current % 2 is 0 item.addClass('odd') current = current + 1 return return showItems: (items) -> $('#items li').remove() itemContainer = $('#items') $('#resultdescription span').text(items.length) for item, i in items additionalClass = "" if i % 2 is 0 additionalClass = "odd" item = @entities[item] c = $("