<!-- Widgets -->
<div class="content-animation animated">
    <div class="row clearfix fBTitrBold ">
        <!-- Advanced Form Example With Validation -->
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div class="card">
                <div class="header text-center">
                    <h2 class="content-title">ویرایش نرم افزار</h2>
                </div>
                <div class="body">
                    <!-- Nav tabs -->
                    <ul class="nav nav-tabs " role="tablist">
                        <li role="presentation" class="active">
                            <a href="#p1" data-toggle="tab">
                                <i class="material-icons">home</i> صفحه اصلی برنامه
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="#p2" data-toggle="tab">
                                <i class="material-icons">filter_1</i> اضافه کردن سربرگ
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="#p3" data-toggle="tab">
                                <i class="material-icons">phonelink_setup</i> وضعیت نرم افزار
                            </a>
                        </li>
                        <li role="presentation">
                            <a href="#p4" data-toggle="tab">
                                <i class="material-icons">speaker_phone</i> ارسال پیام به گوشی
                            </a>
                        </li>
                    </ul>
                    <!-- Tab panes -->
                    <div class="tab-content">
                        <div role="tabpanel" class="tab-pane fade in active" id="p1">
                            <div class="row clearfix">
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <div class="card">
                                        <div class="header text-center">
                                            <h4 class="btn waves-effect full_width btn-success">اصلایدشو</h4>
                                        </div>
                                        <div class="body">
                                            <form id="form_p1c1" method="POST">
                                                <table class="full_width text-center">
                                                    <tr>
                                                        <td width="50%">
                                                            <table class=" full_width text-center">

                                                            </table>
                                                        </td>
                                                        <td width="50%">
                                                            <div class="btn-group ">
                                                                <button type="button"
                                                                        class="btn-update btn btn-warning btn-save-card waves-effect"
                                                                        data-index="c1"
                                                                        data-action="update"
                                                                        data-id="p1">
                                                                    بروز رسانی
                                                                </button>
                                                                <button type="button"
                                                                        class="btn-add btn btn-success btn-save-card waves-effect"
                                                                        data-action="add"
                                                                        data-index="c1"
                                                                        data-id="p1">
                                                                    اضافه کردن
                                                                </button>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div role="tabpanel" class="tab-pane fade" id="p2">
                            <div class="row clearfix">
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <div class="row clearfix">
                                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 ">
                                            <div class="card">
                                                <div class="header text-right">
                                                    <h2>سربرگ های فعلی</h2>
                                                </div>
                                                <div class="body ">
                                                    <div class="row">
                                                        <div class="col-md-12 ">
                                                            <div class="table-responsivep-t-20 no-overflow-y no-overflow-x ">
                                                                <table class="table text-center table-bordered table-striped table-hover  js-exportable full_width dataTable">
                                                                    <thead>
                                                                    <tr>
                                                                        <td class="text-center">تنظیمات</td>
                                                                        <td class="text-center">نام اسلاید</td>
                                                                        <td class="text-center">کد اسلاید</td>
                                                                        <td class="text-center">شماره</td>
                                                                    </tr>
                                                                    </thead>
                                                                    <tfoot>
                                                                    <tr>
                                                                        <td class="text-center">تنظیمات</td>
                                                                        <td class="text-center">نام اسلاید</td>
                                                                        <td class="text-center">کد اسلاید</td>
                                                                        <td class="text-center">شماره</td>
                                                                    </tr>
                                                                    </tfoot>
                                                                    <tbody>

                                                                    </tbody>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div role="tabpanel" class="tab-pane fade" id="p3">

                            <div class="row clearfix">
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <div class="card">
                                        <div class="body">
                                            <div class="row">
                                                <form id="form_p3" method="POST">


                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div role="tabpanel" class="tab-pane fade" id="p4">
                            <div class="row clearfix ">
                                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                                    <div class="card">
                                        <div class="header text-right">
                                            <h2>پیام های ذخیره شده</h2>
                                        </div>
                                        <div class="body ">
                                            <div class="row">
                                                <div class="col-md-12 ">
                                                    <div class="table-responsivep-t-20 no-overflow-y no-overflow-x ">
                                                        <table class="table text-center  table-bordered table-striped table-hover full_width js-notification-table dataTable">
                                                            <thead>
                                                            <tr>
                                                                <th class="text-center">عملیات</th>
                                                                <th class="text-center">بازدید</th>
                                                                <th class="text-center">وضعیت
                                                                    ارسال
                                                                </th>
                                                                <th class="text-center">نام پیام
                                                                </th>
                                                                <th class="text-center">شناسه پیام
                                                                <th class="text-center">شماره</th>
                                                            </tr>
                                                            </thead>
                                                            <tfoot>
                                                            <tr>
                                                                <th class="text-center">عملیات</th>
                                                                <th class="text-center">بازدید</th>
                                                                <th class="text-center">وضعیت
                                                                    ارسال
                                                                </th>
                                                                <th class="text-center">نام پیام
                                                                </th>
                                                                <th class="text-center">شناسه پیام
                                                                </th>
                                                                <th class="text-center">شماره</th>
                                                            </tfoot>
                                                            <tbody>

                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="card">
                                        <div class="header text-right">
                                            <div class="">ساخت پیام جدید</div>
                                        </div>
                                        <div class="body">
                                            <form class="wizard_with_validation" id="wizard_with_validation"
                                                  method="POST">

                                                <h3>مشخصات عمومی پیام</h3>
                                                <fieldset>
                                                    <div class="row clearfix rtl">
                                                        <div class="col-sm-6">
                                                            <div class="form-group form-float">
                                                                <div class="form-line">
                                                                    <input type="text" class="form-control "
                                                                           id="message-notification"
                                                                           name="message-notification"
                                                                           placeholder="اعلان پیام" required>
                                                                    <label class="form-label">اعلان پیام</label>
                                                                </div>
                                                            </div>

                                                        </div>
                                                        <div class="col-sm-6">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <input type="text"
                                                                           class="form-control "
                                                                           id="message-subject"
                                                                           name="message-subject"
                                                                           placeholder="موضوع پیام" required/>
                                                                    <label class="form-label">موضوع پیام</label>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="row clearfix rtl">
                                                        <div class="col-sm-6">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <input type="text"
                                                                           id="message-text"
                                                                           name="message-text"
                                                                           class="form-control"
                                                                           placeholder="متن پیام" required/>
                                                                    <label class="form-label">متن پیام</label>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-sm-6">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <input type="text"
                                                                           class="form-control "
                                                                           id="message-sub-text"
                                                                           name="message-sub-text"
                                                                           placeholder="متن انتهایی پیام" required/>
                                                                    <label class="form-label">متن انتهایی
                                                                        پیام</label>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="row clearfix rtl">
                                                        <div class="col-sm-12">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <input type="text"
                                                                           id="message-image-url"
                                                                           name="message-image-url"
                                                                           class="form-control"
                                                                           placeholder="آدرس تصویر" required/>
                                                                    <label class="form-label">آدرس تصویر</label>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </fieldset>

                                                <h3>قابلیت های پیام</h3>
                                                <fieldset>
                                                    <div class="row clearfix rtl">
                                                        <div class="col-sm-12">
                                                            <div class="form-group">
                                                                <button class="btn btn-danger waves-effect click-on-notification "
                                                                        value="0">
                                                                    <span>غیر فعال بودن کلیک کردن</span>
                                                                </button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-12">
                                                        <div class="row clearfix rtl notification-screen ">
                                                            <div class="card ">
                                                                <div class="header text-right">
                                                                    <div class=""> اطلاعات مربوط به صفحه نمایشی
                                                                    </div>
                                                                </div>
                                                                <div class="body">
                                                                    <div class="row">
                                                                        <div class="col-sm-12">
                                                                            <select class="form-control show-tick full_width "
                                                                                    title="">

                                                                            </select>
                                                                        </div>
                                                                        <div class="col-sm-12 no-overflow-y no-overflow-x">
                                                                            <table class="table text-center table-responsive table-bordered full-width">
                                                                                <thead>
                                                                                <tr>
                                                                                    <th colspan="3"
                                                                                        class="text-center bg-amber">
                                                                                        پارامتر
                                                                                        های صفحه
                                                                                    </th>
                                                                                </tr>
                                                                                <tr>
                                                                                    <th class="text-center bg-blue-grey"
                                                                                        width="10%">
                                                                                        شماره
                                                                                    </th>
                                                                                    <th class="text-center bg-blue-grey"
                                                                                        width="20%">
                                                                                        نام
                                                                                    </th>
                                                                                    <th class="text-center bg-blue-grey"
                                                                                        width="70%">
                                                                                        نوع مقدار
                                                                                    </th>
                                                                                </tr>
                                                                                </thead>
                                                                                <tbody class="table-body-parameters-description">

                                                                                </tbody>
                                                                            </table>

                                                                            <table class="table text-center table-responsive table-bordered full-width">
                                                                                <thead>
                                                                                <tr>
                                                                                    <th class="text-center bg-success">
                                                                                        نام
                                                                                        پارامتر
                                                                                    </th>
                                                                                    <th class="text-center bg-success">
                                                                                        مقدار
                                                                                        پارامتر
                                                                                    </th>
                                                                                    <th class="text-center bg-success">
                                                                                        #
                                                                                    </th>
                                                                                </tr>
                                                                                </thead>
                                                                                <tbody class="table-body-parameters-field">

                                                                                </tbody>
                                                                            </table>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </fieldset>

                                                <h3>تنظیمات پیام</h3>
                                                <fieldset>
                                                    <div class="row clearfix rtl">
                                                        <div class="col-sm-6">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <label>وضعیت لرزش</label>
                                                                    <input type="text"
                                                                           value="500l,200l,200l,500l"
                                                                           class="form-control "
                                                                           id="message-vibration"
                                                                           name="message-vibration"
                                                                           placeholder="وضعیت لرزش" required/>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-sm-6">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <label>کد طبقه بندی پیام</label>
                                                                    <input type="text"
                                                                           id="message-code"
                                                                           name="message-code"
                                                                           class="form-control"
                                                                           placeholder="کد طبقه بندی پیام"
                                                                           required/>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="row clearfix rtl">
                                                        <div class="col-sm-3">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <label>Request Code</label>
                                                                    <input type="text"
                                                                           class="form-control"
                                                                           value="1"
                                                                           id="message-request-code"
                                                                           name="message-request-code"
                                                                           placeholder="Request Code" required/>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-sm-3">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <label>Request Flag</label>
                                                                    <input type="text"
                                                                           value="0"
                                                                           id="message-request-flag"
                                                                           name="message-request-flag"
                                                                           class="form-control"
                                                                           placeholder="Request Flag" required/>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-sm-3">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <label>BN Going</label>
                                                                    <input type="text"
                                                                           value="0"
                                                                           id="message-bn-going"
                                                                           name="message-bn-going"
                                                                           class="form-control"
                                                                           placeholder="BN Going" required/>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-sm-3">
                                                            <div class="form-group">
                                                                <div class="form-line">
                                                                    <label>Auto Cancel</label>
                                                                    <input type="text"
                                                                           value="0"
                                                                           id="message-auto-cancel"
                                                                           name="message-auto-cancel"
                                                                           class="form-control"
                                                                           placeholder="Auto Cancel" required/>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </fieldset>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- #END# Advanced Form Example With Validation -->
    </div>
</div>
<!-- #END# Form -->
<div class="modal fade" id="defaultModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header text-right">
                <h4 class="modal-title " id="defaultModalLabel">ویرایش اسلاید شو</h4>
            </div>
            <div class="modal-body">
                <div class="row clearfix ">
                    <div class="card">
                        <div class="header">
                            <div class="row clearfix rtl">
                                <div class="col-sm-4">
                                    <div class="form-group text-center">
                                        <button type="button" class="btn add-slide-child btn-success waves-effect">اضافه
                                            کردن
                                        </button>
                                    </div>
                                </div>
                                <div class="col-sm-8">
                                    <div class="form-group">
                                        <div class="form-line">
                                            <input type="text" id="acceptor-code" class="form-control"
                                                   placeholder="کد پذیرنده"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="body">
                            <div class="col-md-12" id="preloader">
                                <div class="text-center">
                                    <div class="preloader pl-size-xl">
                                        <div class="spinner-layer center pl-deep-orange">
                                            <div class="circle-clipper left">
                                                <div class="circle"></div>
                                            </div>
                                            <div class="circle-clipper right">
                                                <div class="circle"></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div id="aniimated-thumbnials" class="list-unstyled row clearfix"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-link waves-effect" data-dismiss="modal">بستن</button>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    (function ($) {
        let Field, inputBox;
        let FieldCounter = {
            LoadApp: {p1: null, p2: null, p3: null, p4: null},
            p1: {c1: {count: 0}, c2: {count: 0}},
            p2: {
                flagInsert: true,
                table: null,
                array: [],
                Model: null,
                Slider: null,
                Loader: null,
                OnAdd: null,
                OnActive: null,
                OnDelete: null,
                OnEditID: 0,

                OnEdit: null,

                OnAddFor: -1,
                OnEditSlide: null,
                OnDeleteSlide: null,
                OnAddSlide: null,

                OnEditSlidePanel: null,
                OnDeleteSlidePanel: null,
                OnAddSlidePanel: null
            },
            p3: {OnChange: null},
            p4: {
                c1: {
                    Load: null,
                    table: null,
                    array: [],
                    OnDelete: null,
                    OnActive: null,
                    OnEdit: null,
                    OnChangeKey: null
                },
                c2: {
                    Load: null,
                    formWizard: null,
                    OnSave: null,
                    OnValidation: null,
                    PackagePanel: null,
                    state: {
                        NotificationScreen: null,
                        NotificationScreenBtn: null,
                        1: {
                            value: 0,
                            AddClass: "btn-danger",
                            RemoveClass: "btn-success",
                            text: "غیر فعال بودن کلیک کردن"
                        },
                        0: {value: 1, AddClass: "btn-success", RemoveClass: "btn-danger", text: "فعال بودن کلیک کردن"}
                    },
                    select: {
                        OnSetItem: null,
                        selector: Object,
                        OnInit: null,
                        OnChange: null,
                        ObjectLength: null,
                        OnField: {
                            index: 0,
                            id: [],
                            key: [],
                            Add: null,
                            Clear: null
                        }
                    },
                    SaveObject: {
                        state: 1,
                        stateOption: ['ویرایش', 'ذخیره'],
                        stateRequest: ['edit', 'add'],
                        requestObject: {
                            bn_message: null,
                            bn_title: null,
                            bn_subtitle: null,
                            bn_ticker: null,
                            bn_largeIcon: null,
                            bn_vibrate_array: null,
                            bn_request_code: null,
                            bn_request_flag: null,
                            bn_number: null,
                            bn_going: null,
                            bn_auto_cancel: null,
                            bn_package: null,
                            bn_parameter: '',
                            bn_EditID: -1,
                            index: 0
                        }
                    },
                    PageList: [
                        {
                            package: '',
                            name: 'بدون صفحه',
                            parameters: {}
                        }/*, {
                            package: 'com.gmai.kavandf2000.card.shahrvand.com.shahrvandcard.com.SplashScreen',
                            name: 'صفحه اصلی',
                            parameters: {}
                        }, {
                            package: 'com.gmai.kavandf2000.card.shahrvand.com.shahrvandcard.com.SearchPage',
                            name: 'صفحه جستجو',
                            parameters: {}
                        }, {
                            package: 'com.gmai.kavandf2000.card.shahrvand.com.shahrvandcard.com.PublicItemCMS',
                            name: 'صفحه مشخصات پذیرنده',
                            parameters: {
                                item_id: 'شماره پذیرنده (اجباری)', mode: 'مقدار main (اجباری)'
                            }
                        }, {
                            package: 'com.gmai.kavandf2000.card.shahrvand.com.shahrvandcard.com.login.Register',
                            name: 'صفحه ثبت نام',
                            parameters: {type: 'برای (پذیرنده : master) و (کاربر : client) (اجباری)'}
                        }, {
                            package: 'com.gmai.kavandf2000.card.shahrvand.com.shahrvandcard.com.MainPage',
                            name: 'خانه',
                            parameters: {}
                        }, {
                            package: 'com.gmai.kavandf2000.card.shahrvand.com.shahrvandcard.com.NotificationPage',
                            name: 'صفحه اعلان عمومی',
                            parameters: {
                                index: 'شماره (اجباری)',
                                mode: 'مقدار (notification) (برای اعلان) و مقدار (help) (برای راهنما)'
                            }
                        }*/
                    ]
                }
            }
        };
        //#region p1 start

        FieldCounter.LoadApp.p1 = function () {
            OnEventListener();
            LoadData({request: 'proxy', action: 'app_load_image_slider'}, null, true, function (data) {
                if (data.length > 0) {
                    let item = Selector("p1", 'c1');
                    for (let i = 0; i < data.length; i += 1) {
                        let o = data[i];
                        if (o.error === 0) {
                            let field = Field('p1', 'c1', o.url, o.post);
                            item.append(field[0]);
                        }
                    }
                }
                $('button.remove-input-box')
                    .unbind()
                    .bind("tap , click", function () {
                        $('#' + $(this).attr('data-id')).remove();
                    });
            });
        };

        function OnEventListener() {
            $(".btn-add, .btn-update")
                .unbind()
                .bind("tap, click", function (e) {
                    let btn = $(this),
                        form = $(this).attr("data-id"),
                        card = $(this).attr("data-index"),
                        action = $(this).attr("data-action");

                    switch (action) {
                        case 'update':
                            swal({
                                title: "آیا نمایش این مورد ویرایش شود؟",
                                text: " این مورد ,ویرایش می شود ",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "بله ویرایش شود",
                                cancelButtonText: "نه ویرایش نشود",
                                closeOnConfirm: false,
                                closeOnCancel: false
                            }, function (isConfirm) {
                                if (isConfirm) {
                                    let data = '';
                                    let c = FieldCounter.p1[card].count, flag = true, counter = 0;
                                    if (c > 0) {
                                        while (flag) {
                                            counter += 1;
                                            let item1 = '#input-' + form + "-" + card + "-" + (counter) + "-item-" + 1;
                                            let item2 = '#input-' + form + "-" + card + "-" + (counter) + "-item-" + 2;
                                            if ($(item1).length > 0) {
                                                if ($(item1).val().length > 0) {
                                                    data += "[" + $(item1).val() + "," + $(item2).val() + "]";
                                                }
                                            }
                                            if (counter === c) {
                                                flag = false;
                                            }
                                        }
                                    }
                                    LoadData({
                                        request: 'proxy',
                                        object: {for: card, data: data},
                                        action: 'app_update_slide_show',
                                    }, null, false, function (data) {
                                        if (data === '1') {
                                            swal("ویرایش شد", "این مورد ویرایش شد", "success");
                                        } else {
                                            swal("خطا", "این درخواست انجام نشد", "error");
                                        }
                                    });
                                } else {
                                    swal("لغو شد", "این درخواست لغو شد", "error");
                                }
                            });
                            break;
                        case 'add':
                            let item = Selector(form, card);
                            let field = Field(form, card);
                            item.append(field[0]);
                            $('button.remove-input-box')
                                .unbind()
                                .bind("tap , click", function () {
                                    $('#' + $(this).attr('data-id')).fadeOut(500, function () {
                                        $('#' + $(this).attr('data-id')).remove();
                                    });
                                });
                            break;
                        default:
                            break
                    }
                });
        }

        function Selector(key, card) {
            return $('#form_' + key + card).find('table').find('td').first().find('table');
        }

        Field = function (form, card, D1 = '', D2 = '') {
            FieldCounter[form][card].count += 1;
            let html = '', tr = 'tr-' + form + '-' + card + '-' + FieldCounter[form][card].count;
            html += '<tr class="full_width" id="' + tr + '">';
            html += '<td class="full_width " id="td-' + form + '-' + card + '-' + FieldCounter[form][card].count + '">';
            let ID = 'input-' + form + '-' + card + '-' + FieldCounter[form][card].count + "-item-";
            html += inputBox(tr, "آدرس تصویر", "آدرس سایت پذیرنده", ID + '1', ID + '2', D1, D2);
            html += '</td>';
            html += '</tr>';
            return [html, tr];
        };

        inputBox = function (tr, P1 = '', P2 = '', ID1 = '', ID2 = '', D1 = '', D2 = '') {
            let html = '';
            html += '<div class="row" >';
            html += '    <div class="col-md-5">';
            html += '        <div class="input-group">';
            html += '        <span class="input-group-addon">';
            html += '            <i class="material-icons">photo</i>';
            html += '        </span>';
            html += '            <div class="form-line">';
            html += '                <input type="text" value="' + D1 + '" class="form-control " placeholder="' + P1 + '" id="' + ID1 + '">';
            html += '            </div>';
            html += '        </div>';
            html += '    </div>';
            html += '    <div class="col-md-5">';
            html += '        <div class="input-group">';
            html += '        <span class="input-group-addon">';
            html += '            <i class="material-icons">link</i>';
            html += '        </span>';
            html += '            <div class="form-line">';
            html += '                <input type="text" value="' + D2 + '" class="form-control " placeholder="' + P2 + '" id="' + ID2 + '">';
            html += '            </div>';
            html += '        </div>';
            html += '    </div>';
            html += '    <div class="col-md-2">';
            html += '        <div class="form-line">';
            html += '            <button class="btn btn-danger waves-effect waves-amber remove-input-box" data-id="' + tr + '">حذف</button>';
            html += '        </div>';
            html += '    </div>';
            html += '</div>';
            return html;
        };
        //#endregion p1 end
        //#region p2 start

        FieldCounter.LoadApp.p2 = function () {


            let mt = $('#slide-main-text'), st = $('#slide-sub-text'), addSlideBtn = $(".btn-add-slide"),
                addChild = $('.add-slide-child');
            FieldCounter.p2.Model = $('#defaultModal');
            FieldCounter.p2.Slider = $('#aniimated-thumbnials');
            FieldCounter.p2.Loader = $('#preloader');
            FieldCounter.p2.Model
                .unbind()
                .bind('hidden.bs.modal', function () {
                    FieldCounter.p2.OnAddFor = -1;
                });
            addSlideBtn
                .unbind()
                .bind("tap, click", function (e) {
                    FieldCounter.p2.OnAdd(mt, st, addSlideBtn, FieldCounter.p2.OnEditID);
                });
            addChild
                .unbind()
                .bind("tap , click", function (e) {
                    let id = $('#acceptor-code');
                    if (parseInt(id.val()) > 0) {
                        switch (FieldCounter.p2.OnAddFor) {
                            case 1:
                                FieldCounter.p2.OnAddSlide(FieldCounter.p2.OnEditID, parseInt(id.val()));
                                break;
                            case 2:
                                FieldCounter.p2.OnAddSlidePanel(FieldCounter.p2.OnEditID, parseInt(id.val()));
                                break;
                            default:
                                break;
                        }
                    }
                });
            FormP2c1 = $("#form_p2");


            LoadData({
                request: 'proxy',
                action: 'app_slide_controller',
                'header-type': 'app-load-slide'
            }, null, true, function (data) {
                if (data.length > 0) {
                    FieldCounter.p2.array = data;
                    if (FieldCounter.p2.table !== null)
                        FieldCounter.p2.table.destroy();
                    FieldCounter.p2.table = $('.js-exportable').DataTable({
                        "data": data,
                        "columns": [
                            {"data": "button-edit"},
                            {"data": "main-text"},
                            {"data": "id"},
                            {"data": "count"}
                        ],
                        "fnInitComplete": function (e) {
                            OnEventListener2();
                        },
                        "fnInfoCallback": function (oSettings, iStart, iEnd, iMax, iTotal, sPre) {
                            OnEventListener2();
                        },
                        responsive: true,
                        "language": {
                            "lengthMenu": "نمایش _MENU_ رکورد در صفحه",
                            "zeroRecords": " چیزی یافت نشد",
                            "info": "نمایش از _START_ تا _END_ در _TOTAL_ رکورد",
                            "infoEmpty": "<center>رکوردی پیدا نشد</center>",
                            "infoFiltered": "(filtered from _MAX_ total records)",
                            "paginate": {
                                "next": "بعدی",
                                "previous": "قبلی"
                            }
                        }
                    });
                }
            });
        };

        function OnEventListener2() {
            $("button[data-mod='app-slide-control']")
                .unbind()
                .bind("tap, click", function (e) {
                    let btn = $(this),
                        mode = $(this).attr('data-mod');

                    let id = $(this).attr("data-id"),
                        tr = btn.parents('tr'),
                        index = btn.attr("data-index"),
                        action = btn.attr("data-action");
                    switch (action) {
                        case 'show-item':
                            FieldCounter.p2.OnActive(btn, id);
                            break;
                        case 'edit-item':
                            FieldCounter.p2.OnEditSlide(id);
                            break;
                        default:
                            break;
                    }
                });
        }

        FieldCounter.p2.OnAddSlide = function (SlideID, IDForAdd) {
            swal({
                title: "اضافه کردن این پذیرنده ؟",
                text: "تایید",
                type: "info",
                showCancelButton: true,
                closeOnConfirm: false,
                showLoaderOnConfirm: true,
            }, function () {
                LoadData({
                    request: 'proxy',
                    object: {id: IDForAdd, from: SlideID},
                    action: 'app_slide_controller',
                    'header-type': 'app-add-chile-slide'
                }, null, true, function (data) {
                    if (data.error === 0) {
                        swal("اضافه شد", "", "success");
                        FieldCounter.p2.OnEditSlide(SlideID);
                    } else {
                        switch (data.error) {
                            case 1:
                                swal("خطا", "این پذیرنده اضافه نشد", "error");
                                break;
                            case 100:
                                swal("خطا", "این پذیرنده وجود ندارد", "error");
                                break;
                            case 200:
                                swal("خطا", "این پذیرنده وجود دارد", "error");
                                break;
                            case 300:
                                swal("خطا", "این اسلاید پیدا نشد وجود دارد", "error");
                                break;
                            default:
                                swal("خطا", "این درخواست انجام نشد", "error");
                                break;
                        }
                    }
                });
            });
        };

        FieldCounter.p2.OnEditSlide = function (id) {
            $(function () {
                FieldCounter.p2.OnAddFor = 1;
                FieldCounter.p2.OnEditID = id;

                FieldCounter.p2.Slider.empty();
                FieldCounter.p2.Loader.show();
                FieldCounter.p2.Model.modal('show');
                LoadData({
                    request: 'proxy',
                    action: 'app_slide_controller',
                    object: {id: id},
                    'header-type': 'app-load-child-slide'
                }, null, true, function (data) {
                    if (data.length > 0) {
                        FieldCounter.p2.Slider.lightGallery();
                        for (let i = 0; i < data.length; i += 1) {
                            FieldCounter.p2.Slider.append(AddSlide(data[i]));
                            FieldCounter.p2.Slider.data('lightGallery').destroy(true);
                            FieldCounter.p2.Slider.lightGallery({selector: '.custom-selector'});
                        }
                        $('.btn-delete-slide')
                            .unbind()
                            .bind("tap , click", function (e) {
                                let btn = $(this), ID = $(this).attr('data-id');
                                FieldCounter.p2.OnDeleteSlide(ID, id);
                            });
                        FieldCounter.p2.Loader.hide();
                    } else {
                        FieldCounter.p2.Loader.hide();
                    }
                });
            });
        };
        FieldCounter.p2.OnDeleteSlide = function (ID, parentID) {
            swal({
                title: "آیا این مورد حذف شود؟",
                text: " این مورد ,حذف می شود ",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "بله حذف شود",
                cancelButtonText: "نه حذف نشود",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function (isConfirm) {
                if (isConfirm) {
                    LoadData({
                        request: 'proxy',
                        object: {id: ID, from: parentID},
                        action: 'app_slide_controller',
                        'header-type': 'app-delete-chile-slide'
                    }, null, false, function (data) {
                        console.log(data);
                        if (data === '1') {
                            $('#slide-id-' + ID).fadeOut(500, function () {
                                $('#slide-id-' + ID).remove();
                            });
                            swal("حذف شد", "این مورد حذف شد", "success");
                        } else {
                            swal("خطا", "این درخواست انجام نشد", "error");
                        }
                    });
                } else {
                    swal("لغو شد", "این درخواست لغو شد", "error");
                }
            });
        };

        FieldCounter.p2.OnActive = function (btn, id) {
            let data_value = btn.attr("data-value"), text = "";
            if (data_value === '0') {
                text = "غیر قابل نمایش";
            } else {
                text = "قابل نمایش";
            }
            swal({
                title: "آیا نمایش این مورد ویرایش شود؟",
                text: " این مورد " + text + " می شود ",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "بله " + text + " شود",
                cancelButtonText: "نه " + text + " نشود",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function (isConfirm) {
                if (isConfirm) {
                    LoadData({
                        request: 'proxy',
                        object: {id: id, show: data_value},
                        action: 'app_slide_controller',
                        'header-type': 'app-active-slide'
                    }, null, false, function (data) {
                        if (data === '1') {
                            if (data_value === '1') {
                                btn.attr('data-value', 0);
                                btn.removeClass('btn-warning').addClass('btn-info');
                                btn.find('i').empty().append('visibility');
                            } else {
                                btn.attr('data-value', 1);
                                btn.removeClass('btn-info').addClass('btn-warning');
                                btn.find('i').empty().append('visibility_off');
                            }
                            swal(text + " شد", "این مورد " + text + " شد", "success");
                        } else {
                            swal("خطا", "این درخواست انجام نشد", "error");
                        }
                    });
                } else {
                    swal("لغو شد", "این درخواست لغو شد", "error");
                }
            });
        };

        /**
         * @return {string}
         */
        function AddSlide(o) {
            let slide = '';
            slide += '<div id="slide-id-' + o.ID + '" class="col-lg-3 col-md-4 col-sm-6 col-xs-12" data-src="' + o.url + '">';
            slide += '    <div class="custom-selector" data-src="' + o.url + '">';
            slide += '        <img class="img-responsive thumbnail" src="' + o.url + '">';
            slide += '    </div>';
            slide += '    <button class="btn btn-block btn-default waves-effect">' + (o.name === null ? "حذف شده" : o.name) + '</button>';
            if (!o.state || o.error) {
                slide += '    <div class="btn-group btn-group-justified">';
                if (!o.state)
                    slide += '    <a href="javascript:void(0);" class="btn btn-warning waves-effect">تصویر ندارد</a>';
                if (o.error)
                    slide += '    <a href="javascript:void(0);" class="btn btn-warning waves-effect">از سیستم حذف شده</a>';
                slide += '   </div>';
            }
            slide += '    <button class="btn btn-delete-slide btn-block btn-danger waves-effect" data-index="' + o.index + '" data-id="' + o.ID + '">حذف از لیست</button>';
            slide += '</div>';
            return slide;
        }

        //#endregion p2 end
        //#region p3 start
        FieldCounter.LoadApp.p3 = function () {
            let form = $("#form_p3");
            FieldCounter.p3.item = [];
            LoadData({
                request: 'proxy',
                action: 'app_state_controller',
                'header-type': 'app-state-load'
            }, null, true, function (data) {
                if (data.length > 0) {
                    form.append().empty();
                    for (let i = 0; i < data.length; i += 1) {
                        let o = data[i];
                        form.append(AddCard(o, i));
                    }
                    $('.switch-input')
                        .unbind()
                        .bind('change', function (e) {
                            let ID = $(this).attr('data-id'), value = $(this).prop('checked');
                            FieldCounter.p3.OnChange(ID, value);
                        });
                }
            });

        };
        FieldCounter.p3.OnChange = function (ID, value) {
            LoadData({
                request: 'proxy',
                object: {id: ID, state: (value ? 1 : 0)},
                action: 'app_state_controller',
                'header-type': 'app-state-update'
            }, null, false, null);

        };

        /**
         * @return {string}
         */
        function AddCard(o, index) {
            let html = '';
            html += '<div class="col-md-4">';
            html += '   <div class="card">';
            html += '       <div class="header text-right">' + o.name + '</div>';
            html += '       <div class="body text-center">';
            html += '           <div class="toggle-panel">';
            html += '               <label class="switch switch-left-right">';
            html += '                   <input class="switch-input" type="checkbox" data-id="' + o.id + '" data-index="' + index + '" ' + (o.state === '1' ? 'checked' : '') + '>';
            html += '                   <span class="switch-label" data-on="فعال" data-off="غیر فعال"></span> <span class="switch-handle"></span> </label>';
            html += '           </div>';
            html += '       </div>';
            html += '   </div>';
            html += '</div>';
            return html;
        }

        //#endregion p3 end
        //#region p4 start
        /**
         * @return {boolean}
         */
        FieldCounter.p4.c2.OnValidation = function (o) {
            return true;
        };
        FieldCounter.p4.c1.Load = function () {
            LoadData({
                request: 'proxy',
                action: 'app_notification_controller',
                'header-type': 'app-notification-load'
            }, null, true, function (data) {
                if (data.length > 0) {
                    if (FieldCounter.p4.c1.table != null)
                        FieldCounter.p4.c1.table.destroy();
                    FieldCounter.p4.c1.array = [];
                    for (let i = 0; i < data.length; i += 1) {
                        FieldCounter.p4.c1.array.push(data[i].data);
                    }
                    FieldCounter.p4.c1.table = $('.js-notification-table').DataTable({
                        "data": data,
                        "columns": [
                            {"data": "option-btn"},
                            {"data": "see-btn"},
                            {"data": "state-btn"},
                            {"data": "title-btn"},
                            {"data": "key-btn"},
                            {"data": "counter"}
                        ],
                        responsive: true,
                        "fnInitComplete": function (e) {
                            FieldCounter.p4.c2.OnInitEvent();
                        },
                        "fnInfoCallback": function (oSettings, iStart, iEnd, iMax, iTotal, sPre) {
                            FieldCounter.p4.c2.OnInitEvent();
                        },
                        "language": {
                            "lengthMenu": "نمایش _MENU_ رکورد در صفحه",
                            "zeroRecords": " چیزی یافت نشد",
                            "info": "نمایش از _START_ تا _END_ در _TOTAL_ رکورد",
                            "infoEmpty": "<center>رکوردی پیدا نشد</center>",
                            "infoFiltered": "(filtered from _MAX_ total records)",
                            "paginate": {
                                "next": "بعدی",
                                "previous": "قبلی"
                            }
                        }
                    });
                }
            });
        };

        FieldCounter.p4.c2.OnInitEvent = function () {
            $("button[data-mod='app-notification-control']")
                .unbind()
                .bind("tap, click", function (e) {
                    let btn = $(this),
                        mode = $(this).attr('data-mod');

                    let id = $(this).attr("data-id"),
                        index = btn.attr("data-index"),
                        tr = btn.parents('tr'),
                        action = btn.attr("data-action");
                    switch (action) {
                        case 'delete-item':
                            FieldCounter.p4.c1.OnDelete(id, tr);
                            break;
                        case 'show-item':
                            FieldCounter.p4.c1.OnActive(id, btn);
                            break;
                        case 'edit-item':
                            FieldCounter.p4.c1.OnEdit(id, index);
                            break;
                        case 'change-key-item':
                            FieldCounter.p4.c1.OnChangeKey(id, btn);
                            break;
                        default:
                            break;
                    }
                });
        };
        /**
         * @return {number}
         */
        FieldCounter.p4.c2.select.OnField.Add = function (name = '', value = '', description, index) {
            let table = $('tbody.table-body-parameters-field'),
                id = 'notification' + '-' + name + '-' + index,
                html = '';
            FieldCounter.p4.c2.select.OnField.id.push(id);
            FieldCounter.p4.c2.select.OnField.key.push(name);
            html += '<tr class="align-center">';
            html += '<td class="text-center align-center">';
            html += '<h2 class="btn waves-effect btn-block btn-success">' + name + '</h2>';
            html += '</td>';
            html += '<td class="text-center">';
            html += '<div class="form-group">';
            html += '    <div class="form-line">';
            html += '        <label class="badge bg-orange">' + description + '</label>';
            html += '        <input type="text"';
            html += '               id="' + id + '"';
            html += '               name="' + id + '"';
            html += '               value="' + value + '"';
            html += '               class="form-control"';
            html += '               placeholder="' + description + '" required/>';
            html += '    </div>';
            html += '</div>';
            html += '</td>';
            html += '<td class="text-center">' + index + '</td>';
            html += '</tr>';
            table.append(html);

        };
        FieldCounter.p4.c2.select.OnField.Clear = function () {
            FieldCounter.p4.c2.select.OnField.id = [];
            FieldCounter.p4.c2.select.OnField.key = [];
            FieldCounter.p4.c2.select.OnField.index = 0;

            FieldCounter.p4.c2.SaveObject.state = 1;
            FieldCounter.p4.c2.SaveObject.bn_parameter = '';
            FieldCounter.p4.c2.SaveObject.bn_EditID = -1;

            FieldCounter.p4.c2.state.NotificationScreen("up");

            FieldCounter.p4.c2.state.NotificationScreenBtn.find('span').text(FieldCounter.p4.c2.state[1].text);
            FieldCounter.p4.c2.state.NotificationScreenBtn.removeClass(FieldCounter.p4.c2.state[1].RemoveClass).addClass(FieldCounter.p4.c2.state[1].AddClass);
            FieldCounter.p4.c2.state.NotificationScreenBtn.attr('value', FieldCounter.p4.c2.state[1].value);

        };
        FieldCounter.p4.c2.select.OnSetItem = function (name) {
            if (FieldCounter.p4.c2.PageList.length > 0)
                for (let pl = 0; pl < FieldCounter.p4.c2.PageList.length; pl += 1) {
                    if (name === FieldCounter.p4.c2.PageList[pl].package) {
                        FieldCounter.p4.c2.select.selector.selectpicker("val", pl).selectpicker('render');
                        FieldCounter.p4.c2.select.selector.val(pl).trigger('change');
                    }
                }

        };
        /**
         * @return {number}
         */
        FieldCounter.p4.c2.select.ObjectLength = function (object) {
            let length = 0;
            for (let key in object) {
                if (object.hasOwnProperty(key)) {
                    ++length;
                }
            }
            return length;
        };
        FieldCounter.p4.c2.select.OnChange = function () {
            let table = $('tbody.table-body-parameters-description');
            table.empty().append('<tr><th colspan="3" class="text-center bg-warning" width="100%">این صفحه پارامتری ندارد.</th></tr>');
            FieldCounter.p4.c2.select.selector
                .bind("change", function (e) {
                    $('tbody.table-body-parameters-field').empty();
                    table.empty();
                    let $this = $(this), $value = $this.val(),
                        html = '',
                        count = FieldCounter.p4.c2.select.ObjectLength(FieldCounter.p4.c2.PageList[$value].parameters);
                    FieldCounter.p4.c2.select.OnField.index = $value;
                    if (count > 0) {
                        let x = 0,
                            parameter = (FieldCounter.p4.c2.SaveObject.state === 1 ? [] : FieldCounter.p4.c1.array[FieldCounter.p4.c2.SaveObject.index].parameter.split('|'));
                        for (let key in FieldCounter.p4.c2.PageList[$value].parameters) {
                            if (FieldCounter.p4.c2.PageList[$value].parameters.hasOwnProperty(key)) {
                                x += 1;
                                let style = '';
                                style += '<tr>';
                                style += '<th class="text-center bg-indigo"  width="10%">' + (x) + '</th>';
                                style += '<th class="text-center bg-indigo"  width="20%">' + key + '</th>';
                                style += '<th class="text-center bg-indigo"  width="70%">' + FieldCounter.p4.c2.PageList[$value].parameters[key] + '</th>';
                                style += '</tr>';
                                html += style;
                                FieldCounter.p4.c2.select.OnField.Add(key,
                                    (parameter.length > 0 ? (parameter[(x - 1)].split('=')[0] === key ? (parameter[(x - 1)].split('=')[1]) : '') : ""),
                                    FieldCounter.p4.c2.PageList[$value].parameters[key], x);
                            }
                        }
                    } else {
                        html += '<tr>';
                        html += '<th colspan="3" class="text-center bg-warning" width="100%">این صفحه پارامتری ندارد.</th>';
                        html += '</tr>';
                    }
                    table.empty().append(html);
                    return e;
                });

        };
        FieldCounter.p4.c2.select.OnInit = function () {
            if (FieldCounter.p4.c2.PageList.length > 0) {
                if (FieldCounter.p4.c2.select.selector.children('option').length === 0) {
                    FieldCounter.p4.c2.select.selector.selectpicker();
                    FieldCounter.p4.c2.select.OnField.Clear();
                    for (let pl = 0; pl < FieldCounter.p4.c2.PageList.length; pl += 1) {
                        FieldCounter.p4.c2.select.selector
                            .append('<option class="text-right" value="' + pl + '">' + FieldCounter.p4.c2.PageList[pl].name + '</option>')
                            .selectpicker('refresh');
                    }
                    FieldCounter.p4.c2.select.OnChange();
                    FieldCounter.p4.c2.select.selector.selectpicker("val", 0).selectpicker('render');
                    FieldCounter.p4.c2.select.selector.val(0).trigger('change');
                } else {
                    FieldCounter.p4.c2.select.selector.selectpicker("val", 0).selectpicker('render');
                    FieldCounter.p4.c2.select.selector.val(0).trigger('change');
                }
            }
        };
        FieldCounter.p4.c2.OnSave = function (e) {
            FieldCounter.p4.c2.SaveObject.requestObject.bn_message = $('#message-text');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_title = $('#message-subject');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_subtitle = $('#message-sub-text');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_ticker = $('#message-notification');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_largeIcon = $('#message-image-url');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_vibrate_array = $('#message-vibration');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_request_code = $('#message-request-code');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_request_flag = $('#message-request-flag');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_number = $('#message-code');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_going = $('#message-bn-going');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_auto_cancel = $('#message-auto-cancel');
            FieldCounter.p4.c2.SaveObject.requestObject.bn_package = FieldCounter.p4.c2.PageList[FieldCounter.p4.c2.select.OnField.index].package;

            let parameters = '';
            if (FieldCounter.p4.c2.select.OnField.id.length > 0) {
                for (let i = 0; i < FieldCounter.p4.c2.select.OnField.id.length; i += 1) {
                    let item = $('#' + FieldCounter.p4.c2.select.OnField.id[i]);
                    if (item.length > 0) {
                        if (parameters.length > 0)
                            parameters += "|";
                        parameters += FieldCounter.p4.c2.select.OnField.key[i] + "=" + item.val();
                    }
                }
            }
            FieldCounter.p4.c2.SaveObject.requestObject.bn_parameter = parameters;
            let o = FieldCounter.p4.c2.SaveObject.requestObject;
            if (FieldCounter.p4.c2.OnValidation(o)) {
                swal({
                    title: "آیا این مورد " + FieldCounter.p4.c2.SaveObject.stateOption[FieldCounter.p4.c2.SaveObject.state] + " شود؟",
                    text: " این مورد ," + FieldCounter.p4.c2.SaveObject.stateOption[FieldCounter.p4.c2.SaveObject.state] + " می شود ",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "بله " + FieldCounter.p4.c2.SaveObject.stateOption[FieldCounter.p4.c2.SaveObject.state] + " شود",
                    cancelButtonText: "نه " + FieldCounter.p4.c2.SaveObject.stateOption[FieldCounter.p4.c2.SaveObject.state] + " نشود",
                    closeOnConfirm: false,
                    closeOnCancel: false
                }, function (isConfirm) {
                    if (isConfirm) {
                        LoadData({
                            request: 'proxy',
                            object: {
                                bn_message: o.bn_message.val(),
                                bn_title: o.bn_title.val(),
                                bn_subtitle: o.bn_subtitle.val(),
                                bn_ticker: o.bn_ticker.val(),
                                bn_largeIcon: o.bn_largeIcon.val(),
                                bn_vibrate_array: o.bn_vibrate_array.val(),
                                bn_request_code: o.bn_request_code.val(),
                                bn_request_flag: o.bn_request_flag.val(),
                                bn_number: o.bn_number.val(),
                                bn_going: o.bn_going.val(),
                                bn_auto_cancel: o.bn_auto_cancel.val(),
                                bn_package: o.bn_package,
                                bn_parameter: o.bn_parameter,
                                bn_EditID: o.bn_EditID
                            },
                            action: 'app_notification_controller',
                            'header-type': 'app-notification-' + FieldCounter.p4.c2.SaveObject.stateRequest[FieldCounter.p4.c2.SaveObject.state]
                        }, null, false, function (data) {
                            if (data === "1") {
                                FieldCounter.p4.c1.Load();
                                FieldCounter.p4.c2.select.OnField.Clear();
                                FieldCounter.p4.c2.select.OnInit();
                                FieldCounter.p4.c2.formWizard.reset(0);
                                swal("انجام شد", "این مورد " + FieldCounter.p4.c2.SaveObject.stateOption[FieldCounter.p4.c2.SaveObject.state] + " شد", "success");
                            } else {
                                swal("خطا", "این درخواست انجام نشد", "error");
                            }
                        });
                    }
                });
            } else {
                swal("خطا", "موارد مورد نیاز کامل شود", "error");
            }
        };
        FieldCounter.p4.c2.Load = function () {
            if (FieldCounter.p4.c2.formWizard === null)
                FieldCounter.p4.c2.formWizard = $('#wizard_with_validation').show();
            else {
                FieldCounter.p4.c2.formWizard.steps('destroy');
                FieldCounter.p4.c2.formWizard = $('#wizard_with_validation').show();
            }
            FieldCounter.p4.c2.formWizard.steps({
                headerTag: 'h3',
                bodyTag: 'fieldset',
                transitionEffect: 'slideLeft',
                labels: {
                    finish: "اعمال",
                    next: "بعدی",
                    previous: "قبلی",
                },
                onInit: function (event, currentIndex) {
                    $('form').submit(function (e) {
                        e.preventDefault();
                    });
                    $.AdminBSB.input.activate();
                    //Set tab width
                    let $tab = $(event.currentTarget).find('ul[role="tablist"] li'),
                        tabCount = $tab.length;
                    $tab.css('width', (100 / tabCount) + '%');
                    //set button waves effect
                    setButtonWavesEffect(event);
                },
                onStepChanging: function (event, currentIndex, newIndex) {
                    if (currentIndex > newIndex) {
                        return true;
                    }
                    if (currentIndex < newIndex) {
                        FieldCounter.p4.c2.formWizard.find('.body:eq(' + newIndex + ') label.error').remove();
                        FieldCounter.p4.c2.formWizard.find('.body:eq(' + newIndex + ') .error').removeClass('error');
                    }
                    FieldCounter.p4.c2.formWizard.validate().settings.ignore = ':disabled,:hidden';
                    return FieldCounter.p4.c2.formWizard.valid();
                },
                onStepChanged: function (event, currentIndex, priorIndex) {
                    setButtonWavesEffect(event);
                },
                onFinishing: function (event, currentIndex) {
                    FieldCounter.p4.c2.formWizard.validate().settings.ignore = ':disabled';
                    return FieldCounter.p4.c2.formWizard.valid();
                },
                onFinished: function (e) {
                    FieldCounter.p4.c2.OnSave(e);
                }
            });

            FieldCounter.p4.c2.formWizard.validate({
                highlight: function (input) {
                    $(input).parents('.form-line').addClass('error');
                },
                unhighlight: function (input) {
                    $(input).parents('.form-line').removeClass('error');
                },
                errorPlacement: function (error, element) {
                    $(element).parents('.form-group').append(error);
                }
            });
            FieldCounter.p4.c2.state.NotificationScreenBtn = $('.click-on-notification');
            FieldCounter.p4.c2.select.selector = $('.notification-screen').find("select");
            FieldCounter.p4.c2.select.OnInit();

            FieldCounter.p4.c2.state.NotificationScreen("up");

            FieldCounter.p4.c2.state.NotificationScreenBtn.unbind()
                .bind("tap", function () {
                    let btn = $(this);
                    FieldCounter.p4.c2.PackagePanel(btn, FieldCounter.p4.c2.state);
                });
            FieldCounter.p4.c2.formWizard.find("a[href='#finish']").text(FieldCounter.p4.c2.SaveObject.stateOption[FieldCounter.p4.c2.SaveObject.state]);
        };
        FieldCounter.p4.c2.state.NotificationScreen = function (value) {
            if (value === '0' || value === 'up') {
                $('.notification-screen').slideUp("slow");
            }
            if (value === '1' || value === 'down') {
                $('.notification-screen').slideDown("slow");
            }
        };
        FieldCounter.p4.c2.PackagePanel = function (btn, state) {
            btn.find('span').text(state[btn.attr('value')].text);
            btn.removeClass(state[btn.attr('value')].RemoveClass).addClass(state[btn.attr('value')].AddClass);
            btn.attr('value', state[btn.attr('value')].value);

            FieldCounter.p4.c2.state.NotificationScreen(btn.attr('value'));
        };
        FieldCounter.LoadApp.p4 = function () {
            FieldCounter.p4.c1.Load();
            FieldCounter.p4.c2.Load();
        };
        FieldCounter.p4.c1.OnEdit = function (id, index) {
            let o = FieldCounter.p4.c1.array[index];
            if (o.id === id) {
                FieldCounter.p4.c2.SaveObject.state = 0;
                FieldCounter.p4.c2.SaveObject.index = index;
                FieldCounter.p4.c2.SaveObject.requestObject.bn_EditID = id;
                FieldCounter.p4.c2.formWizard.find("a[href='#finish']").text(FieldCounter.p4.c2.SaveObject.stateOption[FieldCounter.p4.c2.SaveObject.state]);
                $('#message-text').val(o.message);
                $('#message-subject').val(o.title);
                $('#message-sub-text').val(o.subtitle);
                $('#message-notification').val(o.ticker);
                $('#message-image-url').val(o.largeicon);
                $('#message-vibration').val(o.vibrate_array);
                $('#message-request-code').val(o.request_code);
                $('#message-request-flag').val(o.request_flag);
                $('#message-code').val(o.number);
                $('#message-bn-going').val(o.going);
                $('#message-auto-cancel').val(o.auto_cancel);

                if (o.package.length > 0) {
                    FieldCounter.p4.c2.select.OnSetItem(o.package);
                    FieldCounter.p4.c2.PackagePanel(FieldCounter.p4.c2.state.NotificationScreenBtn, FieldCounter.p4.c2.state);
                }
            } else {
                swal("خطا", "پیام مورد نظر یافت نشد.", "error");
            }
        };
        FieldCounter.p4.c1.OnDelete = function (ID, tr) {
            swal({
                title: "آیا این مورد حذف شود؟",
                text: " این مورد ,حذف می شود ",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "بله حذف شود",
                cancelButtonText: "نه حذف نشود",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function (isConfirm) {
                if (isConfirm) {
                    LoadData({
                        request: 'proxy',
                        object: {id: ID},
                        action: 'app_notification_controller',
                        'header-type': 'app-notification-delete'
                    }, null, false, function (data) {
                        if (data === '1') {
                            tr.fadeOut(function (e) {
                                FieldCounter.p2.table.row(tr)
                                    .remove()
                                    .draw();
                            });
                            swal("حذف شد", "این مورد حذف شد", "success");
                        } else {
                            swal("خطا", "این درخواست انجام نشد", "error");
                        }
                    });
                } else {
                    swal("لغو شد", "این درخواست لغو شد", "error");
                }
            });
        };
        FieldCounter.p4.c1.OnActive = function (id, btn) {
            let data_value = btn.attr("data-value"), text = "";
            if (data_value === '0') {
                text = "غیر قابل نمایش";
            } else {
                text = "قابل نمایش";
            }
            swal({
                title: "آیا نمایش این مورد ویرایش شود؟",
                text: " این مورد " + text + " می شود ",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "بله " + text + " شود",
                cancelButtonText: "نه " + text + " نشود",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function (isConfirm) {
                if (isConfirm) {
                    LoadData({
                        request: 'proxy',
                        object: {id: id, show: data_value},
                        action: 'app_notification_controller',
                        'header-type': 'app-notification-active'
                    }, null, false, function (data) {
                        if (data === '1') {
                            if (data_value === '1') {
                                btn.attr('data-value', 0);
                                btn.removeClass('btn-warning').addClass('btn-info');
                                btn.find('i').empty().append('visibility');
                            } else {
                                btn.attr('data-value', 1);
                                btn.removeClass('btn-info').addClass('btn-warning');
                                btn.find('i').empty().append('visibility_off');
                            }
                            swal(text + " شد", "این مورد " + text + " شد", "success");
                        } else {
                            swal("خطا", "این درخواست انجام نشد", "error");
                        }
                    });
                } else {
                    swal("لغو شد", "این درخواست لغو شد", "error");
                }
            });
        };
        FieldCounter.p4.c1.OnChangeKey = function (id, btn) {
            btn.addClass('btn-warning').removeClass('btn-success');
            LoadData({
                request: 'proxy',
                object: {id: id},
                action: 'app_notification_controller',
                'header-type': 'app-notification-change-key'
            }, null, true, function (data) {
                if (data.state === 0) {
                    btn.addClass('btn-success').removeClass('btn-warning');
                    btn.find('code').text(data.key);
                } else {
                    btn.addClass('btn-danger').removeClass('btn-warning');
                }
            });
        };
        //#endregion p4 end


        $(document).ready(function () {
            $('form').submit(function (e) {
                e.preventDefault();
            });
            FieldCounter.LoadApp.p1();
            FieldCounter.LoadApp.p2();
            FieldCounter.LoadApp.p3();
            FieldCounter.LoadApp.p4();
        });

    }(jQuery));
</script>