Revision 859a4609 ui/static/snf/js/models.js
b/ui/static/snf/js/models.js | ||
---|---|---|
105 | 105 |
}, |
106 | 106 |
|
107 | 107 |
fetch: function(options) { |
108 |
if (!options) { options = {} }; |
|
108 | 109 |
// default to update |
109 | 110 |
if (!this.noUpdate) { |
110 |
if (!options) { options = {} }; |
|
111 | 111 |
if (options.update === undefined) { options.update = true }; |
112 | 112 |
if (!options.removeMissing && options.refresh) { options.removeMissing = true }; |
113 |
} else { |
|
114 |
if (options.refresh === undefined) { |
|
115 |
options.refresh = true; |
|
116 |
} |
|
113 | 117 |
} |
114 | 118 |
// custom event foreach fetch |
115 | 119 |
return bb.Collection.prototype.fetch.call(this, options) |
116 | 120 |
}, |
117 | 121 |
|
122 |
create: function(model, options) { |
|
123 |
var coll = this; |
|
124 |
options || (options = {}); |
|
125 |
model = this._prepareModel(model, options); |
|
126 |
if (!model) return false; |
|
127 |
var success = options.success; |
|
128 |
options.success = function(nextModel, resp, xhr) { |
|
129 |
if (success) success(nextModel, resp, xhr); |
|
130 |
}; |
|
131 |
model.save(null, options); |
|
132 |
return model; |
|
133 |
}, |
|
134 |
|
|
118 | 135 |
get_fetcher: function(timeout, fast, limit, initial, params) { |
119 | 136 |
var fetch_params = params || {}; |
120 | 137 |
fetch_params.skips_timeouts = true; |
... | ... | |
1647 | 1664 |
}) |
1648 | 1665 |
|
1649 | 1666 |
models.PublicKey = models.Model.extend({ |
1650 |
path: 'keys/', |
|
1651 |
base_url: '/ui/userdata' |
|
1667 |
path: 'keys', |
|
1668 |
base_url: '/ui/userdata', |
|
1669 |
details: false, |
|
1670 |
noUpdate: true, |
|
1671 |
|
|
1672 |
|
|
1673 |
get_public_key: function() { |
|
1674 |
return cryptico.publicKeyFromString(this.get("content")); |
|
1675 |
}, |
|
1676 |
|
|
1677 |
get_filename: function() { |
|
1678 |
return "{0}.pub".format(this.get("name")); |
|
1679 |
}, |
|
1680 |
|
|
1681 |
identify_type: function() { |
|
1682 |
try { |
|
1683 |
var cont = snf.util.validatePublicKey(this.get("content")); |
|
1684 |
var type = cont.split(" ")[0]; |
|
1685 |
return synnefo.util.publicKeyTypesMap[type]; |
|
1686 |
} catch (err) { return false }; |
|
1687 |
} |
|
1688 |
|
|
1652 | 1689 |
}) |
1653 | 1690 |
|
1654 | 1691 |
models.PublicKeys = models.Collection.extend({ |
1655 |
path: 'keys/', |
|
1656 |
base_url: '/ui/userdata' |
|
1692 |
model: models.PublicKey, |
|
1693 |
details: false, |
|
1694 |
path: 'keys', |
|
1695 |
base_url: '/ui/userdata', |
|
1696 |
noUpdate: true, |
|
1697 |
|
|
1698 |
comparator: function(i) { return -parseInt(i.id || 0) }, |
|
1699 |
|
|
1700 |
generate_new: function(passphrase, length, save) { |
|
1701 |
|
|
1702 |
var passphrase = passphrase || ""; |
|
1703 |
var length = length || 1024; |
|
1704 |
var key = cryptico.generateRSAKey(passphrase, length); |
|
1705 |
|
|
1706 |
var b64enc = $.base64.encode; |
|
1707 |
return key; |
|
1708 |
}, |
|
1709 |
|
|
1710 |
add_crypto_key: function(key, success, error, options) { |
|
1711 |
var options = options || {}; |
|
1712 |
var m = new models.PublicKey(); |
|
1713 |
var name_tpl = "public key"; |
|
1714 |
var name = name_tpl; |
|
1715 |
var name_count = 1; |
|
1716 |
|
|
1717 |
while(this.filter(function(m){ return m.get("name") == name }).length > 0) { |
|
1718 |
name = name_tpl + " " + name_count; |
|
1719 |
name_count++; |
|
1720 |
} |
|
1721 |
|
|
1722 |
m.set({name: name}); |
|
1723 |
m.set({content: "ssh-rsa AAAAB3NzaC1yc2EA" + cryptico.publicKeyString(key)}); |
|
1724 |
|
|
1725 |
options.success = function () { return success(m) }; |
|
1726 |
options.errror = error; |
|
1727 |
|
|
1728 |
this.create(m.attributes, options); |
|
1729 |
} |
|
1657 | 1730 |
}) |
1658 | 1731 |
|
1659 |
|
|
1660 | 1732 |
// storage initialization |
1661 | 1733 |
snf.storage.images = new models.Images(); |
1662 | 1734 |
snf.storage.flavors = new models.Flavors(); |
Also available in: Unified diff