|
@@ 473-506 (lines=34) @@
|
| 470 |
|
* |
| 471 |
|
* @return void |
| 472 |
|
*/ |
| 473 |
|
protected function setupScriptForDefaultView($templateScript) |
| 474 |
|
{ |
| 475 |
|
$removeClass = NestedForm::REMOVE_FLAG_CLASS; |
| 476 |
|
$defaultKey = NestedForm::DEFAULT_KEY_NAME; |
| 477 |
|
|
| 478 |
|
/** |
| 479 |
|
* When add a new sub form, replace all element key in new sub form. |
| 480 |
|
* |
| 481 |
|
* @example comments[new___key__][title] => comments[new_{index}][title] |
| 482 |
|
* |
| 483 |
|
* {count} is increment number of current sub form count. |
| 484 |
|
*/ |
| 485 |
|
$script = <<<EOT |
| 486 |
|
var index = 0; |
| 487 |
|
$('#has-many-{$this->column}').on('click', '.add', function () { |
| 488 |
|
|
| 489 |
|
var tpl = $('template.{$this->column}-tpl'); |
| 490 |
|
|
| 491 |
|
index++; |
| 492 |
|
|
| 493 |
|
var template = tpl.html().replace(/{$defaultKey}/g, index); |
| 494 |
|
$('.has-many-{$this->column}-forms').append(template); |
| 495 |
|
{$templateScript} |
| 496 |
|
}); |
| 497 |
|
|
| 498 |
|
$('#has-many-{$this->column}').on('click', '.remove', function () { |
| 499 |
|
$(this).closest('.has-many-{$this->column}-form').hide(); |
| 500 |
|
$(this).closest('.has-many-{$this->column}-form').find('.$removeClass').val(1); |
| 501 |
|
}); |
| 502 |
|
|
| 503 |
|
EOT; |
| 504 |
|
|
| 505 |
|
Admin::script($script); |
| 506 |
|
} |
| 507 |
|
|
| 508 |
|
/** |
| 509 |
|
* Setup tab template script. |
|
@@ 515-561 (lines=47) @@
|
| 512 |
|
* |
| 513 |
|
* @return void |
| 514 |
|
*/ |
| 515 |
|
protected function setupScriptForTabView($templateScript) |
| 516 |
|
{ |
| 517 |
|
$removeClass = NestedForm::REMOVE_FLAG_CLASS; |
| 518 |
|
$defaultKey = NestedForm::DEFAULT_KEY_NAME; |
| 519 |
|
|
| 520 |
|
$script = <<<EOT |
| 521 |
|
|
| 522 |
|
$('#has-many-{$this->column} > .nav').off('click', 'i.close-tab').on('click', 'i.close-tab', function(){ |
| 523 |
|
var \$navTab = $(this).siblings('a'); |
| 524 |
|
var \$pane = $(\$navTab.attr('href')); |
| 525 |
|
if( \$pane.hasClass('new') ){ |
| 526 |
|
\$pane.remove(); |
| 527 |
|
}else{ |
| 528 |
|
\$pane.removeClass('active').find('.$removeClass').val(1); |
| 529 |
|
} |
| 530 |
|
if(\$navTab.closest('li').hasClass('active')){ |
| 531 |
|
\$navTab.closest('li').remove(); |
| 532 |
|
$('#has-many-{$this->column} > .nav > li:nth-child(1) > a').tab('show'); |
| 533 |
|
}else{ |
| 534 |
|
\$navTab.closest('li').remove(); |
| 535 |
|
} |
| 536 |
|
}); |
| 537 |
|
|
| 538 |
|
var index = 0; |
| 539 |
|
$('#has-many-{$this->column} > .header').off('click', '.add').on('click', '.add', function(){ |
| 540 |
|
index++; |
| 541 |
|
var navTabHtml = $('#has-many-{$this->column} > template.nav-tab-tpl').html().replace(/{$defaultKey}/g, index); |
| 542 |
|
var paneHtml = $('#has-many-{$this->column} > template.pane-tpl').html().replace(/{$defaultKey}/g, index); |
| 543 |
|
$('#has-many-{$this->column} > .nav').append(navTabHtml); |
| 544 |
|
$('#has-many-{$this->column} > .tab-content').append(paneHtml); |
| 545 |
|
$('#has-many-{$this->column} > .nav > li:last-child a').tab('show'); |
| 546 |
|
{$templateScript} |
| 547 |
|
}); |
| 548 |
|
|
| 549 |
|
if ($('.has-error').length) { |
| 550 |
|
$('.has-error').parent('.tab-pane').each(function () { |
| 551 |
|
var tabId = '#'+$(this).attr('id'); |
| 552 |
|
$('li a[href="'+tabId+'"] i').removeClass('hide'); |
| 553 |
|
}); |
| 554 |
|
|
| 555 |
|
var first = $('.has-error:first').parent().attr('id'); |
| 556 |
|
$('li a[href="#'+first+'"]').tab('show'); |
| 557 |
|
} |
| 558 |
|
EOT; |
| 559 |
|
|
| 560 |
|
Admin::script($script); |
| 561 |
|
} |
| 562 |
|
|
| 563 |
|
/** |
| 564 |
|
* Setup default template script. |
|
@@ 570-603 (lines=34) @@
|
| 567 |
|
* |
| 568 |
|
* @return void |
| 569 |
|
*/ |
| 570 |
|
protected function setupScriptForTableView($templateScript) |
| 571 |
|
{ |
| 572 |
|
$removeClass = NestedForm::REMOVE_FLAG_CLASS; |
| 573 |
|
$defaultKey = NestedForm::DEFAULT_KEY_NAME; |
| 574 |
|
|
| 575 |
|
/** |
| 576 |
|
* When add a new sub form, replace all element key in new sub form. |
| 577 |
|
* |
| 578 |
|
* @example comments[new___key__][title] => comments[new_{index}][title] |
| 579 |
|
* |
| 580 |
|
* {count} is increment number of current sub form count. |
| 581 |
|
*/ |
| 582 |
|
$script = <<<EOT |
| 583 |
|
var index = 0; |
| 584 |
|
$('#has-many-{$this->column}').on('click', '.add', function () { |
| 585 |
|
|
| 586 |
|
var tpl = $('template.{$this->column}-tpl'); |
| 587 |
|
|
| 588 |
|
index++; |
| 589 |
|
|
| 590 |
|
var template = tpl.html().replace(/{$defaultKey}/g, index); |
| 591 |
|
$('.has-many-{$this->column}-forms').append(template); |
| 592 |
|
{$templateScript} |
| 593 |
|
}); |
| 594 |
|
|
| 595 |
|
$('#has-many-{$this->column}').on('click', '.remove', function () { |
| 596 |
|
$(this).closest('.has-many-{$this->column}-form').hide(); |
| 597 |
|
$(this).closest('.has-many-{$this->column}-form').find('.$removeClass').val(1); |
| 598 |
|
}); |
| 599 |
|
|
| 600 |
|
EOT; |
| 601 |
|
|
| 602 |
|
Admin::script($script); |
| 603 |
|
} |
| 604 |
|
|
| 605 |
|
/** |
| 606 |
|
* Disable create button. |