Browse Source

- Add support for 0050 - AdHoc with a new widget

- Fix little issues (scroll) in the Dialog widget
- Remove old commented sourcecode
- Fix a lot of issues in XMPPtoForm and FormtoXMPP
pull/16/head
Jaussoin Timothée 11 years ago
parent
commit
d6bf515a28
  1. 1
      app/views/conf.tpl
  2. 118
      app/widgets/AdHoc/AdHoc.php
  3. 32
      app/widgets/AdHoc/_adhoc_form.tpl
  4. 13
      app/widgets/AdHoc/_adhoc_list.tpl
  5. 8
      app/widgets/AdHoc/_adhoc_note.tpl
  6. 33
      app/widgets/AdHoc/adhoc.js
  7. 1
      app/widgets/AdHoc/adhoc.tpl
  8. 1
      app/widgets/AdHoc/locales.ini
  9. 2
      app/widgets/AdminMain/AdminMain.php
  10. 2
      app/widgets/Chats/_chats.tpl
  11. 2
      app/widgets/Chats/locales.ini
  12. 5
      app/widgets/Dialog/Dialog.php
  13. 4
      app/widgets/Dialog/dialog.js
  14. 4
      app/widgets/Menu/_menu_list.tpl
  15. 1
      app/widgets/Notification/notification.js
  16. 2
      app/widgets/Post/_post.tpl
  17. 24
      app/widgets/Presence/presence.js
  18. 63
      lib/XMPPtoForm.php
  19. 6
      linker.php
  20. 2
      locales/locales.ini
  21. 6
      themes/material/css/color.css
  22. 2
      themes/material/css/form.css
  23. 110
      themes/material/css/style.css

1
app/views/conf.tpl

@ -11,6 +11,7 @@
<?php $this->widget('Vcard4');?>
<?php $this->widget('Avatar');?>
<?php $this->widget('Config');?>
<?php $this->widget('AdHoc');?>
<?php //$this->widget('ConfigData');?>
<?php $this->widget('PubsubSubscriptionConfig');?>
</div>

118
app/widgets/AdHoc/AdHoc.php

@ -0,0 +1,118 @@
<?php
use Moxl\Xec\Action\AdHoc\Get;
use Moxl\Xec\Action\AdHoc\Command;
use Moxl\Xec\Action\AdHoc\Submit;
class AdHoc extends WidgetBase
{
function load()
{
$this->addjs('adhoc.js');
$this->registerEvent('adhoc_get_handle', 'onList');
$this->registerEvent('adhoc_command_handle', 'onCommand');
$this->registerEvent('adhoc_submit_handle', 'onCommand');
}
function onList($package)
{
$list = $package->content;
$html = $this->prepareList($list);
RPC::call('movim_fill', 'adhoc_widget', $html);
RPC::call('AdHoc.refresh');
}
function onCommand($package)
{
$command = $package->content;
$view = $this->tpl();
if(isset($command->note)) {
$view->assign('note', $command->note);
Dialog::fill($view->draw('_adhoc_note', true));
}
if(isset($command->x)) {
$xml = new \XMPPtoForm();
$form = $xml->getHTML($command->x->asXML());
$view->assign('form', $form);
$view->assign('attributes', $command->attributes());
$view->assign('actions', null);
if(isset($command->actions)) {
$view->assign('actions', $command->actions);
}
Dialog::fill($view->draw('_adhoc_form', true), true);
}
RPC::call('AdHoc.initForm');
}
function prepareList($list)
{
$view = $this->tpl();
$view->assign('list', $list);
return $view->draw('_adhoc_list', true);
}
function ajaxGet()
{
$session = \Sessionx::start();
$g = new Get;
$g->setTo($session->host)
->request();
}
function ajaxCommand($jid, $node)
{
$c = new Command;
$c->setTo($jid)
->setNode($node)
->request();
}
function ajaxSubmit($data, $node, $sessionid)
{
$session = \Sessionx::start();
$s = new Submit;
$s->setTo($session->host)
->setNode($node)
->setData($data)
->setSessionid($sessionid)
->request();
}
function getIcon($command)
{
$icons = array(
'http://jabber.org/protocol/admin#delete-user' => 'md-delete',
'http://jabber.org/protocol/admin#end-user-session' => 'md-stop',
'http://jabber.org/protocol/admin#change-user-password' => 'md-lock',
'ping' => 'md-swap-horiz',
'http://jabber.org/protocol/admin#shutdown' => 'md-settings-power',
'http://jabber.org/protocol/admin#add-user' => 'md-person-add',
'http://jabber.org/protocol/admin#user-stats' => 'md-people',
'uptime' => 'md-access-time',
'http://jabber.org/protocol/admin#server-buddy' => 'md-stop',
'http://jabber.org/protocol/admin#get-user-roster' => 'md-format-list-bulleted',
'http://jabber.org/protocol/admin#get-online-users' => 'md-trending-up',
'http://jabber.org/protocol/admin#announce' => 'md-notifications',
);
if(array_key_exists($command, $icons)) {
return $icons[$command];
} else {
return 'md-chevron-right';
}
}
function display()
{
}
}

32
app/widgets/AdHoc/_adhoc_form.tpl

@ -0,0 +1,32 @@
<section class="scroll">
<form name="command" data-sessionid="{$attributes->sessionid}" data-node="{$attributes->node}">
{$form}
</form>
</section>
<div>
<a onclick="Dialog.clear()" class="button flat">
{$c->__('button.close')}
</a>
{if="$actions != null"}
{if="isset($actions->next)"}
<a onclick="AdHoc.submit()" class="button flat">
{$c->__('button.next')}
</a>
{/if}
{if="isset($actions->previous)"}
<a onclick="" class="button flat">
{$c->__('button.previous')}
</a>
{/if}
{if="isset($actions->cancel)"}
<a onclick="" class="button flat">
{$c->__('button.cancel')}
</a>
{/if}
{if="isset($actions->complete)"}
<!--<a onclick="" class="button flat">
{$c->__('button.submit')}
</a>-->
{/if}
{/if}
</div>

13
app/widgets/AdHoc/_adhoc_list.tpl

@ -0,0 +1,13 @@
<ul class="divided active">
{loop="$list"}
<li class="action" data-node="{$value->attributes()->node}" data-jid="{$value->attributes()->jid}">
<span class="icon gray">
<i class="md {$c->getIcon((string)$value->attributes()->node)}"></i>
</span>
<div class="action">
<i class="md md-chevron-right"></i>
</div>
<span>{$value->attributes()->name}</span>
</li>
{/loop}
</ul>

8
app/widgets/AdHoc/_adhoc_note.tpl

@ -0,0 +1,8 @@
<section>
<h4 class="gray">{$note}</h4>
</section>
<div>
<a onclick="Dialog.clear()" class="button flat">
{$c->__('button.close')}
</a>
</div>

33
app/widgets/AdHoc/adhoc.js

@ -0,0 +1,33 @@
var AdHoc = {
refresh: function() {
var items = document.querySelectorAll('#adhoc_widget li');
var i = 0;
while(i < items.length)
{
items[i].onclick = function() {
AdHoc_ajaxCommand(this.dataset.jid, this.dataset.node);
};
i++;
}
},
initForm: function() {
var textareas = document.querySelectorAll('#dialog form[name=command] textarea');
var i = 0;
while(i < textareas.length)
{
movim_textarea_autoheight(textareas[i]);
i++;
}
},
submit: function() {
var form = document.querySelector('#dialog form[name=command]');
AdHoc_ajaxSubmit(movim_parse_form('command'), form.dataset.node, form.dataset.sessionid);
}
}
MovimWebsocket.attach(function() {
AdHoc_ajaxGet();
});

1
app/widgets/AdHoc/adhoc.tpl

@ -0,0 +1 @@
<div class="tabelem" title="{$c->__('adhoc.title')}" id="adhoc_widget" ></div>

1
app/widgets/AdHoc/locales.ini

@ -0,0 +1 @@
adhoc.title = 'Actions'

2
app/widgets/AdminMain/AdminMain.php

@ -25,7 +25,6 @@ class AdminMain extends WidgetBase
$config = $cd->get();
if(isset($form)) {
\movim_log(serialize($form));
if(isset($form['password'])
&& $form['password'] != '' && $form['repassword'] != ''
&& $form['password'] == $form['repassword']) {
@ -46,7 +45,6 @@ class AdminMain extends WidgetBase
$config->$key = $value;
}
\movim_log(serialize($config));
$cd->set($config);
//set timezone

2
app/widgets/Chats/_chats.tpl

@ -1,6 +1,6 @@
{if="$chats == null"}
<li class="condensed">
<span class="icon bubble color green"><i class="md md-chat"></i></span>
<span class="icon green"><i class="md md-chat"></i></span>
<p>{$c->__('chats.empty')}</p>
</li>
{/if}

2
app/widgets/Chats/locales.ini

@ -1,5 +1,5 @@
[chats]
chats.empty = 'Open a new conversation by clicking on the plus button in the header'
chats.empty = 'Open a new conversation by clicking on the plus button bellow'
chats.add = 'Chat with a contact'
[message]

5
app/widgets/Dialog/Dialog.php

@ -9,10 +9,11 @@ class Dialog extends WidgetBase
static function fill($html = '', $scroll = false)
{
RPC::call('movim_fill', 'dialog', $html);
if($scroll) {
RPC::call('Dialog.toggleScroll');
RPC::call('Dialog.addScroll');
}
RPC::call('movim_fill', 'dialog', $html);
}
function display()

4
app/widgets/Dialog/dialog.js

@ -1,6 +1,6 @@
var Dialog = {
toggleScroll : function() {
movim_toggle_class('#dialog', 'scroll');
addScroll : function() {
movim_add_class('#dialog', 'scroll');
},
filled : function() {
if(document.querySelector('#dialog').innerHTML != '') { return true; }

4
app/widgets/Menu/_menu_list.tpl

@ -7,7 +7,7 @@
{loop="$items"}
<li class="condensed" data-id="{$value->nodeid}"
{if="$value->title != null"}
title="{$value->title}"
title="{$value->title|strip_tags}"
{else}
title="{$c->__('menu.contact_post')}"
{/if}
@ -54,7 +54,7 @@
<br/>
<ul id="menu_wrapper">
<li class="condensed">
<span class="icon bubble color orange">
<span class="icon orange">
<i class="md md-format-align-left"></i>
</span>
<span>{$c->__('menu.empty_title')}</span>

1
app/widgets/Notification/notification.js

@ -21,7 +21,6 @@ var Notification = {
sec*1000);
},
refresh : function(keys) {
console.log(keys);
var counters = document.querySelectorAll('.counter');
for(i = 0; i < counters.length; i++) {
var n = counters[i];

2
app/widgets/Post/_post.tpl

@ -19,7 +19,7 @@
<span class="icon bubble color {$post->node|stringToColor}">{$post->node|firstLetterCapitalize}</span>
<!--</a>-->
{/if}
<span>
<span {if="$post->title != null"}title="{$post->title|strip_tags}"{/if}>
{if="$post->title != null"}
{$post->title}
{else}

24
app/widgets/Presence/presence.js

@ -12,37 +12,13 @@ function postStart() {
localStorage.postStart = 0;
}
}
/*
function setPresenceActions() {
var textarea = document.querySelector('textarea.status');
if(textarea != null) {
movim_textarea_autoheight(textarea);
textarea.onkeypress = function(event) {
if(event.keyCode == 13) {
Presence_ajaxSetStatus(this.value);
this.blur();
}
};
textarea.onfocus = function(event) {
movim_textarea_autoheight(this);
};
}
}
*/
var Presence = {
refresh : function() {
var textarea = document.querySelector('form[name=presence] textarea');
if(textarea != null) {
movim_textarea_autoheight(textarea);
/*textarea.onkeypress = function(event) {
if(event.keyCode == 13) {
Presence_ajaxSetStatus(this.value);
this.blur();
}
};*/
textarea.onkeydown = function(event) {
movim_textarea_autoheight(this);

63
lib/XMPPtoForm.php

@ -35,7 +35,7 @@ class XMPPtoForm{
break;
case "field":
if($element['type'] != 'hidden' && $element['type'] != 'fixed')
$this->html .='<div class="element">';
$this->html .='<div>';
switch($element['type']){
case "boolean":
$this->outCheckbox($element);
@ -134,26 +134,36 @@ class XMPPtoForm{
private function outCheckbox($s){
$this->html .= '
<input
id="'.$s['var'].'"
name="'.$s['var'].'"
type="'.$s['type'].'"
label="'.$s['label'].'"
type="checkbox" '.$s->required;
if($s->value == "true" || $s->value == "1")
$this->html .= ' checked';
$this->html .= '/>';
$this->html .= '
<label for="'.$s['var'].'">';
<ul class="simple">
<li class="action">
<span>';
if($s['label']==null){
$this->html .= $s['var'];
}
else{
$this->html .= $s['label'];
}
$this->html .= '
</label>';
$this->html .= '
</span>';
$this->html .= '
<div class="action">
<div class="checkbox">
<input
id="'.$s['var'].'"
name="'.$s['var'].'"
type="checkbox"
label="'.$s['label'].'"
type="checkbox" '.$s->required;
if($s->value == "true" || $s->value == "1")
$this->html .= ' checked';
$this->html .= '/>';
$this->html .= '
<label for="'.$s['var'].'"></label>
</div>
</div>
</li>
</ul>';
}
private function outTextarea($s){
@ -163,15 +173,17 @@ class XMPPtoForm{
name="'.$s["var"].'"
type="'.$s['type'].'"
label="'.$s['label'].'"
required="'.$s->required.'">
<label for="'.$s["var"].'">'.$s["label"].'</label>';
required="'.$s->required.'">';
foreach($s->children() as $value){
if($value->getName() == "value"){
$this->html .= $value;
$this->html .= $value. "\n";
}
}
$this->html .= '</textarea>';
$this->html .= '
<label for="'.$s["var"].'">'.$s["label"].'</label>';
}
private function outInput($s, $type, $multiple){
@ -278,6 +290,9 @@ class FormtoXMPP{
case "pubsub":
$node = $this->stream->configure->x;
break;
case "command":
$node = $this->stream->x;
break;
}
foreach($this->inputs as $key => $value) {
if($value === '' && $this->stream->getName() == "stream") {
@ -292,9 +307,9 @@ class FormtoXMPP{
$node->addChild($key, $value);
} elseif($value->attributes) {
$field = $node->addChild('field');
if($value == 'true')
if($value == 'true' || $value === 1)
$value = '1';
if($value == 'false')
if($value == 'false' || $value === 0)
$value = '0';
$field->addChild('value', trim($value->value));
@ -307,10 +322,14 @@ class FormtoXMPP{
} else{
$field = $node->addChild('field');
if($value == 'true' || $value === 1)
if($value == 'true')
$value = '1';
if($value == 'false' || $value === 0)
if($value == 'false')
$value = '0';
if(is_bool($value)) {
$value = ($value) ? '1' : '0';
}
$field->addChild('value', trim($value));
$field->addAttribute('var', trim($key));

6
linker.php

@ -45,7 +45,7 @@ $connector($config->websocketurl, array('xmpp'))->then(function($conn) use (&$st
$conn->on('message', function($message) use ($conn, $loop) {
if($message != '') {
#fwrite(STDERR, colorize($message, 'yellow')." : ".colorize('received', 'green')."\n");
fwrite(STDERR, colorize($message, 'yellow')." : ".colorize('received', 'green')."\n");
if($message == '</stream:stream>') {
$conn->close();
@ -76,7 +76,7 @@ $connector($config->websocketurl, array('xmpp'))->then(function($conn) use (&$st
}
if(!empty($xml)) {
#fwrite(STDERR, colorize(trim($xml), 'yellow')." : ".colorize('sent to XMPP', 'green')."\n");
fwrite(STDERR, colorize(trim($xml), 'yellow')." : ".colorize('sent to XMPP', 'green')."\n");
$conn->send(trim($xml));
}
}
@ -118,7 +118,7 @@ $connector($config->websocketurl, array('xmpp'))->then(function($conn) use (&$st
\Moxl\API::clear();
if(!empty($xml)) {
#fwrite(STDERR, colorize(trim($xml), 'yellow')." : ".colorize('sent to XMPP', 'green')."\n");
fwrite(STDERR, colorize(trim($xml), 'yellow')." : ".colorize('sent to XMPP', 'green')."\n");
$conn->send(trim($xml));
}

2
locales/locales.ini

@ -84,6 +84,8 @@ button.edit = 'Edit'
button.return = 'Return'
button.accept = 'Accept'
button.refuse = 'Refuse'
button.next = 'Next'
button.previous = 'Previous'
[step]
step.step = 'Step %s'

6
themes/material/css/color.css

@ -88,10 +88,12 @@ form textarea:focus + label {
color: #2196F3;
}
*/
form input:focus:invalid {
form input:focus:invalid,
form textarea:focus:invalid {
border-bottom-color: #F44336;
}
form input:focus:invalid + label {
form input:focus:invalid + label,
form textarea:focus:invalid + label {
color: #F44336;
}
/*

2
themes/material/css/form.css

@ -98,6 +98,8 @@ form > div > textarea {
margin-bottom: 1rem;
overflow: hidden; /* Fixme */
box-shadow: none; /* Firefox weird CSS */
}
/* Webkit hack */

110
themes/material/css/style.css

@ -302,99 +302,7 @@ main > header > div > span.active:hover {
display: none;
}
}
/*
main > header > div > span.action {
padding-left: 9rem;
}
main > header > div > span.action:hover {
background-color: rgba(0, 0, 0, 0.05);
}
*/
/*
main > header > div > a span.icon:hover,
main > header > div > span.icon:hover {
background-color: rgba(0, 0, 0, 0.05);
}
*/
/*
main > header {
position: relative;
min-height: 7rem;
padding-left: 9rem;
overflow: hidden;
color: white;
z-index: 2;
box-shadow: 0 0 0.5rem rgba(0, 0, 0, 0.5);
white-space: nowrap;
text-overflow: ellipsis;
}
main > header > * {
max-width: calc(25% - 7rem);
overflow: hidden;
}
*/
/* Two blocks*/
/*
main > header > div:first-child:nth-last-child(2) {
}
main > header > div:first-child:nth-last-child(2) ~ div {
max-width: 100%;
width: 75%;
position: absolute;
top: 0;
right: 0;
}
main > header h2 {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
@media screen and (max-width: 1024px) {
main > header > div {
width: 100%;
max-width: 100%;
}
main > header > div:first-child:nth-last-child(2) {
display: none;
}
main > header > div:first-child:nth-last-child(2) ~ div {
width: 100%;
}
}
main > header > div > form,
main > header > div > h2 {
max-width: calc(100% - 7rem);
}*/
/*
@media screen and (max-width: 1024px) {
main > header > form,
main > header > h2 {
max-width: calc(100% - 7rem);
}
}
*/
/*
main > header ul {
float: right;
}
main > header ul li {
float: left;
height: 7rem;
min-width: 0;
line-height: 7rem;
width: 7rem;
padding: 0;
font-size: 4rem;
}
*/
main > section {
height: 100%;
position: relative;
@ -579,11 +487,7 @@ main ul li .control > i {
}
/* Header */
/*
header .icon:hover {
cursor: pointer;
}
*/
header.big {
background-size: cover, cover;
background-position: center center;
@ -598,13 +502,7 @@ header.big {
header.big p {
color: white;
}
/*
@media screen and (max-width: 1024px) {
header.big {
min-height: 25rem;
}
}
*/
/* Dialog */
.dialog {
@ -653,6 +551,10 @@ header.big p {
padding: 0 2rem;
}
.dialog > section > form > ul > li {
padding: 0;
}
@media screen and (max-width: 600px) {
.dialog {
width: 90%;

Loading…
Cancel
Save