Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 1091 | Rev 1093 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1091 Rev 1092
Línea 406... Línea 406...
406
        $('#row-form').hide();
406
        $('#row-form').hide();
407
        $('#row-lists').show();
407
        $('#row-lists').show();
408
        return;
408
        return;
409
    });
409
    });
410
    /**
410
    /**
411
     * Clicked save and close new/edit Form
411
     * Clicked save and continue new Form
412
     */
412
     */
413
    $('button.btn-form-save-close').click(function(e) {
413
    $('button.btn-form-save-continue').click(function(e) {
414
 
-
 
415
        for (var instanceName in CKEDITOR.instances) {
414
        for (var instanceName in CKEDITOR.instances) {
416
            CKEDITOR.instances[instanceName].updateElement();
415
            CKEDITOR.instances[instanceName].updateElement();
417
        }
416
        }
418
 
-
 
419
        if ($('#form-name').val() == '') {
417
        if ($('#form-name').val() == '') {
420
            $.fn.showError('ERROR_ENTER_NAME');
418
            $.fn.showError('ERROR_ENTER_NAME');
421
        } else if ($('#form-description').val() == '') {
419
        } else if ($('#form-description').val() == '') {
422
            $.fn.showError('ERROR_ENTER_DESCRIPTION');
420
            $.fn.showError('ERROR_ENTER_DESCRIPTION');
423
        } else if ($('#form-text').val() == '') {
421
        } else if ($('#form-text').val() == '') {
Línea 427... Línea 425...
427
        } else if ($('#job_description_id').val() == '') {
425
        } else if ($('#job_description_id').val() == '') {
428
            $.fn.showError('ERROR_SELECT_JOB_DESCRIPTION');
426
            $.fn.showError('ERROR_SELECT_JOB_DESCRIPTION');
429
        } else if (sections.length == 0) {
427
        } else if (sections.length == 0) {
430
            $.fn.showError('ERROR_NOT_SECTIONS');
428
            $.fn.showError('ERROR_NOT_SECTIONS');
431
        } else {
429
        } else {
432
 
-
 
433
            $.ajax({
430
            $.ajax({
434
                'dataType': 'json',
431
                'dataType': 'json',
435
                'method': 'post',
432
                'method': 'post',
436
                'url': $('#form-main').attr('action'),
433
                'url': $('#form-main').attr('action'),
437
                'data': {
434
                'data': {
Línea 443... Línea 440...
443
                    'content': JSON.stringify(sections)
440
                    'content': JSON.stringify(sections)
444
                },
441
                },
445
            }).done(function(response) {
442
            }).done(function(response) {
446
                if (response['success']) {
443
                if (response['success']) {
447
                    $.fn.showSuccess(response['data']);
444
                    $.fn.showSuccess(response['data']);
448
                    $('#row-form').hide();
-
 
449
                    $('#row-lists').show();
445
                    $('#form-main').attr('action', response['action_edit']);
450
                    /*---------- Reset Form -------- */
-
 
451
                    $('#form-main')[0].reset();
446
                    $('#form-main #form-id').val(response['id']);
452
                    /*--------Reset Sections ----------*/
-
 
453
                    sections = [];
-
 
454
                    tableForm.fnDraw();
-
 
455
                    return;
447
                    return;
456
                } else {
448
                } else {
457
                    $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
449
                    $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
458
                    return;
450
                    return;
459
                }
451
                }
460
            });
452
            });
461
        }
453
        }
462
    });
454
    });
463
    /**
-
 
464
     * Remove Html Tags
-
 
465
     */
-
 
466
    const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')
-
 
467
    /**
-
 
468
     * Render Sections data
-
 
469
     */
-
 
470
    const renderData = (data) => {
-
 
471
        $("#rows").html($("#sectionTemplate").render(data));
-
 
472
    }
455
});
473
    /**
-
 
474
     * Add Section to array
-
 
475
     */
-
 
476
    const addSection = (title, text, type) => {
-
 
477
        sections.push({
-
 
478
            'id_section': new Date().getTime(),
-
 
479
            'title': title,
-
 
480
            'type': type,
-
 
481
            'text': text,
-
 
482
            'options': []
-
 
483
        });
-
 
484
        return renderData(sections);
-
 
485
    }
-
 
486
    /**
-
 
487
     * Edit item behavior
-
 
488
     */
-
 
489
    const editSection = (id, title, text, type) => {
-
 
490
        sections.map((item) => {
-
 
491
            if (item.id_section == id) {
-
 
492
                item.title = title;
-
 
493
                item.type = type;
-
 
494
                item.text = text;
-
 
495
            }
-
 
496
        });
-
 
497
        return renderData(sections);
-
 
498
    }
-
 
499
    /**
456
/**
500
     * Remove behavior
-
 
501
     */
-
 
502
    const removeSection = (id) => {
457
 * Clicked save and close new/edit Form
503
        sections = sections.filter((item) => item.id_section != id);
-
 
504
        return renderData(sections);
-
 
505
    }
-
 
506
    /**
-
 
507
     * Add Option to array
-
 
508
     */
458
 */
509
    const addOption = (id_section, title) => {
459
$('button.btn-form-save-close').click(function(e) {
510
        sections.map((item) => {
-
 
511
            if (item.id_section == id_section) {
460
    for (var instanceName in CKEDITOR.instances) {
512
                item.options.push({
-
 
513
                    'id_section': id_section,
-
 
514
                    'id_option': new Date().getTime(),
461
        CKEDITOR.instances[instanceName].updateElement();
515
                    'title': title,
-
 
516
                });
-
 
517
            }
-
 
518
        });
-
 
519
        return renderData(sections);
-
 
520
    }
-
 
521
    /**
-
 
522
     * Edit item Option
-
 
523
     */
-
 
524
    const editOption = (id_section, id, title) => {
-
 
525
        sections.map((item) => {
-
 
526
            if (item.id_section == id_section) {
-
 
527
                item.options.map((opt) => {
-
 
528
                    if (opt.id_option == id) {
-
 
529
                        opt.title = title
-
 
530
                    }
-
 
531
                });
-
 
532
            }
-
 
533
        });
-
 
534
        return renderData(sections);
-
 
535
    }
462
    }
-
 
463
    if ($('#form-name').val() == '') {
-
 
464
        $.fn.showError('ERROR_ENTER_NAME');
-
 
465
    } else if ($('#form-description').val() == '') {
-
 
466
        $.fn.showError('ERROR_ENTER_DESCRIPTION');
-
 
467
    } else if ($('#form-text').val() == '') {
-
 
468
        $.fn.showError('ERROR_ENTER_TEXT');
-
 
469
    } else if ($('#form-status').val() == '') {
-
 
470
        $.fn.showError('ERROR_SELECT_STATUS');
-
 
471
    } else if ($('#job_description_id').val() == '') {
-
 
472
        $.fn.showError('ERROR_SELECT_JOB_DESCRIPTION');
-
 
473
    } else if (sections.length == 0) {
-
 
474
        $.fn.showError('ERROR_NOT_SECTIONS');
536
    /**
475
    } else {
-
 
476
        $.ajax({
-
 
477
            'dataType': 'json',
-
 
478
            'method': 'post',
-
 
479
            'url': $('#form-main').attr('action'),
537
     * Remove Option
480
            'data': {
-
 
481
                'name': $('#form-main #form-name').val(),
-
 
482
                'job_description_id': $('#form-main #job_description_id').val(),
-
 
483
                'status': $('#form-main #form-status').val(),
-
 
484
                'description': $('#form-main #form-description').val(),
-
 
485
                'text': $('#form-main #form-text').val(),
-
 
486
                'content': JSON.stringify(sections)
538
     */
487
            },
539
    const removeOption = (id_section, id) => {
488
        }).done(function(response) {
540
        sections.map((item) => {
489
            if (response['success']) {
-
 
490
                $.fn.showSuccess(response['data']);
-
 
491
                $('#row-form').hide();
-
 
492
                $('#row-lists').show();
-
 
493
                /*---------- Reset Form -------- */
541
            if (item.id_section == id_section) {
494
                $('#form-main')[0].reset();
-
 
495
                /*--------Reset Sections ----------*/
-
 
496
                sections = [];
-
 
497
                tableForm.fnDraw();
-
 
498
                return;
-
 
499
            } else {
542
                item.options = item.options.filter((opt) => opt.id_option != id) || []
500
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
-
 
501
                return;
543
            }
502
            }
544
        });
503
        });
545
        return renderData(sections);
-
 
546
    }
504
    }
-
 
505
});
-
 
506
/**
-
 
507
 * Remove Html Tags
-
 
508
 */
-
 
509
const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')
-
 
510
/**
-
 
511
 * Render Sections data
-
 
512
 */
-
 
513
const renderData = (data) => {
-
 
514
    $("#rows").html($("#sectionTemplate").render(data));
-
 
515
}
-
 
516
/**
-
 
517
 * Add Section to array
-
 
518
 */
-
 
519
const addSection = (title, text, type) => {
-
 
520
    sections.push({
-
 
521
        'id_section': new Date().getTime(),
-
 
522
        'title': title,
-
 
523
        'type': type,
-
 
524
        'text': text,
-
 
525
        'options': []
547
    /**
526
    });
-
 
527
    return renderData(sections);
-
 
528
}
-
 
529
/**
-
 
530
 * Edit item behavior
-
 
531
 */
-
 
532
const editSection = (id, title, text, type) => {
-
 
533
    sections.map((item) => {
-
 
534
        if (item.id_section == id) {
548
     * Clicked refresh button
535
            item.title = title;
-
 
536
            item.type = type;
-
 
537
            item.text = text;
-
 
538
        }
549
     */
539
    });
-
 
540
    return renderData(sections);
-
 
541
}
-
 
542
/**
-
 
543
 * Remove behavior
-
 
544
 */
-
 
545
const removeSection = (id) => {
-
 
546
    sections = sections.filter((item) => item.id_section != id);
-
 
547
    return renderData(sections);
-
 
548
}
-
 
549
/**
-
 
550
 * Add Option to array
-
 
551
 */
-
 
552
const addOption = (id_section, title) => {
-
 
553
    sections.map((item) => {
550
    $('button.btn-refresh').click(function(e) {
554
        if (item.id_section == id_section) {
551
        tableForm.fnDraw();
555
            item.options.push({
-
 
556
                'id_section': id_section,
-
 
557
                'id_option': new Date().getTime(),
-
 
558
                'title': title,
-
 
559
            });
-
 
560
        }
-
 
561
    });
-
 
562
    return renderData(sections);
-
 
563
}
-
 
564
/**
-
 
565
 * Edit item Option
-
 
566
 */
-
 
567
const editOption = (id_section, id, title) => {
-
 
568
    sections.map((item) => {
-
 
569
        if (item.id_section == id_section) {
-
 
570
            item.options.map((opt) => {
-
 
571
                if (opt.id_option == id) {
-
 
572
                    opt.title = title
-
 
573
                }
552
        return;
574
            });
-
 
575
        }
-
 
576
    });
-
 
577
    return renderData(sections);
-
 
578
}
-
 
579
/**
-
 
580
 * Remove Option
-
 
581
 */
-
 
582
const removeOption = (id_section, id) => {
-
 
583
    sections.map((item) => {
-
 
584
        if (item.id_section == id_section) {
-
 
585
            item.options = item.options.filter((opt) => opt.id_option != id) || []
-
 
586
        }
553
    });
587
    });
-
 
588
    return renderData(sections);
-
 
589
}
-
 
590
/**
-
 
591
 * Clicked refresh button
-
 
592
 */
-
 
593
$('button.btn-refresh').click(function(e) {
-
 
594
tableForm.fnDraw();
-
 
595
return;
-
 
596
});
554
});
597
});
555
JS;
598
JS;
-
 
599
 
556
$this->inlineScript()->captureEnd();
600
$this->inlineScript()->captureEnd();
557
?>
601
?>
558
<!-- Content Header (Page header) -->
602
<!-- Content Header (Page header) -->
559
<section class="content-header">
603
<section class="content-header">
560
   <div class="container-fluid">
604
   <div class="container-fluid">
Línea 598... Línea 642...
598
   </div>
642
   </div>
599
   <!-- Create/Edit Form -->
643
   <!-- Create/Edit Form -->
600
   <div class="row" id="row-form" style="display: none; padding: 16px;">
644
   <div class="row" id="row-form" style="display: none; padding: 16px;">
601
      <div class="col-xs-12 col-md-12">
645
      <div class="col-xs-12 col-md-12">
602
         <form action="#" name="form-main" id="form-main">
646
         <form action="#" name="form-main" id="form-main">
603
            <input type="hidden" name="form-continue" id="form-continue" value="0" />
-
 
604
            <div class="form-group">
647
            <div class="form-group">
605
               <label for="form-name">LABEL_FIRST_NAME</label>
648
               <label for="form-name">LABEL_FIRST_NAME</label>
606
               <input type="text" name="form-name" id="form-name" class="form-control" maxlength="50" />
649
               <input type="text" name="form-name" id="form-name" class="form-control" maxlength="50" />
607
            </div>
650
            </div>
608
            <div class="form-group">
651
            <div class="form-group">
Línea 641... Línea 684...
641
               <div class="col-xs-12 col-md-12">
684
               <div class="col-xs-12 col-md-12">
642
                  <div class="panel-group" id="rows"></div>
685
                  <div class="panel-group" id="rows"></div>
643
               </div>
686
               </div>
644
            </div>
687
            </div>
645
            <div class="form-group">
688
            <div class="form-group">
-
 
689
            <button type="submit" form="form-main" class="btn btn-info btn-form-save-continue">LABEL_SAVE & LABEL_CONTINUE</button>
646
               <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
690
               <button type="button" class="btn btn-primary btn-form-save-close">LABEL_SAVE & LABEL_CLOSE</button>
647
               <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
691
               <button type="button" class="btn btn-secondary btn-edit-cancel">LABEL_CANCEL</button>
648
            </div>
692
            </div>
649
         </form>
693
         </form>
650
      </div>
694
      </div>