Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 1092 Rev 1093
Línea 450... Línea 450...
450
                    return;
450
                    return;
451
                }
451
                }
452
            });
452
            });
453
        }
453
        }
454
    });
454
    });
455
});
-
 
456
/**
455
    /**
457
 * Clicked save and close new/edit Form
456
     * Clicked save and close new/edit Form
458
 */
457
     */
459
$('button.btn-form-save-close').click(function(e) {
458
    $('button.btn-form-save-close').click(function(e) {
460
    for (var instanceName in CKEDITOR.instances) {
459
        for (var instanceName in CKEDITOR.instances) {
461
        CKEDITOR.instances[instanceName].updateElement();
460
            CKEDITOR.instances[instanceName].updateElement();
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');
-
 
475
    } else {
-
 
476
        $.ajax({
-
 
477
            'dataType': 'json',
-
 
478
            'method': 'post',
-
 
479
            'url': $('#form-main').attr('action'),
-
 
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)
-
 
487
            },
-
 
488
        }).done(function(response) {
-
 
489
            if (response['success']) {
-
 
490
                $.fn.showSuccess(response['data']);
-
 
491
                $('#row-form').hide();
-
 
492
                $('#row-lists').show();
-
 
493
                /*---------- Reset Form -------- */
-
 
494
                $('#form-main')[0].reset();
-
 
495
                /*--------Reset Sections ----------*/
-
 
496
                sections = [];
-
 
497
                tableForm.fnDraw();
-
 
498
                return;
-
 
499
            } else {
-
 
500
                $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
-
 
501
                return;
-
 
502
            }
-
 
503
        });
-
 
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': []
-
 
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) {
-
 
535
            item.title = title;
-
 
536
            item.type = type;
-
 
537
            item.text = text;
-
 
538
        }
461
        }
539
    });
-
 
540
    return renderData(sections);
462
        if ($('#form-name').val() == '') {
541
}
-
 
542
/**
-
 
543
 * Remove behavior
463
            $.fn.showError('ERROR_ENTER_NAME');
544
 */
-
 
545
const removeSection = (id) => {
464
        } else if ($('#form-description').val() == '') {
546
    sections = sections.filter((item) => item.id_section != id);
465
            $.fn.showError('ERROR_ENTER_DESCRIPTION');
547
    return renderData(sections);
466
        } else if ($('#form-text').val() == '') {
548
}
-
 
549
/**
-
 
550
 * Add Option to array
467
            $.fn.showError('ERROR_ENTER_TEXT');
551
 */
-
 
-
 
468
        } else if ($('#form-status').val() == '') {
-
 
469
            $.fn.showError('ERROR_SELECT_STATUS');
552
const addOption = (id_section, title) => {
470
        } else if ($('#job_description_id').val() == '') {
-
 
471
            $.fn.showError('ERROR_SELECT_JOB_DESCRIPTION');
553
    sections.map((item) => {
472
        } else if (sections.length == 0) {
554
        if (item.id_section == id_section) {
473
            $.fn.showError('ERROR_NOT_SECTIONS');
-
 
474
        } else {
555
            item.options.push({
475
            $.ajax({
-
 
476
                'dataType': 'json',
556
                'id_section': id_section,
477
                'method': 'post',
557
                'id_option': new Date().getTime(),
478
                'url': $('#form-main').attr('action'),
558
                'title': title,
479
                'data': {
-
 
480
                    'name': $('#form-main #form-name').val(),
-
 
481
                    'job_description_id': $('#form-main #job_description_id').val(),
-
 
482
                    'status': $('#form-main #form-status').val(),
-
 
483
                    'description': $('#form-main #form-description').val(),
-
 
484
                    'text': $('#form-main #form-text').val(),
-
 
485
                    'content': JSON.stringify(sections)
559
            });
486
                },
560
        }
487
            }).done(function(response) {
561
    });
488
                if (response['success']) {
-
 
489
                    $.fn.showSuccess(response['data']);
562
    return renderData(sections);
490
                    $('#row-form').hide();
563
}
-
 
564
/**
-
 
565
 * Edit item Option
491
                    $('#row-lists').show();
566
 */
-
 
567
const editOption = (id_section, id, title) => {
492
                    /*---------- Reset Form -------- */
568
    sections.map((item) => {
493
                    $('#form-main')[0].reset();
569
        if (item.id_section == id_section) {
494
                    /*--------Reset Sections ----------*/
570
            item.options.map((opt) => {
495
                    sections = [];
571
                if (opt.id_option == id) {
496
                    tableForm.fnDraw();
572
                    opt.title = title
497
                    return;
-
 
498
                } else {
-
 
499
                    $.fn.showError(response['message'] || 'ERROR_UNKNOWN');
-
 
500
                    return;
573
                }
501
                }
574
            });
502
            });
575
        }
503
        }
576
    });
504
    });
-
 
505
    /**
-
 
506
     * Remove Html Tags
-
 
507
     */
-
 
508
    const removeTags = (str) => str.toString().replace(/(<([^>]+)>)/ig, '')
-
 
509
    /**
-
 
510
     * Render Sections data
-
 
511
     */
-
 
512
    const renderData = (data) => {
-
 
513
        $("#rows").html($("#sectionTemplate").render(data));
-
 
514
    }
-
 
515
    /**
-
 
516
     * Add Section to array
-
 
517
     */
-
 
518
    const addSection = (title, text, type) => {
-
 
519
        sections.push({
-
 
520
            'id_section': new Date().getTime(),
-
 
521
            'title': title,
-
 
522
            'type': type,
-
 
523
            'text': text,
-
 
524
            'options': []
-
 
525
        });
-
 
526
        return renderData(sections);
-
 
527
    }
-
 
528
    /**
-
 
529
     * Edit item behavior
-
 
530
     */
-
 
531
    const editSection = (id, title, text, type) => {
-
 
532
        sections.map((item) => {
-
 
533
            if (item.id_section == id) {
-
 
534
                item.title = title;
-
 
535
                item.type = type;
-
 
536
                item.text = text;
-
 
537
            }
-
 
538
        });
-
 
539
        return renderData(sections);
-
 
540
    }
-
 
541
    /**
-
 
542
     * Remove behavior
-
 
543
     */
-
 
544
    const removeSection = (id) => {
-
 
545
        sections = sections.filter((item) => item.id_section != id);
-
 
546
        return renderData(sections);
-
 
547
    }
-
 
548
    /**
-
 
549
     * Add Option to array
-
 
550
     */
-
 
551
    const addOption = (id_section, title) => {
-
 
552
        sections.map((item) => {
-
 
553
            if (item.id_section == id_section) {
-
 
554
                item.options.push({
-
 
555
                    'id_section': id_section,
-
 
556
                    'id_option': new Date().getTime(),
-
 
557
                    'title': title,
-
 
558
                });
-
 
559
            }
-
 
560
        });
-
 
561
        return renderData(sections);
-
 
562
    }
-
 
563
    /**
-
 
564
     * Edit item Option
-
 
565
     */
-
 
566
    const editOption = (id_section, id, title) => {
-
 
567
        sections.map((item) => {
-
 
568
            if (item.id_section == id_section) {
-
 
569
                item.options.map((opt) => {
-
 
570
                    if (opt.id_option == id) {
-
 
571
                        opt.title = title
-
 
572
                    }
-
 
573
                });
-
 
574
            }
-
 
575
        });
577
    return renderData(sections);
576
        return renderData(sections);
578
}
577
    }
579
/**
578
    /**
580
 * Remove Option
579
     * Remove Option
581
 */
580
     */
582
const removeOption = (id_section, id) => {
581
    const removeOption = (id_section, id) => {
583
    sections.map((item) => {
582
        sections.map((item) => {
584
        if (item.id_section == id_section) {
583
            if (item.id_section == id_section) {
585
            item.options = item.options.filter((opt) => opt.id_option != id) || []
584
                item.options = item.options.filter((opt) => opt.id_option != id) || []
-
 
585
            }
586
        }
586
        });
-
 
587
        return renderData(sections);
-
 
588
    }
-
 
589
    /**
-
 
590
     * Clicked refresh button
-
 
591
     */
-
 
592
    $('button.btn-refresh').click(function(e) {
-
 
593
        tableForm.fnDraw();
-
 
594
        return;
587
    });
595
    });
588
    return renderData(sections);
-
 
589
}
-
 
590
/**
-
 
591
 * Clicked refresh button
-
 
592
 */
-
 
593
$('button.btn-refresh').click(function(e) {
-
 
594
tableForm.fnDraw();
-
 
595
return;
-
 
596
});
-
 
597
});
596
});
598
JS;
597
JS;
Línea 599... Línea 598...
599
 
598
 
600
$this->inlineScript()->captureEnd();
599
$this->inlineScript()->captureEnd();