Move BufferLine to models

This commit is contained in:
David Cormier 2013-10-07 20:43:09 -04:00
parent c538d759b8
commit ebecc5faae
2 changed files with 47 additions and 46 deletions

View file

@ -1,7 +1,47 @@
var models = angular.module('weechat-models'); var models = angular.module('weechatModels', []);
models.factory('models', function() { models.factory('models', ['colors', function(colors) {
function BufferLine(weechatBufferLine) {
/*
* Parse the text elements from the buffer line added
*
*/
function parseLineAddedTextElements(message) {
var prefix = colors.parse(message['objects'][0]['content'][0]['prefix']);
var buffer = message['objects'][0]['content'][0]['buffer'];
text_elements = _.union(prefix, text);
text_elements =_.map(text_elements, function(text_element) {
if ('fg' in text_element) {
text_element['fg'] = colors.prepareCss(text_element['fg']);
}
// TODO: parse background as well
return text_element;
});
return text_elements;
}
var buffer = message['objects'][0]['content'][0]['buffer'];
var date = message['objects'][0]['content'][0]['date'];
var text = colors.parse(message['objects'][0]['content'][0]['message']);
var content = parseLineAddedTextElements(message);
}); return {
content: content,
date: date,
buffer: buffer,
text: text[0]['text'],
}
}
return {
BufferLine: BufferLine
}
}]);

View file

@ -1,4 +1,4 @@
var weechat = angular.module('weechat', ['localStorage']); var weechat = angular.module('weechat', ['localStorage', 'weechatModels']);
weechat.factory('colors', [function($scope) { weechat.factory('colors', [function($scope) {
@ -191,57 +191,18 @@ weechat.factory('imagePlugin', [function() {
} }
}]); }]);
weechat.factory('handlers', ['$rootScope', 'colors', 'pluginManager', function($rootScope, colors, pluginManager) { weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'pluginManager', function($rootScope, colors, models, pluginManager) {
var handleBufferClosing = function(message) { var handleBufferClosing = function(message) {
var buffer_pointer = message['objects'][0]['content'][0]['pointers'][0]; var buffer_pointer = message['objects'][0]['content'][0]['pointers'][0];
$rootScope.closeBuffer(buffer_pointer); $rootScope.closeBuffer(buffer_pointer);
} }
function BufferLine(weechatBufferLine) {
/*
* Parse the text elements from the buffer line added
*
*/
function parseLineAddedTextElements(message) {
var prefix = colors.parse(message['objects'][0]['content'][0]['prefix']);
var buffer = message['objects'][0]['content'][0]['buffer'];
text_elements = _.union(prefix, text);
text_elements =_.map(text_elements, function(text_element) {
if ('fg' in text_element) {
text_element['fg'] = colors.prepareCss(text_element['fg']);
}
// TODO: parse background as well
return text_element;
});
return text_elements;
}
var buffer = message['objects'][0]['content'][0]['buffer'];
var date = message['objects'][0]['content'][0]['date'];
var text = colors.parse(message['objects'][0]['content'][0]['message']);
var content = parseLineAddedTextElements(message);
var additionalContent = pluginManager.contentForMessage(text[0]['text']);
return {
metadata: additionalContent,
content: content,
date: date,
buffer: buffer
}
}
var handleBufferLineAdded = function(message) { var handleBufferLineAdded = function(message) {
var buffer_line = {} var buffer_line = {}
message = new BufferLine(message); message = new models.BufferLine(message);
message.metadata = pluginManager.contentForMessage(message.text);
if (!_isActiveBuffer(message.buffer)) { if (!_isActiveBuffer(message.buffer)) {
$rootScope.buffers[message.buffer]['notification'] = true; $rootScope.buffers[message.buffer]['notification'] = true;