Browse Source

Parametrização a partir de variáveis do block escola_modelo e outros ajustes

master
Matheus Garcia 6 years ago
parent
commit
127154db8e
  1. 5
      amd/src/config.js
  2. 4
      block_fale_conosco.php
  3. 4
      datatable.js
  4. BIN
      httpful.phar
  5. 3
      index.php
  6. 281
      indexyui.php
  7. 18
      proxy.php
  8. 4
      version.php

5
amd/src/config.js

@ -2,20 +2,19 @@ define(['jquery', 'js/jquery.dataTables.min.js', 'js/jquery-ui.min.js'] , functi
var exports = {}; var exports = {};
var answered = 1; var answered = 1;
var school = 'SSL';
var init = exports.init = function() { var init = exports.init = function() {
// Altera entre mensagens respondidas e não respondidas // Altera entre mensagens respondidas e não respondidas
$( "#id_situacao" ).change(function() { $( "#id_situacao" ).change(function() {
answered = $(this).val(); answered = $(this).val();
$("#id_situacao").val(answered); $("#id_situacao").val(answered);
tabelaContatos.ajax.url('proxy.php?schoolInitials=' + school +' + &answered=' + answered) tabelaContatos.ajax.url('proxy.php?answered=' + answered)
tabelaContatos.ajax.reload(); tabelaContatos.ajax.reload();
}); });
// Obtém dados de todas as conversas // Obtém dados de todas as conversas
var tabelaContatos = $('#tabela_contatos').DataTable({ var tabelaContatos = $('#tabela_contatos').DataTable({
ajax: { ajax: {
url: "proxy.php?schoolInitials=" + school + "&answered=" + 0, url: "proxy.php?answered=" + 0,
dataSrc:"" dataSrc:""
}, },
columns: [ columns: [

4
block_fale_conosco.php

@ -10,9 +10,7 @@ class block_fale_conosco extends block_base {
return $this->content; return $this->content;
} }
$this->content = new stdClass; $this->content = new stdClass;
$this->content->text = 'The content of our SimpleHTML block!';
$this->content->footer = 'Footer here...';
return $this->content; return $this->content;
} }

4
datatable.js

@ -1,4 +0,0 @@
YUI().use("datatable", "datasource-get", "datasource-jsonschema", "datatable-datasource", function(Y) {
});

BIN
httpful.phar

Binary file not shown.

3
index.php

@ -17,8 +17,6 @@ $PAGE->requires->css(new moodle_url('https://maxcdn.bootstrapcdn.com/bootstrap/3
$PAGE->requires->css(new moodle_url('https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css')); $PAGE->requires->css(new moodle_url('https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css'));
$PAGE->requires->css(new moodle_url('https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css')); $PAGE->requires->css(new moodle_url('https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css'));
$PAGE->set_context($context); $PAGE->set_context($context);
// Get data // Get data
@ -28,7 +26,6 @@ $user = $USER;
global $DB, $CFG, $USER; global $DB, $CFG, $USER;
echo $OUTPUT->header(); echo $OUTPUT->header();
// Print concluded courses // Print concluded courses

281
indexyui.php

@ -1,281 +0,0 @@
<?php
require_once("../../config.php");
require_once("./searchform.php");
include('httpful.phar');
// Check if user is logged and not guest
require_login();
if (isguestuser()) {
die();
}
global $DB;
// Prepare page
$context = context_system::instance();
$PAGE->set_pagelayout('standard');
$PAGE->set_url('/blocks/fale_conosco/index.php');
//$PAGE->requires->js('/blocks/fale_conosco/datatable.js', true);
$PAGE->set_context($context);
// Get data
$strtitle = get_string('fale_conosco', 'block_fale_conosco');
$user = $USER;
//$icon = $OUTPUT->pix_icon('print', get_string('print', 'block_fale_conosco'), 'block_fale_conosco');
global $DB, $CFG;
/*
$uri = 'https://escolamodelows.interlegis.leg.br/api/v1/fale_conosco';
$response = \Httpful\Request::get($uri)
//->sendsJson()
//->body('{"school_initial": "SSL"}')
->expectsJson()
->send();
$data=$response->body;
html_writer::span("<p>Quantidade" . count($data) . '</p>');
// Print the header
$PAGE->navbar->add($strtitle);
$PAGE->set_title($strtitle);
$PAGE->set_heading($strtitle);
*/
//$PAGE->requires->css('/blocks/fale_conosco/printstyle.css');
echo $OUTPUT->header();
// Print concluded courses
echo $OUTPUT->box_start('generalbox boxaligncenter');
echo $OUTPUT->heading(get_string('fale_conosco', 'block_fale_conosco'));
//Instantiate simplehtml_form
$mform = new searchform();
//Form processing and displaying is done here
if ($mform->is_cancelled()) {
//Handle form cancel operation, if cancel button is present on form
} else if ($fromform = $mform->get_data()) {
//In this case you process validated data. $mform->get_data() returns data posted in form.
} else {
// this branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
// or on the first display of the form.
//Set default data (if any)
//$mform->set_data($toform);
//displays the form
$mform->display();
}
/*
$table = new html_table();
$table->align = array('left', 'left', 'left', 'center');
$table->width = '100%';
$table->head = array(
get_string('id', 'block_fale_conosco'),
get_string('name', 'block_fale_conosco'),
get_string('email, block_fale_conosco'),
get_string('cpf', 'block_fale_conosco')
);
$table->data = $data;
echo html_writer::table($table);
*/
?>
<script>
YUI().use('datatable', 'datasource-io', 'datasource-get', 'datasource-local',
'datasource-jsonschema', 'datatable-paginator', 'tabview', 'escape', 'plugin',
function(Y){
var dataSource = new Y.DataSource.IO({
source:"proxy.php?zip=94089&query=chinese"
});
dataSource.plug(Y.Plugin.DataSourceJSONSchema, {
schema: {
resultListLocator: "",
resultFields: [
{key:"id"},
{key:"name"},
{key:"email"}
]
}
});
var cols = [
{key: "id"},//, sortable: true},
{key: "name"},//, sortable: true},
{key: 'email'}//, sortable: true}
];
var table = new Y.DataTable({
columns: cols,
rowsPerPage: 10,
//pageSizes: [ 4, 'Show All' ]
});
table.plug(Y.Plugin.DataTableDataSource, {
datasource: dataSource,
initialRequest: ""
});
table.addAttr("selectedRow", { value: null });
table.delegate('click', function (e) {
this.set('selectedRow', e.currentTarget);
}, '.yui3-datatable-data tr', table);
var tabview = new Y.TabView({
srcNode: '#demo',
}).render("#tabs");
table.after('selectedRowChange', function (e) {
var tr = e.newVal, // the Node for the TR clicked ...
last_tr = e.prevVal, // " " " the last TR clicked ...
rec = this.getRecord(tr); // the current Record for the clicked TR
//Y.log(rec.get('id'));
usuario = Y.one('#id_usuario'),
usuario.set('value', rec.get("id"));
var dataSourceContato = new Y.DataSource.IO({
source:"proxy.php?zip=94089&query=chinese"
});
dataSourceContato.plug(Y.Plugin.DataSourceJSONSchema, {
schema: {
resultListLocator: "",
resultFields: [
{key:"id"},
{key:"name"},
{key:"email"}
]
}
});
tabview.selectChild(1);
//
// This if-block does double duty,
// (a) it tracks the first click to toggle the "details" DIV to visible
// (b) it un-hightlights the last TR clicked
//
if ( !last_tr ) {
// first time thru ... display the Detail DT DIV that was hidden
//Y.one("#chars").show();
} else {
last_tr.removeClass("myhilite");
}
//
// After unhighlighting, now highlight the current TR
//
tr.addClass("myhilite");
});
dataSource.after("response", function() {
table.render("#datatable")}
);
});
</script>
<table id="grid-basic" class="table table-condensed table-hover table-striped">
<thead>
<tr>
<th data-column-id="id" data-type="numeric">ID</th>
<th data-column-id="sender">Sender</th>
<th data-column-id="received" data-order="desc">Received</th>
</tr>
</thead>
<tbody>
<tr>
<td>10238</td>
<td>eduardo@pingpong.com</td>
<td>14.10.2013</td>
</tr>
...
</tbody>
</table>
<style>
.yui3-skin-sam .yui3-datatable-caption {
font-size: 13px;
font-style: normal;
text-align: left;
}
.yui3-datatable-col-nchars {
text-align: center;
}
.yui3-skin-sam .yui3-datatable tr.myhilite td {
background-color: #C0ffc0;
}
#datatable tbody tr { /* Turn on cursor to show TR's are selectable on Master DataTable only */
cursor: pointer;
}
</style>
<div id="demo">
<ul>
<li><a href="#datatable">Tabela</a></li>
<li><a href="#datatable-item">Mensagem</a></li>
</ul>
<div>
<div class="yui3-u-1-3" id="datatable">
</div>
<div id="datatable-item">
<p>Mensagem específica</p>
</div>
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/r/dt/dt-1.10.9/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/r/dt/dt-1.10.9/datatables.min.js"></script>
<script>
var arrayReturn = [];
$.ajax({
url: "http://jsonplaceholder.typicode.com/posts",
async: false,
dataType: 'json',
success: function (data) {
for (var i = 0, len = data.length; i < len; i++) {
var desc = data[i].body;
arrayReturn.push([ data[i].userId, '<a href="http://google.com" target="_blank">'+data[i].title+'</a>', desc.substring(0, 12)]);
}
inittable(arrayReturn);
}
});
function inittable(data) {
//console.log(data);
$('#photos').DataTable( {
"aaData": data
} );
}
</script>
<table id="photos" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>User ID</th>
<th>Title</th>
<th>Body</th>
</tr>
</thead>
</table>
<?php
echo $OUTPUT->box_end();
echo $OUTPUT->footer();

18
proxy.php

@ -1,12 +1,12 @@
<?php <?php
include('httpful.phar'); include_once($CFG->dirroot . "/blocks/escola_modelo/lib/httpful.phar");
require_once("../../config.php"); require_once("../../config.php");
require_once($CFG->dirroot . "/blocks/escola_modelo/classes/util.php");
header("Content-Type: application/json"); header("Content-Type: application/json");
if(isset($_GET["conversationID"])) { if(isset($_GET["conversationID"])) {
$id = intval($_GET['conversationID']); $id = intval($_GET['conversationID']);
$uri = 'https://escolamodelows.interlegis.leg.br/api/v1/fale_conosco/mensagens'; $uri = evlURLWebServices() + '/api/v1/fale_conosco/mensagens';
// $uri = 'http://localhost:3000/api/v1/fale_conosco/mensagens';
$response = \Httpful\Request::post($uri) $response = \Httpful\Request::post($uri)
->sendsJson() ->sendsJson()
->body('{"conversation_id": "' . $id . '"}') ->body('{"conversation_id": "' . $id . '"}')
@ -16,8 +16,7 @@ if(isset($_GET["conversationID"])) {
$cpf = $USER->username; $cpf = $USER->username;
$description = $_GET['description']; $description = $_GET['description'];
$uri = 'https://escolamodelows.interlegis.leg.br/api/v1/fale_conosco/adicionar'; $uri = evlURLWebServices() + '/api/v1/fale_conosco/adicionar';
// $uri = 'http://localhost:3000/api/v1/fale_conosco/adicionar';
$response = \Httpful\Request::post($uri) $response = \Httpful\Request::post($uri)
->sendsJson() ->sendsJson()
->body('{ ->body('{
@ -29,21 +28,20 @@ if(isset($_GET["conversationID"])) {
"conversation_id": "' . $id . '" "conversation_id": "' . $id . '"
}') }')
->send(); ->send();
} elseif(isset($_REQUEST["schoolInitials"])) { } else {
$was_answered = intval($_GET['answered'])== 0 ? 'false':'true'; $was_answered = intval($_GET['answered'])== 0 ? 'false':'true';
$was_answered = trim($was_answered, '"'); $was_answered = trim($was_answered, '"');
$uri = 'https://escolamodelows.interlegis.leg.br/api/v1/fale_conosco/conversa'; $uri = evlURLWebServices() . '/api/v1/fale_conosco/conversa';
// $uri = 'http://localhost:3000/api/v1/fale_conosco/conversa';
$response = \Httpful\Request::post($uri) $response = \Httpful\Request::post($uri)
->sendsJson() ->sendsJson()
->body( ->body(
'{ '{
"school_initials": "SSL", "school_initials": "' . evlSiglaEscola() . '",
"page" : "1", "page" : "1",
"limit": "2000", "limit": "2000",
"was_answered": '. $was_answered .' "was_answered": '. $was_answered .'
}') }')
->send(); ->send();
} }
$data=$response->body; $data=$response->body;

4
version.php

@ -2,4 +2,8 @@
$plugin->component = 'block_fale_conosco'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494) $plugin->component = 'block_fale_conosco'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494)
$plugin->version = 2018092400; // YYYYMMDDHH (year, month, day, 24-hr time) $plugin->version = 2018092400; // YYYYMMDDHH (year, month, day, 24-hr time)
$plugin->requires = 2010112400; // YYYYMMDDHH (This is the release version for Moodle 2.0) $plugin->requires = 2010112400; // YYYYMMDDHH (This is the release version for Moodle 2.0)
$plugin->dependencies = array(
'block_escola_modelo' => ANY_VERSION
);

Loading…
Cancel
Save