2015-01-20 10:25:10 +00:00
|
|
|
define([
|
|
|
|
'underscore',
|
|
|
|
'backbone'
|
|
|
|
], function(_, Backbone) {
|
|
|
|
'use strict';
|
|
|
|
|
2015-01-31 05:17:47 +00:00
|
|
|
var Repo = Backbone.Model.extend({
|
|
|
|
|
|
|
|
defaults: {
|
|
|
|
id: null,
|
|
|
|
name: "",
|
|
|
|
desc: "",
|
|
|
|
mtime: 0,
|
|
|
|
mtime_relative: "",
|
|
|
|
encrypted: false,
|
|
|
|
owner: "-",
|
|
|
|
owner_nickname: "-"
|
|
|
|
},
|
|
|
|
|
|
|
|
parse: function(response) {
|
|
|
|
var attrs = _.clone(response);
|
|
|
|
attrs.id = response.id || response.repo_id;
|
|
|
|
attrs.name = response.name || response.repo_name;
|
|
|
|
attrs.desc = response.desc || response.repo_desc;
|
|
|
|
return attrs;
|
|
|
|
},
|
|
|
|
|
|
|
|
validate: function(attrs, options) {
|
|
|
|
if (!attrs.name) return gettext("Name is required");
|
|
|
|
if (!attrs.desc) return gettext("Description is required");
|
|
|
|
|
|
|
|
if (attrs.encrypted) {
|
2015-03-20 05:48:40 +00:00
|
|
|
if (!attrs.passwd1) return gettext("Please enter password");
|
|
|
|
if (!attrs.passwd2) return gettext("Please enter the password again");
|
2015-03-19 08:06:20 +00:00
|
|
|
if (attrs.passwd1.length < app.pageOptions.repo_password_min_length) {
|
|
|
|
return gettext("Password is too short");
|
|
|
|
}
|
2015-01-31 05:17:47 +00:00
|
|
|
if (attrs.passwd1 != attrs.passwd2) return gettext("Passwords don't match");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2015-01-20 10:25:10 +00:00
|
|
|
|
|
|
|
return Repo;
|
|
|
|
});
|