Create Thread Log JavaScript application

This commit is contained in:
Dmitriy Simushev 2013-02-04 11:19:40 +00:00
parent b4f99c1c18
commit 503c17352c
10 changed files with 146 additions and 28 deletions

View File

@ -16,6 +16,7 @@
default_app_js - Build JavaScript files related to default application
chat_app_js - Build JavaScript files related to chat application
thread_log_app_js - Build JavaScript files related to thread log application
users_app_js - Build JavaScript files related to users application
core_handlebars - Compile Handlebars templates of the Core
@ -272,6 +273,14 @@
<echo>Users JavaScript application built.</echo>
</target>
<!-- Compile and concatenate JavaScript files related to thread log application -->
<target name="thread_log_app_js" depends="default_app_js">
<antcall target="app_js">
<param name="app_name" value="thread_log" />
</antcall>
<echo>Thread log JavaScript application built.</echo>
</target>
<!-- Compile Handlebars templates of the Core -->
<target name="core_handlebars">
<echo>Compile Handlebars templates of the Core</echo>
@ -301,7 +310,7 @@
</target>
<!-- Build all project -->
<target name="all" depends="chat_app_js,users_app_js,styles_all">
<target name="all" depends="chat_app_js,thread_log_app_js,users_app_js,styles_all">
<echo>Mibew Messenger built.</echo>
</target>

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(b,c){var a=new c.Marionette.Application;a.addRegions({messagesRegion:"#messages-region"});a.addInitializer(function(c){a.messagesRegion.show(new b.Views.MessagesCollection({collection:new b.Collections.Messages(c.messages)}))});b.Application=a})(Mibew,Backbone);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a){a.Views.MessagesCollection=a.Views.CollectionBase.extend({itemView:a.Views.Message,className:"messages-collection"})})(Mibew);

View File

@ -0,0 +1,8 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(a,b){a.Collections.Messages=b.Collection.extend({model:a.Models.Message})})(Mibew,Backbone,_);

View File

@ -0,0 +1,3 @@
;(function(a,b){a.Collections.Messages=b.Collection.extend({model:a.Models.Message})})(Mibew,Backbone,_);
(function(a){a.Views.MessagesCollection=a.Views.CollectionBase.extend({itemView:a.Views.Message,className:"messages-collection"})})(Mibew);
(function(b,c){var a=new c.Marionette.Application;a.addRegions({messagesRegion:"#messages-region"});a.addInitializer(function(c){a.messagesRegion.show(new b.Views.MessagesCollection({collection:new b.Collections.Messages(c.messages)}))});b.Application=a})(Mibew,Backbone);

View File

@ -0,0 +1,27 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function (Mibew, Backbone) {
// Create application instance
var App = new Backbone.Marionette.Application();
// Define regions
App.addRegions({
messagesRegion: '#messages-region'
});
// Initialize application
App.addInitializer(function(options){
App.messagesRegion.show(new Mibew.Views.MessagesCollection({
collection: new Mibew.Collections.Messages(options.messages)
}));
});
Mibew.Application = App;
})(Mibew, Backbone);

View File

@ -0,0 +1,31 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew) {
/**
* @class Represents messages list view
*/
Mibew.Views.MessagesCollection = Mibew.Views.CollectionBase.extend(
/** @lends Mibew.Views.MessagesCollection.prototype */
{
/**
* Default item view constructor.
* @type Function
*/
itemView: Mibew.Views.Message,
/**
* Class name for view's DOM element
* @type String
*/
className: 'messages-collection'
}
);
})(Mibew);

View File

@ -0,0 +1,25 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Mibew, Backbone, _){
/**
* @class Represents messages list
*/
Mibew.Collections.Messages = Backbone.Collection.extend(
/** @lends Mibew.Collections.Message.prototype */
{
/**
* Default contructor for model
* @type Function
*/
model: Mibew.Models.Message
}
);
})(Mibew, Backbone, _);

View File

@ -53,12 +53,13 @@ if (isset($_GET['threadid'])) {
// Build messages list
$lastid = -1;
$messages = $thread_info['thread']->getMessages(false, $lastid);
foreach ($messages as $key => $msg) {
if ($msg['kind'] == Thread::KIND_AVATAR) {
unset($messages[$key]);
$result = array();
foreach ($messages as $msg) {
if ($msg['kind'] != Thread::KIND_AVATAR) {
$result[] = $msg;
}
}
$page['threadMessages'] = json_encode($messages);
$page['threadMessages'] = json_encode($result);
}
prepare_menu($operator, false);

View File

@ -18,24 +18,28 @@
$page['title'] = getlocal("thread.chat_log");
function tpl_header() { global $page, $webimroot; ?>
<script type="text/javascript" src="<?php echo($webimroot); ?>/js/compiled/common.js"></script>
<script type="text/javascript" src="<?php echo($webimroot); ?>/js/compiled/handlebars.js"></script>
<script type="text/javascript" src="<?php echo($webimroot); ?>/js/compiled/handlebars_helpers.js"></script>
<script type="text/javascript" src="<?php echo($webimroot); ?>/js/compiled/messageview.js"></script>
<script type="text/javascript" src="<?php echo($webimroot); ?>/js/templates/compiled/message.tpl.js"></script>
<!-- External libs -->
<script type="text/javascript" src="<?php echo $webimroot ?>/js/libs/jquery.min.js"></script>
<script type="text/javascript" src="<?php echo $webimroot ?>/js/libs/json2.js"></script>
<script type="text/javascript" src="<?php echo $webimroot ?>/js/libs/underscore-min.js"></script>
<script type="text/javascript" src="<?php echo $webimroot ?>/js/libs/backbone-min.js"></script>
<script type="text/javascript" src="<?php echo $webimroot ?>/js/libs/backbone.marionette.min.js"></script>
<script type="text/javascript" src="<?php echo $webimroot ?>/js/libs/handlebars.js"></script>
<!-- Application files -->
<script type="text/javascript" src="<?php echo $webimroot ?>/js/compiled/mibewapi.js"></script>
<script type="text/javascript" src="<?php echo $webimroot ?>/js/compiled/default_app.js"></script>
<script type="text/javascript" src="<?php echo $webimroot ?>/js/compiled/thread_log_app.js"></script>
<!-- Start application -->
<script type="text/javascript"><!--
EventHelper.register(window, 'onload', function() {
var threadMessages = <?php echo($page['threadMessages']); ?>;
var messageEl = document.getElementById('message');
var messageView = new MessageView();
for (var index in threadMessages) {
if (! threadMessages.hasOwnProperty(index)) {
continue;
}
messageEl.innerHTML += messageView.themeMessage(threadMessages[index]);
}
jQuery(document).ready(function(){
Mibew.Application.start({
messages: <?php echo($page['threadMessages']); ?>
});
});
// --></script>
//--></script>
<?php }
function tpl_content() { global $page, $webimroot, $errors;
@ -104,13 +108,7 @@ $chatthread = $page['thread_info']['thread'];
<br clear="all"/>
</div>
<div class="message" id="message">
<?php
foreach( $page['threadMessages'] as $message ) {
echo $message;
}
?>
</div>
<div class="message" id="messages-region"></div>
</div>
<br />