Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/bf7095e67d38
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:26:33 2012
Кодировка: UTF-8

# HG changeset patch
# User boris
# Date 1284573912 -14400
# Node ID bf7095e67d38f1207ecaaa46bb0090414c27dacb
# Parent d0c6393ecc46032f124e505d283e610f207a7143
add class work-time

diff -r d0c6393ecc46 -r bf7095e67d38 blocks3d-wt.pro
--- a/blocks3d-wt.pro Wed Sep 15 21:47:55 2010 +0400
+++ b/blocks3d-wt.pro Wed Sep 15 22:05:12 2010 +0400
@@ -4,6 +4,7 @@
SOURCES += salt.C
SOURCES += blocks3d-wt.C
SOURCES += blocks3d-wt-widget.C
+SOURCES += work-time.C

CONFIG += debug
CONFIG += precompile_header
diff -r d0c6393ecc46 -r bf7095e67d38 files/js/.ajax.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/files/js/.ajax.js Wed Sep 15 22:05:12 2010 +0400
@@ -0,0 +1,393 @@
+
+
+ //////////////////////////////////////////////
+ //////////////////////////////////////////////
+ //// AJAX functions
+ //////////////////////////////////////////////
+ //////////////////////////////////////////////
+
+
+
+/*
+
+usage:
+
+1. Execute this JavaScript file
+
+2. Main function is
+ bajax(sURL, post_array, action, then)
+
+Arguments:
+
+ sURL - path to downloading file
+ GET parameters should be written here
+ example: "/php/info1.php?fu=123"
+
+ post_array - array with POST parameters and their values
+
+ variant 1:
+ example: ['fu','ttt', 'eee','rrr']
+ variant 2:
+ example: {'fu':'ttt', 'eee':'rrr'}
+
+ In this example two parameters wiil be sent:
+ fu = ttt, eee = rrr
+
+ action - a string with rules how to use downloaded text
+ 'return': function will be runned in not
+ asynchronous type and return this text (not Asynchronous)
+
+ 'eval': downloaded text will
+ be runned as JavaScript code (Asynchronous)
+
+ 'eval_sync': same, but not Asynchronous
+
+
+ Other:
+ downloaded text will be inserted in HTML element with id = action
+
+
+
+ then - this JavaScript code will be runned after using
+ downloaded text. It can be zero string.
+ It will not executed, if action = 'return'
+
+
+-------------
+
+Other functions to work:
+
+setHTML(sURL, then, kuda)
+ Set downloadedtext to element with id kuda and runns then
+
+myeval_post(sURL, then, what, value)
+ Analog of myeval, but it adds POST parameter what with value value :)
+
+loadHTML(sURL)
+ returns downloaded text
+
+
+myeval(sURL, then)
+ runns downloaded text and execute code from argument then
+*/
+
+// Возвращает document.getElementById
+function $(str)
+{
+ return document.getElementById(str);
+}
+
+
+
+
+
+// показать надпись, что идет загрузка
+function ajax_loading_show()
+{
+ if ($('ajax_loading'))
+ {
+ $('ajax_loading').style.visibility = '';
+ }
+}
+
+// спрятать надпись, что идет загрузка
+function ajax_loading_hide()
+{
+ if ($('ajax_loading'))
+ {
+ $('ajax_loading').style.visibility = 'hidden';
+ }
+}
+
+ajax_loading_hide();
+
+
+var bajax_killed = 0; // убит ли bajax
+
+// после выполнения этой функции bajax перестает работать
+function bajax_kill()
+{
+ bajax_killed = 1;
+
+ try
+ {
+ make_request_object = function(){return false;};
+ bajax = function(){return false;};
+ }
+ catch(e)
+ {
+ }
+}
+
+////////////////////////////////////////////////////////////
+// функция возвращает объект request
+////////////////////////////////////////////////////////////
+
+function make_request_object()
+{
+ var i;
+ var request = null;
+
+ var msxmlhttp =
+ [
+ //'Msxml2.XMLHTTP.5.0',
+ //'Msxml2.XMLHTTP.4.0',
+ //'Msxml2.XMLHTTP.3.0',
+ 'Msxml2.XMLHTTP',
+ 'Microsoft.XMLHTTP'
+ ];
+
+ for (i = 0; i < msxmlhttp.length; i++)
+ {
+ try
+ {
+ request = new ActiveXObject(msxmlhttp[i]);
+ }
+ catch (e)
+ {
+ request = null;
+ }
+
+ if (request)
+ {
+ break;
+ }
+ }
+
+ if (request)
+ {
+ return request;
+ }
+
+ try
+ {
+ request = new XMLHttpRequest();
+ }
+ catch (e)
+ {
+ }
+
+ return request;
+}
+
+
+
+////////////////////////////////////////////////////////////
+// универсальная AJAX-функция
+////////////////////////////////////////////////////////////
+
+function bajax(sURL, post_array, action, then)
+{
+
+ if (bajax_killed)
+ {
+ return '';
+ }
+
+ var i;
+ var post = '';
+ var request_type = 'GET';
+ var sURL1 = sURL;
+
+ var request = make_request_object();
+ var asynchronous = false;
+
+ if (!request)
+ {
+ return;
+ }
+
+ if (sURL.split('?').length==1)
+ {
+ sURL1 += '?';
+ }
+ else
+ {
+ if (sURL[sURL.length - 1] != '&')
+ {
+ sURL1 += '&';
+ }
+ }
+
+ sURL1 += 'ran='+Math.floor(Math.random() * 9999999);
+
+ if (action != 'return' && action != 'eval_sync')
+ {
+ asynchronous = true;
+
+ request.onreadystatechange = function()
+ {
+ if (request.readyState == 4)
+ {
+ //alert(sURL + "\n\n" + request.responseText);
+
+ // hide 'loading...'
+ ajax_loading_hide();
+
+ try
+ {
+ if (action == 'eval')
+ {
+ eval(request.responseText);
+ }
+ else
+ {
+ $(action).innerHTML = request.responseText;
+ }
+ }
+ catch (e)
+ {
+ }
+
+ if (then)
+ {
+ try
+ {
+ eval(then);
+ }
+ catch(e)
+ {
+ }
+ }
+ }
+ };
+ }
+
+
+
+ // если есть POST-данные, присобачим их
+ if (post_array)
+ {
+ var p, v;
+ request_type = 'POST';
+ if (post_array.length)
+ {
+ for (i = 0; i < post_array.length / 2; i++)
+ {
+ p = post_array[2 * i];
+ v = post_array[2 * i + 1];
+ if (!v)
+ {
+ continue;
+ }
+ post += p + "=" + encodeURIComponent(v + '') + '&';
+ }
+ }
+ else
+ {
+ for (p in post_array)
+ {
+ v = post_array[p];
+ if (!v)
+ {
+ continue;
+ }
+ post += p + "=" + encodeURIComponent(v + '') + '&';
+ }
+ }
+ }
+
+ // loading...
+ ajax_loading_show();
+
+ // делаем запрос
+ request.open(request_type, sURL1, asynchronous);
+
+ if (post_array)
+ {
+ //alert(post);
+
+ request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+ request.setRequestHeader("Content-Length", post.length);
+ request.send(post);
+ }
+ else
+ {
+ request.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
+ request.send(null);
+ }
+
+ if (action == 'return')
+ {
+ // hide 'loading...'
+ ajax_loading_hide();
+ return request.responseText;
+ }
+
+ if (action == 'eval_sync')
+ {
+ // hide 'loading...'
+ ajax_loading_hide();
+
+ try
+ {
+ eval(request.responseText);
+ }
+ catch (e)
+ {
+ }
+
+ if (then)
+ {
+ try
+ {
+ eval(then);
+ }
+ catch(e)
+ {
+ }
+ }
+ }
+}
+
+
+function gbajax(sURL, GET, POST, action, then)
+{
+ if (sURL.split('?').length==1)
+ {
+ sURL += '?';
+ }
+ else
+ {
+ sURL += '&';
+ }
+
+ for (k in GET)
+ {
+ sURL += encodeURIComponent(k + '') + '=' + encodeURIComponent(GET[k] + '') + '&';
+ }
+ return bajax(sURL, POST, action, then);
+}
+
+
+////////////////////////////////////////////////////////////
+// функция для выполнения содержимого файла из Интернет
+////////////////////////////////////////////////////////////
+function myeval(sURL, then)
+{
+ bajax(sURL, false, 'eval', then);
+}
+
+////////////////////////////////////////////////////////////////
+// функция присваивает элементу kuda значение файла из Интернет
+////////////////////////////////////////////////////////////////
+function setHTML(sURL, then, kuda)
+{
+ bajax(sURL, false, kuda, then);
+}
+
+////////////////////////////////////////////////////////////////
+// функция присваивает элементу kuda значение файла из Интернет
+////////////////////////////////////////////////////////////////
+
+function loadHTML(sURL)
+{
+ return bajax(sURL, false, 'return', false);
+}
+
+// функция для получения содержимого файла из Интернет
+function myeval_post(sURL, then, what, value)
+{
+ bajax(sURL, [what, value], 'eval', then);
+}
+
diff -r d0c6393ecc46 -r bf7095e67d38 files/js/.dollar.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/files/js/.dollar.js Wed Sep 15 22:05:12 2010 +0400
@@ -0,0 +1,11 @@
+function dollar(str)
+{
+ if (document.getElementById(str))
+ {
+ return document.getElementById(str);
+ }
+ else
+ {
+ return {};
+ }
+}
diff -r d0c6393ecc46 -r bf7095e67d38 files/js/countdown.js
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/files/js/countdown.js Wed Sep 15 22:05:12 2010 +0400
@@ -0,0 +1,73 @@
+
+function timer_div_id(id)
+{
+ return '#timer_' + id;
+}
+function timer_div(id)
+{
+ return $(timer_div_id(id));
+}
+
+//~ var started = realnow();
+
+var limits = {}; // index: product id
+function countdown_show(id)
+{
+ try
+ {
+ var delta = realnow() - limits[id][1];
+ var limit = limits[id][0] - delta;
+ if (limit < 0)
+ {
+ timer_div(id).html('...');
+ }
+ else
+ {
+ timer_div(id).html(cool_time(limit));
+ }
+ }
+ catch(e)
+ {
+ }
+}
+
+function countdown_show_all()
+{
+ var id;
+ for (id in limits)
+ {
+ countdown_show(id);
+ }
+}
+
+var timers = {};
+var prices_end = {};
+function set_countdown(product_id, now_left, price_end)
+{
+
+ if (prices_end[product_id] && prices_end[product_id] < price_end) {
+ $(timer_div_id(product_id)).css({opacity: 0}).animate({ opacity: 1}, 1000, "linear")
+ }
+ prices_end[product_id] = price_end;
+
+ limits[product_id] = [now_left, realnow()];
+
+ if (now_left && now_left + 5 > 0)
+ {
+ try
+ {
+ if (timers[product_id])
+ {
+ clearTimeout(timers[product_id]);
+ }
+ timers[product_id] = setTimeout('ajax_refresh(false)', (now_left + 0.1) * 1000);
+ }
+ catch(e)
+ {
+ }
+ }
+}
+
+
+setInterval('countdown_show_all()', 100);
+
diff -r d0c6393ecc46 -r bf7095e67d38 work-time.C
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/work-time.C Wed Sep 15 22:05:12 2010 +0400
@@ -0,0 +1,30 @@
+
+#include "work-time.h"
+#include
+#include
+
+
+Worktime::Worktime(Wt::WContainerWidget *parent) :
+ WText(parent)
+{
+ wApp->require("/files/js/jquery.countdown.pack.js");
+ start_at = now();
+ render();
+}
+
+std::string Worktime::int2time(posix::time_duration secs)
+{
+ posix::seconds secs1(secs.total_seconds());
+ return to_simple_string(secs1);
+}
+
+void Worktime::render()
+{
+ setText(int2time(spent()));
+
+ doJavaScript("$('#" + id() + "').countdown({"
+ "since: -" + boost::lexical_cast(
+ spent().total_milliseconds()) + " / 1000,"
+ "compact: true"
+ "});");
+};
diff -r d0c6393ecc46 -r bf7095e67d38 work-time.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/work-time.h Wed Sep 15 22:05:12 2010 +0400
@@ -0,0 +1,24 @@
+
+#ifndef WORKTIME_H_
+#define WORKTIME_H_
+
+#include
+#include
+
+#include
+namespace posix = boost::posix_time;
+
+class Worktime : public Wt::WText
+{
+public:
+ Worktime(Wt::WContainerWidget *parent=0);
+ void render();
+ inline posix::ptime now() { return posix::microsec_clock::universal_time(); }
+ inline posix::time_duration spent() { return now() - start_at; }
+private:
+ posix::ptime start_at;
+ std::string int2time(posix::time_duration secs);
+};
+
+
+#endif // WORKTIME_H_