Skip to content

Commit

Permalink
Web interface. Stable. Add s2 to rules. fintech-fab#12
Browse files Browse the repository at this point in the history
  • Loading branch information
devpull committed Aug 29, 2014
1 parent 2282bd4 commit 24e5b88
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 41 deletions.
1 change: 1 addition & 0 deletions workbench/fintech-fab/actions-calc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

###data###
data in: POST request
default route http://host.net/actions-calc

- terminal_id
- auth_sign
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public function manage()

$content = View::make('ff-actions-calc::calculator.manage')
->nest('_events', 'ff-actions-calc::calculator._events', ['events' => $oTerminal->events])
->nest('_rules', 'ff-actions-calc::calculator._rules', ['rules' => $oTerminal->rules])
->nest('_signals', 'ff-actions-calc::calculator._signals', ['signals' => $oTerminal->signals]);

$this->layout->content = $content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
class RuleController extends BaseController
{

/**
* Create rule.
* On GET sending view. On POST creating rule.
*
* @return string
*/
public function create()
{
if (Request::isMethod('GET')) {
Expand All @@ -40,7 +46,11 @@ public function create()
return json_encode(['status' => 'error', 'message' => 'Не удалось создать правило.']);
}

return json_encode(['status' => 'success', 'message' => 'Новое правило создано.']);
return json_encode([
'status' => 'success',
'message' => 'Новое правило создано.',
'data' => ['count' => $oEvent->count('id')]
]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ function (oData) {
$submit.closest('form').serialize(),
function (oData) {
if (oData.status == 'success') {
updRulesCountFromEvent(oData);
// finding rule_id passed to #modal-rule-create
var $ruleId = $('#modal-rule-create').find('input[name="event_id"]').val();
updateEventRules($ruleId);
$modalRuleCreate.foundation('reveal', 'close');
} else if (oData.status == 'error') {
revealFormErrors($submit.closest('form'), oData.errors);
Expand Down Expand Up @@ -455,6 +459,7 @@ function (oData) {
$th.closest('form').serialize(),
function (oData) {
if (oData.status == 'success') {
updateEventRules($ruleId);
$('#modal-rule-update').foundation('reveal', 'close');
} else if (oData.status == 'error') {
revealFormErrors($th.closest('form'), oData.errors);
Expand All @@ -463,6 +468,8 @@ function (oData) {
'json'
).always(function () {
buttonWakeUp($th);
}).fail(function (xhr) {
alert(xhr.responseText);
});

return false;
Expand All @@ -482,7 +489,7 @@ function (oData) {
function (oData) {
if (oData.status == 'success') { // success
// update event -> rules button counter
updateRulesCounter($th, oData);
updRulesCountFromRules($th, oData);
console.log($('button.see-rules').data('rules-count'));
// deleted, removing table records and opened rules, if exists
$thisRow.fadeOut();
Expand Down Expand Up @@ -622,15 +629,14 @@ function (oData) {
};

/**
* Update event table
* Update events table
*
* @returns {boolean}
*/
function updateEventsTable() {
var $eventTableContainer = $('#events-table-container');

$.get('/actions-calc/manage/update-events-table',
{},
function (oData) {
$eventTableContainer.html(oData);
},
Expand All @@ -641,7 +647,32 @@ function (oData) {
}

/**
* Update table row
* Get event rules
*
* @param id
*/
function updateEventRules(id) {
$.post(
'/actions-calc/manage/get-event-rules',
{event_id: id},
function (oData) {
var $eventsContainer = $('#events-table-container');
var $eventRulesTable = $eventsContainer.find('tr[data-event-rules=' + id + ']');

if ($eventRulesTable !== undefined) {
$eventRulesTable.find('#event-rules-wrap').replaceWith(oData);
}
},
'html'
).fail(function (xhr) {
alert(xhr.responseText);
});

return false;
}

/**
* Update event name and event_sid on update
* @param oData
*/
function updateRuleRow(oData) {
Expand Down Expand Up @@ -749,17 +780,32 @@ function typeFromString(string) {
}

/**
* Update rules counter inside see-rules button
* Update rules counter inside see-rules button, from rules table
*
* @param $th
* @param oData
*/
function updateRulesCounter($th, oData) {
function updRulesCountFromRules($th, oData) {
var $eventId = $th.closest('tr.event-rules-row').data('event-rules');
var $ruleRow = $('#events-rules').find('tr[data-id=' + $eventId + ']');
var $seeRules = $ruleRow.find('button.see-rules');

$seeRules.data('rules-count', oData.data.count);
$seeRules.find('span').text(oData.data.count);
}

/**
* Update rules counter inside see-rules button, from event
*
* @param oData
*/
function updRulesCountFromEvent(oData) {
var $eventId = $('#modal-rule-create').find('input[name="event_id"]').val();
var $ruleRow = $('#events-rules').find('tr[data-id=' + $eventId + ']');
var $seeRules = $ruleRow.find('button.see-rules');

$seeRules.data('rules-count', oData.data.count);
$seeRules.find('span').text(oData.data.count);
}

</script>
22 changes: 0 additions & 22 deletions workbench/fintech-fab/actions-calc/src/views/calculator/_rules.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div class="tabs-content">
<div class="content active" id="panel0-1">
<div id="events-container"><?php echo $_events; ?></div>
<div id="rules-container"><?php echo $_rules; ?></div>
<!-- <div id="rules-container">--><?php //echo $_rules; ?><!--</div>-->
</div>
<div class="content" id="panel0-2">
<div id="signals-container"><?php echo $_signals; ?></div>
Expand Down
10 changes: 0 additions & 10 deletions workbench/fintech-fab/actions-calc/src/views/rule/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@

{{ Form::hidden('event_id') }}

{{--<div class="row">--}}
{{--<div class="large-12 columns">--}}
{{--<div class="signal_id-field">--}}
{{--{{ Form::label('signal_id', 'Сигнал') }}--}}
{{--{{ Form::input('text', 'signal_id') }}--}}
{{--<small class="hide" id="signal_id-error">Сигнал обязателен.</small>--}}
{{--</div>--}}
{{--</div>--}}
{{--</div>--}}

<div class="row">
<div class="large-3 large-centered columns">
{{ Form::label('signal_id', 'Сигнал') }}
Expand Down

0 comments on commit 24e5b88

Please sign in to comment.