Last active
December 12, 2015 00:58
-
-
Save JogoShugh/4687639 to your computer and use it in GitHub Desktop.
Just for Fun: CoffeeScript samples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loadMeta = (callback) -> | |
formSchema = {} | |
attributes = getSelectedAttributesNames() | |
$.ajax(metaUrl).done (data) -> | |
titleRequests = [] | |
attributeNames = _.map(attributes, (fieldName) -> | |
"Story." + fieldName | |
) | |
attribs = _.pick(data.Attributes, attributeNames) | |
_.each attribs, (item, index) -> | |
field = {} | |
mixThemInProps = v1AtttributeTypeToBackboneFormsFieldMap[item.AttributeType] | |
_.extend field, mixThemInProps | |
isRequired = item.IsRequired | |
if isRequired | |
field.validators = [] unless field.validators | |
field.validators.push "required" | |
formSchema[item.Name] = field | |
titleRequest = -> | |
formField = field | |
$.ajax(l10nUrl + "?" + item.DisplayName).done (data) -> | |
formField.title = data | |
titleRequests.push titleRequest | |
$.when.apply(null, titleRequests).done -> | |
callback() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadMeta(callback) { | |
formSchema = {}; | |
var attributes = getSelectedAttributesNames(); | |
$.ajax(metaUrl).done(function (data) { | |
var titleRequests = []; | |
var attributeNames = _.map(attributes, function (fieldName) { | |
return "Story." + fieldName; | |
}); | |
attribs = _.pick(data.Attributes, attributeNames); | |
_.each(attribs, function (item, index) { | |
var field = {}; | |
var mixThemInProps = v1AtttributeTypeToBackboneFormsFieldMap[item.AttributeType]; | |
_.extend(field, mixThemInProps); | |
var isRequired = item.IsRequired; | |
if (isRequired) { | |
if (!field.validators) { | |
field.validators = []; | |
} | |
field.validators.push("required"); | |
} | |
formSchema[item.Name] = field; | |
var titleRequest = function () { | |
var formField = field; | |
return $.ajax(l10nUrl + "?" + item.DisplayName).done(function (data) { | |
formField.title = data; | |
}); | |
}; | |
titleRequests.push(titleRequest); | |
}); | |
$.when.apply(null, titleRequests).done(function () { | |
callback(); | |
}); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define [ | |
'../modules/stdMortRatio', | |
'../modules/ciMedian', | |
'../modules/proportion' | |
] | |
, (args...) -> | |
modules = {} | |
modules[module.name] = module for module in args | |
return modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(-> | |
templateNames = ["input-text", "display-moduleList", "input-textarea", 'display-templatesList', 'display-templatesListItem'] | |
templateInsaneNames = ("text!../templates/" + name + ".jade" for name in templateNames) | |
define templateInsaneNames, (args...) -> | |
templates = {} | |
templates[templateNames[i]] = args[i] for i in [0..args.length] | |
return templates | |
)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var __slice = [].slice; | |
define(['../modules/stdMortRatio', '../modules/ciMedian', '../modules/proportion'], function() { | |
var args, module, modules, _i, _len; | |
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | |
modules = {}; | |
for (_i = 0, _len = args.length; _i < _len; _i++) { | |
module = args[_i]; | |
modules[module.name] = module; | |
} | |
return modules; | |
}); | |
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var __slice = [].slice; | |
(function() { | |
var name, templateInsaneNames, templateNames; | |
templateNames = ["input-text", "display-moduleList", "input-textarea", 'display-templatesList', 'display-templatesListItem']; | |
templateInsaneNames = (function() { | |
var _i, _len, _results; | |
_results = []; | |
for (_i = 0, _len = templateNames.length; _i < _len; _i++) { | |
name = templateNames[_i]; | |
_results.push("text!../templates/" + name + ".jade"); | |
} | |
return _results; | |
})(); | |
return define(templateInsaneNames, function() { | |
var args, i, templates, _i, _ref; | |
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | |
templates = {}; | |
for (i = _i = 0, _ref = args.length; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { | |
templates[templateNames[i]] = args[i]; | |
} | |
return templates; | |
}); | |
})(); | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment