viewpoint
Version:
the exchange email API for nodejs module
132 lines (114 loc) • 3.91 kB
JavaScript
var Mixin, NAMESPACES, TypeMixin, camelCase, pascalCase, ref,
extend = 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; },
hasProp = {}.hasOwnProperty,
slice = [].slice;
Mixin = require('mixto');
ref = require('../ews-util'), pascalCase = ref.pascalCase, camelCase = ref.camelCase;
NAMESPACES = require('../ews-ns').NAMESPACES;
module.exports = TypeMixin = (function(superClass) {
extend(TypeMixin, superClass);
function TypeMixin() {
return TypeMixin.__super__.constructor.apply(this, arguments);
}
TypeMixin.prototype.getChildNode = function(methodName) {
return this.node.get("t:" + (pascalCase(methodName)), NAMESPACES);
};
TypeMixin.prototype.getChildValue = function(methodName) {
var element;
element = this.getChildNode(methodName);
if (element) {
return element.text();
}
};
TypeMixin.prototype.getChildIntValue = function(methodName) {
var element;
element = this.getChildNode(methodName);
if (element) {
return parseInt(element.text());
}
};
TypeMixin.prototype.getChildBoolValue = function(methodName) {
var element;
element = this.getChildNode(methodName);
if (element) {
return element.text() === 'true';
}
};
TypeMixin.prototype.getChildTimeValue = function(methodName) {
var element;
element = this.getChildNode(methodName);
if (element) {
return element.text();
}
};
TypeMixin.addBoolTextMethods = function() {
var methods;
methods = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return methods.forEach((function(_this) {
return function(methodName) {
return _this.prototype[methodName] = function() {
return this.getChildBoolValue(methodName);
};
};
})(this));
};
TypeMixin.addIntTextMethods = function() {
var methods;
methods = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return methods.forEach((function(_this) {
return function(methodName) {
return _this.prototype[methodName] = function() {
return this.getChildIntValue(methodName);
};
};
})(this));
};
TypeMixin.addTextMethods = function() {
var methods;
methods = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return methods.forEach((function(_this) {
return function(methodName) {
return _this.prototype[methodName] = function() {
return this.getChildValue(methodName);
};
};
})(this));
};
TypeMixin.addTimeTextMethods = function() {
var methods;
methods = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return methods.forEach((function(_this) {
return function(methodName) {
return _this.prototype[methodName] = function() {
return this.getChildTimeValue(methodName);
};
};
})(this));
};
TypeMixin.addAttrMethods = function() {
var methods;
methods = 1 <= arguments.length ? slice.call(arguments, 0) : [];
return methods.forEach((function(_this) {
return function(methodName) {
return _this.prototype[methodName] = function() {
var attrKey, attrVal, element, ref1, res, text;
element = this.getChildNode(methodName);
if (!element) {
return null;
}
res = {};
ref1 = element.attrVals();
for (attrKey in ref1) {
attrVal = ref1[attrKey];
res[camelCase(attrKey)] = attrVal;
}
if ((text = element.text())) {
res.content = text;
}
return res;
};
};
})(this));
};
return TypeMixin;
})(Mixin);