ozserver
Version:
API for OZ
55 lines (44 loc) • 1.85 kB
JavaScript
var Edit, EventEmitter, Schema, exports, validate,
__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; };
validate = require('validate');
EventEmitter = require('events').EventEmitter;
Schema = require(global.home + '/script/views/validate/post');
Edit = (function(_super) {
__extends(Edit, _super);
function Edit(model) {
var _this = this;
this.model = model != null ? model : {};
this.on('success', function() {
_this.model.success = true;
return _this.model.notice = 'Сообщение успешно изменено';
});
this.on('userNotFound', function() {
_this.model.success = false;
return _this.model.notice = 'Не удалось найти информацию об авторе данного поста';
});
this.on('postNotFound', function() {
_this.model.success = false;
return _this.model.notice = 'Не удалось найти пост, который требуется изменить';
});
}
Edit.prototype.check = function() {
this.model.success = false;
this.model.message.text = this.model.message.text.toString().trim();
this.model.notice = validate(Schema, this.model);
if (Array.isArray(this.model.notice)) {
this.model.notice = this.model.notice[0].toString().replace('Error: ', '');
} else {
this.model.success = true;
}
return this.model.success;
};
return Edit;
})(EventEmitter);
exports = module.exports = function(model) {
if (model == null) {
model = {};
}
return new Edit(model);
};
exports.Edit = Edit;