text:
#include "roomfeatures_edit.h"
#include "ui_roomfeatures_edit.h"

#include <QSqlDatabase>
#include <QSqlQuery>
#include <QVariant>
#include <QMessageBox>
#include <QListWidgetItem>

/*
 *
 * On close, check if anything needs savinga
 *
 */

QListWidgetItem* lastitem = NULL;

bool edited_name = false;
bool edited_des = false;

RoomFeatures_Edit::RoomFeatures_Edit(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::RoomFeatures_Edit)
{
    ui->setupUi(this);

    ui->deleteButton->setEnabled(false);
    ui->saveButton->setEnabled(false);
    ui->saveAllButton->setEnabled(false);

    QSqlDatabase db = QSqlDatabase::database();
    QSqlQuery query(db);

    query.exec("SELECT * FROM jotel_features");

    while(query.next()) {
        QListWidgetItem* nitem = new QListWidgetItem;

        QVariant qv_id(query.value(0).toInt());

        QVariant qv_name(query.value(1).toString());
        QVariant qv_des(query.value(2).toString());

        QVariant qv_ename("0");
        QVariant qv_edess("0");

        nitem->setData(Qt::UserRole, qv_id);

        nitem->setData(Qt::UserRole + 1, qv_name);
        nitem->setData(Qt::UserRole + 2, qv_des);

        nitem->setData(Qt::UserRole + 3, qv_ename);
        nitem->setData(Qt::UserRole + 4, qv_edess);

        nitem->setText(query.value(1).toString());
        ui->rmfList->addItem(nitem);
    }

    if(ui->rmfList->count() == 0) {
        QMessageBox::warning(this, "No room features found", tr("No room features found. Press add to make a new feature"),
                             QMessageBox::Ok);
    }
}

RoomFeatures_Edit::~RoomFeatures_Edit()
{
    delete lastitem;
    delete ui;
}

void RoomFeatures_Edit::accept() {
}

void RoomFeatures_Edit::reject() {
    this->destroy();
}

void RoomFeatures_Edit::closeEvent(QCloseEvent* event) {
    bool nts = false;
    int listcount = ui->rmfList->count();

    for(int i = 0; i < listcount; i++) {
        if(ui->rmfList->item(i)->text().contains('*')) {
           nts = true;
        }
    }

    if(nts) {
        QMessageBox::StandardButton sts = QMessageBox::question(this, "Changes made",
                                                                "Do you want to exit without saving?",
                                                                QMessageBox::Yes | QMessageBox::No |
                                                                QMessageBox::Cancel);

        if(sts == QMessageBox::Yes) {
            // event->accept();
            this->destroy();
        } else {
            // event
        }
    }
}

/*
 * UserRole = ID
 * UserRole + 1 = ORIGINAL NAME
 * UserRole + 2 = DESCRIPTION
 *
 * UserRole + 3 = NAME THAT HAS BEEN EDITED
 * UserRole + 4 = DESCRIPTION THAT HAS BEEN EDITED
 */

void RoomFeatures_Edit::displayItemInformation(QListWidgetItem* item) {
        ui->saveButton->setEnabled(true);
        ui->saveAllButton->setEnabled(true);
        ui->deleteButton->setEnabled(true);

        if(lastitem == NULL) {
            lastitem = item;

            ui->featureNameEdit->setText(item->data(Qt::UserRole + 1).toString());

            if(item->data(Qt::UserRole + 2) == "0" || item->data(Qt::UserRole + 2) == "") {
                ui->featureDeacriptionEdit->clear();
                ui->featureDeacriptionEdit->setPlaceholderText("No description found. Edit feature description in here");
            } else {
                ui->featureDeacriptionEdit->setText(item->data(Qt::UserRole + 2).toString());
            }
        } else {
            if(item == lastitem) {
                return;
            }

            if(lastitem->data(Qt::UserRole + 3) != "0") {
                if(lastitem->data(Qt::UserRole + 3).toString() != ui->featureNameEdit->text()) {
                    QVariant qv_ename(ui->featureNameEdit->text());
                    lastitem->setData(Qt::UserRole + 3, qv_ename);
                }
            } else {
                if(lastitem->data(Qt::UserRole + 1).toString() != ui->featureNameEdit->text()) {
                    QVariant qv_ename(ui->featureNameEdit->text());
                    lastitem->setData(Qt::UserRole + 3, qv_ename);
                }
            }

            if(lastitem->data(Qt::UserRole + 4) != "0") {
                if(lastitem->data(Qt::UserRole + 4).toString() != ui->featureDeacriptionEdit->toPlainText()) {
                    QVariant qv_edes(ui->featureDeacriptionEdit->toPlainText());
                    lastitem->setData(Qt::UserRole + 4, qv_edes);
                }
            } else {
                if(lastitem->data(Qt::UserRole + 2).toString() != ui->featureDeacriptionEdit->toPlainText()) {
                    QVariant qv_edes(ui->featureDeacriptionEdit->toPlainText());
                    lastitem->setData(Qt::UserRole + 4, qv_edes);
                }
            }

            if(item->data(Qt::UserRole + 3) != "0") {
                ui->featureNameEdit->setText(item->data(Qt::UserRole + 3).toString());
            } else {
                ui->featureNameEdit->setText(item->data(Qt::UserRole + 1).toString());
            }

            if(item->data(Qt::UserRole + 4) != "0") {
                ui->featureDeacriptionEdit->setText(item->data(Qt::UserRole + 4).toString());
            } else {
                ui->featureDeacriptionEdit->setText(item->data(Qt::UserRole + 2).toString());
            }

            edited_name = false;
            edited_des = false;

            lastitem = item;
        }
}

void RoomFeatures_Edit::hasBeenEdited_Name(QString s) {
    if(ui->rmfList->currentItem()->data(Qt::UserRole + 1).toString() != ui->featureNameEdit->text()) {
        edited_name = true;
        if(!ui->rmfList->currentItem()->text().contains('*')) {
            ui->rmfList->currentItem()->setText(ui->rmfList->currentItem()->text() + " *");
        }
    } else {
        edited_name = false;

        if(ui->rmfList->currentItem()->text().contains('*')) {
            if(!edited_des && !edited_name) {
                ui->rmfList->currentItem()->setText(ui->rmfList->currentItem()->data(Qt::UserRole + 1).toString());
            }
        }
    }
}

void RoomFeatures_Edit::hasBeenEdited_Description() {
    if(ui->rmfList->currentItem()->data(Qt::UserRole + 2).toString() != ui->featureDeacriptionEdit->toPlainText()) {
        edited_des = true;
        if(!ui->rmfList->currentItem()->text().contains('*')) {
            ui->rmfList->currentItem()->setText(ui->rmfList->currentItem()->text() + " *");
        }
    } else {
        edited_des = false;

        if(ui->rmfList->currentItem()->text().contains('*')) {
            if(!edited_name && !edited_des) {
                ui->rmfList->currentItem()->setText(ui->rmfList->currentItem()->data(Qt::UserRole + 1).toString());
            }
        }
    }
}

void RoomFeatures_Edit::save() {
    if(!ui->rmfList->currentItem()->text().contains('*')) {
        QMessageBox::warning(this, "No changes found",
                             tr("Nothing has been edited for this feature"),
                             QMessageBox::Ok);
        return;
    }

    QSqlDatabase db = QSqlDatabase::database();

    QListWidgetItem* ci = ui->rmfList->currentItem();

    if(ci->data(Qt::UserRole + 1).toString() != ui->featureNameEdit->text()) {
        QVariant qv_name(ui->featureNameEdit->text());
        ci->setData(Qt::UserRole + 1, qv_name);
        ci->setText(ci->data(Qt::UserRole + 1).toString());

        QSqlQuery query(db);
        QString toexec(QString("UPDATE jotel_features SET name = '%1' WHERE id = '%2';").arg(
                           ui->featureNameEdit->text(), ci->data(Qt::UserRole).toString()));
        query.prepare(toexec);
        query.exec(toexec);
    }

    if(ci->data(Qt::UserRole + 2).toString() != ui->featureDeacriptionEdit->toPlainText()) {
        QVariant qv_des(ui->featureDeacriptionEdit->toPlainText());
        ci->setData(Qt::UserRole + 2, qv_des);

        if(ci->text().contains('*')) {
            ci->setText(ci->data(Qt::UserRole + 1).toString());
        }

        QSqlQuery query(db);
        QString toexec(QString("UPDATE jotel_features SET description = '%1' WHERE id = '%2';").arg(
                           ui->featureDeacriptionEdit->toPlainText(), ci->data(Qt::UserRole).toString()));
        query.prepare(toexec);
        query.exec(toexec);
    }

    QMessageBox::information(this, "Feature saved", "Feature has been saved", QMessageBox::Ok);
}

void RoomFeatures_Edit::save(QListWidgetItem *item) {
    QSqlDatabase db = QSqlDatabase::database();

    if(ui->rmfList->currentItem() == item) {
        if(item->data(Qt::UserRole + 1).toString() != ui->featureNameEdit->text()) {
            QVariant qv_name(ui->featureNameEdit->text());
            item->setData(Qt::UserRole + 1, qv_name);
            item->setText(item->data(Qt::UserRole + 1).toString());

            QSqlQuery query(db);
            QString toexec(QString("UPDATE jotel_features SET name = '%1' WHERE id = '%2';").arg(
                               ui->featureNameEdit->text(), item->data(Qt::UserRole).toString()));
            query.prepare(toexec);
            query.exec(toexec);
        }

        if(item->data(Qt::UserRole + 2).toString() != ui->featureDeacriptionEdit->toPlainText()) {
            QVariant qv_des(ui->featureDeacriptionEdit->toPlainText());
            item->setData(Qt::UserRole + 2, qv_des);

            if(item->text().contains('*')) {
                item->setText(item->data(Qt::UserRole + 1).toString());
            }

            QSqlQuery query(db);
            QString toexec(QString("UPDATE jotel_features SET description = '%1' WHERE id = '%2';").arg(
                               ui->featureDeacriptionEdit->toPlainText(), item->data(Qt::UserRole).toString()));
            query.prepare(toexec);
            query.exec(toexec);
        }
    } else {
        if(item->data(Qt::UserRole + 3) != "0") {
            QVariant qv_name(item->data(Qt::UserRole + 3).toString());
            QVariant qv_newname("0");

            item->setData(Qt::UserRole + 1, qv_name);
            item->setData(Qt::UserRole + 3, qv_newname);

            item->setText(item->data(Qt::UserRole + 1).toString());

            QSqlQuery query(db);
            QString toexec(QString("UPDATE jotel_features SET name = '%1' WHERE id = '%2';").arg(
                               item->text(), item->data(Qt::UserRole).toString()));
            query.prepare(toexec);
            query.exec(toexec);
        }

        if(item->data(Qt::UserRole + 4) != "0") {
            QVariant qv_des(item->data(Qt::UserRole + 4).toString());
            QVariant qv_newdes("0");

            item->setData(Qt::UserRole + 2, qv_des);
            item->setData(Qt::UserRole + 4, qv_newdes);

            if(item->text().contains('*')) {
                item->setText(item->data(Qt::UserRole + 1).toString());
            }

            QSqlQuery query(db);
            QString toexec(QString("UPDATE jotel_features SET description = '%1' WHERE id = '%2';").arg(
                               item->data(Qt::UserRole + 2).toString(), item->data(Qt::UserRole).toString()));
            query.prepare(toexec);
            query.exec(toexec);
        }
    }
}

void RoomFeatures_Edit::saveAll() {
    int listcount = ui->rmfList->count();

    if(listcount == 0) {
        QMessageBox::warning(this, "Nothing edited", "Cannot save all as no features have been edited", QMessageBox::Ok);
        return;
    }

    for(int i = 0; i < listcount; i++) {
        if(ui->rmfList->item(i)->text().contains('*')) {
           this->save(ui->rmfList->item(i));
        }
    }

    QMessageBox::information(this, "Saved", "All edited features have been saved", QMessageBox::Ok);
}

void RoomFeatures_Edit::addItem() {
    QSqlDatabase db = QSqlDatabase::database();
    QSqlQuery query(db);

    int newid = ui->rmfList->count() + 1;

    QListWidgetItem* item = new QListWidgetItem;
    item->setText(QString("New feature %1").arg(newid));

    if(query.exec(QString("INSERT INTO jotel_features (name) VALUES ('%1');").arg(item->text()))) {
        QSqlQuery idquery(db);

        idquery.exec(QString("SELECT id FROM jotel_features WHERE name = '%1';").arg(item->text()));

        if(idquery.next()) {
            QVariant qv_id(idquery.value(0).toInt());
            QVariant qv_name(item->text());

            QVariant qv_ename("0");
            QVariant qv_edes("0");

            item->setData(Qt::UserRole, qv_id);
            item->setData(Qt::UserRole + 1, qv_name);

            item->setData(Qt::UserRole + 3, qv_ename);
            item->setData(Qt::UserRole + 4, qv_edes);

            ui->rmfList->addItem(item);
        }
    }
}

void RoomFeatures_Edit::deleteItem() {
    QSqlDatabase db = QSqlDatabase::database();
    QSqlQuery query(db);

    QListWidgetItem* ci = ui->rmfList->currentItem();

    QMessageBox::StandardButton confirmation =
            QMessageBox::warning(this, "Delete feature", QString("Are you sure you want to delete feature '%1'?").arg(
                                                                        ci->text()), QMessageBox::Yes | QMessageBox::No);

    if(confirmation != QMessageBox::Yes) {
        return;
    }

    query.exec(QString("DELETE FROM jotel_features WHERE id = '%1'").arg(ci->data(Qt::UserRole).toInt()));
    ui->rmfList->takeItem(ui->rmfList->row(ci));

    QMessageBox::information(this, "Deleted", "Feature has been deleted", QMessageBox::Ok);
}


text:
/**
 * Create with IntelliJ IDEA
 * Project name : admin-frontend
 * Package name :
 * Author : qinxiangyu
 * User : qxy
 * Date : 17-10-24
 * Time : 下午2:44
 * ---------------------------------
 *
 */
(function () {
    'use strict';

    angular.module("BlurAdmin.pages.tool.queryUser",[]).config(routeConfig);

    /** @ngInject */
    function routeConfig($stateProvider,$urlRouterProvider) {
        $stateProvider
            .state('tool.queryUser', {
                url: '/queryUser',
                templateUrl: 'app/pages/tool/queryUser/queryUser_list.html',
                controller: "QueryUserListCtrl",
                title: 'User管理',
                sidebarMeta: {
                    icon: 'ion-ios-pulse',
                    order: 0,
                }
            })
    }
})();

redpajama_set_name: RedPajamaGithub


text:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_alignParentTop="true"
        android:background="@color/app_main_color_dark" >

        <ImageView
                   android:layout_width="@dimen/header_logo_width"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_marginLeft="20dp"
            android:src="@drawable/logo_with_text" >
        </ImageView>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativeLayout1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/main_menu_top_margin"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal" >

            <LinearLayout
                android:id="@+id/homeButton1"
                android:layout_width="@dimen/main_menu_button_size"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:gravity="center"
                android:orientation="vertical" >

                <ImageView
                    android:layout_width="@dimen/main_menu_image_size"
                    android:layout_height="@dimen/main_menu_image_size"
                    android:background="@drawable/home_profile" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:text="@string/home_my_profile"
                    android:textColor="#0d5c7c"
                    android:textSize="16sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/homeButton2"
                android:layout_width="@dimen/main_menu_button_size"
                android:layout_height="wrap_content"
                android:layout_marginLeft="60dp"
                android:clickable="true"
                android:gravity="center"
                android:orientation="vertical" >

                <ImageView
                    android:layout_width="@dimen/main_menu_image_size"
                    android:layout_height="@dimen/main_menu_image_size"
                    android:background="@drawable/home_calendar" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:text="@string/home_planning"
                    android:textColor="#0d5c7c"
                    android:textSize="16sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/homeButton3"
                android:layout_width="@dimen/main_menu_button_size"
                android:layout_height="wrap_content"
                android:layout_marginLeft="60dp"
                android:clickable="true"
                android:gravity="center"
                android:orientation="vertical" >

                <ImageView
                    android:layout_width="@dimen/main_menu_image_size"
                    android:layout_height="@dimen/main_menu_image_size"
                    android:background="@drawable/home_examin" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:text="@string/home_examen"
                    android:textColor="#0d5c7c"
                    android:textSize="16sp" />
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/main_menu_top_margin"
            android:clickable="true"
            android:gravity="center"
            android:orientation="horizontal" >

            <LinearLayout
                android:id="@+id/homeButton4"
                android:layout_width="@dimen/main_menu_button_size"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical" >

                <ImageView
                    android:layout_width="@dimen/main_menu_image_size"
                    android:layout_height="@dimen/main_menu_image_size"
                    android:background="@drawable/home_entrainement" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:text="@string/home_entrainement"
                    android:textColor="#0d5c7c"
                    android:textSize="16sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/homeButton5"
                android:layout_width="@dimen/main_menu_button_size"
                android:layout_height="wrap_content"
                android:layout_marginLeft="60dp"
                android:clickable="true"
                android:gravity="center"
                android:orientation="vertical" >

                <ImageView
                    android:layout_width="@dimen/main_menu_image_size"
                    android:layout_height="@dimen/main_menu_image_size"
                    android:background="@drawable/home_result" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:text="@string/home_resultats"
                    android:textColor="#0d5c7c"
                    android:textSize="16sp" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/homeButton6"
                android:layout_width="@dimen/main_menu_button_size"
                android:layout_height="wrap_content"
                android:layout_marginLeft="60dp"
                android:clickable="true"
                android:gravity="center"
                android:orientation="vertical" >

                <ImageView
                    android:layout_width="@dimen/main_menu_image_size"
                    android:layout_height="@dimen/main_menu_image_size"
                    android:background="@drawable/home_arrow" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="10dp"
                    android:text="@string/home_telechargement"
                    android:textColor="#0d5c7c"
                    android:textSize="16sp" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>


text:
package com.google.android.apps.iosched.io.model;

import com.google.gson.annotations.SerializedName;

public class Event {

    public String room;
    public String end_date;
    public String level;
    public String[] track;
    public String start_time;
    public String title;
    @SerializedName("abstract")
    public String _abstract;
    public String start_date;
    public String attending;
    public String has_streaming;
    public String end_time;
    public String livestream_url;
    public String[] youtube_url;
    public String id;
    public String tags;
    public String[] speaker_id;
    public String[] prereq;
}


text:
* fix: npm engine semver to allow node 6.10.x.
* chore: forked async-hook to updated its engine semver also

## v4.1.6

* fix: Use the correct `err` variable name in try/catch. Thanks to [@enko](https://github.com/enko).

## v4.1.5

* dep: update engine support ^4.7||^6.9.2||^7.3 to be same as `async-hook`'s
* dep: update `async-hook` to 1.7.1
* test: give `fs.watchFile` a little more time to pass on Travis CI

## v4.1.4

* feat: supports node 4.5.0 now
* test: add node 4 to travis

## v4.1.3

* dep: updated dependencies. Fix eslint issues
* feat: add runPromise

## v4.1.2

* chore: republishing to npm v4.1.2
* test: Update travis and strict npm engine to ^6.2.2

## v4.1.1

* test: Updated travis and strict npm engine to ^6.2.2

## v4.1.0

* feat: add `runAndReturn` method to get return value of `func` (from [@overlookmotel](https://github.com/overlookmotel/node-continuation-local-storage)).

## v4.0.1

* feat: Same API but major change to implementation. Uses **unofficial** [AsyncWrap](https://github.com/nodejs/node-eps/blob/async-wrap-ep/XXX-asyncwrap-api.md) instead of [async-listener](https://github.com/othiym23/async-listener).

### v3.1.0 (2014-07-28):

* Updated to use `async-listener@0.4.7` to pick up bug fixes.

### v3.0.0 (2013-12-14):

* Removed the notion of a "default" or "global" context per namespace.
  It only existed to create a simpler interface for developing and testing the module,
  and created the potential for nasty information disclosure bugs
  (see [issue #14](https://github.com/othiym23/node-continuation-local-storage/issues/14)
  for details). This is potentially a breaking change, if you're depending on the global context,
  so semver says we have to bump the major version.
* Added this changelog.

### v2.6.2 (2013-12-07):

* `async-listener` and `emitter-listener` dependency refresh.

### v2.6.1 (2013-11-29):

* `emitter-listener` has been extracted from `shimmer` into a standalone module
  for `namespace.bindEmitter()`.

### v2.6.0 (2013-11-27):

* When an error is thrown in a CLS-bound continuation chain, attach the active
  context for the namespace to which the chain is bound. This is necessary
  because CLS and asyncListeners actually do too good a job of cleaning up
  after errors, and so they don't escape the continuation chain. New Relic
  needs the context so it can get the transaction active when the error
  happened for error tracing.

### v2.5.2 (2013-10-30):

* `async-listener` dependency refresh for better support of node 0.8.0 - 0.8.3.

### v2.5.1 (2013-10-27):

* `async-listener` dependency refresh.

### v2.5.0 (2013-10-27):

* Relax the requirement that CLS contexts be pushed and popped from a stack,
  instead treating them as a set.  This allows context interleaving (i.e.
  using the lower-level `namespace.enter()` and `namespace.exit()` API without
  any strict ordering dependencies).  Everything works, but this still makes me
  a little uneasy.
* EEs can now be bound to multiple namespaces, although this is likely to be
  slow.

### v2.4.4 (2013-10-27):

* Even if you use an EE bound to a namespace outside a continuation chain, it
  shouldn't explode.

### v2.4.3 (2013-10-16):

* `async-listener` dependency refresh.

### v2.4.2 (2013-10-13):

* More tweaks for `async-listener` error handlers (just a dependency refresh).

### v2.4.1 (2013-10-12):

* `async-listener` error listeners have gotten lots of tweaks. Update to newest
  API.
* Only exit namespace context on error if a continuation chain is active.

### v2.4.0 (2013-10-11):

* `async-listener` now supports error listeners. Update to newest API.
* Namespace context should be exited on asynchronous errors.

### v2.3.4 (2013-10-03):

* When EEs are in the middle of emitting, make sure that calls to
  `emitter.removeListener` are testing against non-monkeypatched versions of
  the event handlers (necessary so certain Connect middleware functions, such
  as `connect.limit`, run correctly).

### v2.3.3 (2013-10-02):

* Ensure handler rebinding gets called even in case of errors.
* Be consistent about making sure contexts are kept in a sane state when errors
  are thrown in EEs.

### v2.3.2 (2013-10-02):

* Guard `on` / `addListener` remonkeypatching in `namespace.bindEmitter()` so
  that `shimmer` is only called to rebind if the monkeypatched versions have
  actually been replaced.
* Don't try to call emit if there are no listeners on a bound EE.
* Don't use `setImmediate` in tests, because it's not available in Node 0.8.x.

### v2.3.1 (2013-10-01):

* Update to newest version of `async-listener`.
* Fix typo.

### v2.3.0 (2013-09-30):

* EventEmitters can now be bound to CLS namespaces. Because EEs act as coupling
  points between asynchronous domains, it's necessary for the EE binding to
  capture the CLS context both when the listener is added, and when a matching
  handler is firing because of a matching event being emitted.

### v2.2.1 (2013-09-30):

* More tweaks to conform with `asyncListener` API changes.
* Many more test cases to ensure `asyncListener` stuff is working with Node
  0.8.x.

### v2.2.0 (2013-09-26):

* Square up with latest `async-listener` / node PR #6011 changes.

### v2.1.2 (2013-09-09):

* Document `namespace.createContext()`.
* Fix issue where a value was *always* being returned from `namespace.run()`,
  even on error.

### v2.1.1 (2013-09-03):

* Clean up minor typo in docs.

### v2.1.0 (2013-09-03):

* Incorporate documentation from failed CLS PR.
* `namespace.bind()` now also always exits the domain, even on error.
* Namespaces can be destroyed.
* `cls.reset()` allows tests to nuke all existing namespaces (use with care
  obviously).

### v2.0.0 (2013-09-01):

* Use `async-listener` polyfill instead of `cls-glue`.
* Incorporate tests from `cls-glue`.

### v1.1.1 (2013-09-01):

* Namespace exits context even on error.

### v1.1.0 (2013-07-30):

* Split createContext so it's part of the namespace API.
* Tweak error message to be more informative.

### v1.0.1 (2013-07-25):

* Correct Tim's email address.

### v1.0.0 (2013-07-25):

* Each application of CLS is allocated its own "namespace", which bind data to
  continuation chains, either using `.run()` or `.bind()` to create a new
  nested context. These nested contexts are prototype chains that point back to
  a "default" / "global" context, with the default context for each namespace
  being a prototype-free "data bag" created with `Object.create(null)`.

### v0.1.1 (2013-05-03):

* Document progress thus far.

### v0.1.0 (2013-05-03):

* First attempt: basic API, docs, and tests.


text:
#include <iostream>
#include <map>
#include <cstring>
#include <cstdlib>
#include "testcpp.h"

namespace {
class DrCb : public RdKafka::DeliveryReportCb {
 public:
  DrCb(RdKafka::ErrorCode exp_err) : cnt(0), exp_err(exp_err) {
  }

  void dr_cb(RdKafka::Message &msg) {
    Test::Say("Delivery report: " + RdKafka::err2str(msg.err()) + "\n");
    if (msg.err() != exp_err)
      Test::Fail("Delivery report: Expected " + RdKafka::err2str(exp_err) +
                 " but got " + RdKafka::err2str(msg.err()));
    cnt++;
  }

  int cnt;
  RdKafka::ErrorCode exp_err;
};
};  // namespace

/**
 * @brief Test producer auth failures.
 *
 * @param topic_known If true we make sure the producer knows about the topic
 *                    before restricting access to it and producing,
 *                    this should result in the ProduceRequest failing,
 *                    if false we restrict access prior to this which should
 *                    result in MetadataRequest failing.
 */

static void do_test_producer(bool topic_known) {
  Test::Say(tostr() << _C_MAG << "[ Test producer auth with topic "
                    << (topic_known ? "" : "not ") << "known ]\n");

  /* Create producer */
  RdKafka::Conf *conf;
  Test::conf_init(&conf, NULL, 20);

  std::string errstr;
  DrCb dr(RdKafka::ERR_NO_ERROR);
  conf->set("dr_cb", &dr, errstr);

  std::string bootstraps;
  if (conf->get("bootstrap.servers", bootstraps) != RdKafka::Conf::CONF_OK)
    Test::Fail("Failed to retrieve bootstrap.servers");

  RdKafka::Producer *p = RdKafka::Producer::create(conf, errstr);
  if (!p)
    Test::Fail("Failed to create Producer: " + errstr);
  delete conf;

  /* Create topic */
  std::string topic_unauth = Test::mk_topic_name("0115-unauthorized", 1);
  Test::create_topic(NULL, topic_unauth.c_str(), 3, 1);

  int exp_dr_cnt = 0;

  RdKafka::ErrorCode err;

  if (topic_known) {
    /* Produce a single message to make sure metadata is known. */
    Test::Say("Producing seeding message 0\n");
    err = p->produce(topic_unauth, RdKafka::Topic::PARTITION_UA,
                     RdKafka::Producer::RK_MSG_COPY, (void *)"0", 1, NULL, 0, 0,
                     NULL);
    TEST_ASSERT(!err, "produce() failed: %s", RdKafka::err2str(err).c_str());

    p->flush(-1);
    exp_dr_cnt++;
  }

  /* Add denying ACL for unauth topic */
  test_kafka_cmd(
      "kafka-acls.sh --bootstrap-server %s "
      "--add --deny-principal 'User:*' "
      "--operation All --deny-host '*' "
      "--topic '%s'",
      bootstraps.c_str(), topic_unauth.c_str());

  /* Produce message to any partition. */
  Test::Say("Producing message 1 to any partition\n");
  err = p->produce(topic_unauth, RdKafka::Topic::PARTITION_UA,
                   RdKafka::Producer::RK_MSG_COPY, (void *)"1", 1, NULL, 0, 0,
                   NULL);
  TEST_ASSERT(!err, "produce() failed: %s", RdKafka::err2str(err).c_str());
  exp_dr_cnt++;

  /* Produce message to specific partition. */
  Test::Say("Producing message 2 to partition 0\n");
  err = p->produce(topic_unauth, 0, RdKafka::Producer::RK_MSG_COPY, (void *)"3",
                   1, NULL, 0, 0, NULL);
  TEST_ASSERT(!err, "produce() failed: %s", RdKafka::err2str(err).c_str());
  exp_dr_cnt++;

  /* Wait for DRs */
  dr.exp_err = RdKafka::ERR_TOPIC_AUTHORIZATION_FAILED;
  p->flush(-1);

  /* Produce message to any and specific partition, should fail immediately. */
  Test::Say("Producing message 3 to any partition\n");
  err = p->produce(topic_unauth, RdKafka::Topic::PARTITION_UA,
                   RdKafka::Producer::RK_MSG_COPY, (void *)"3", 1, NULL, 0, 0,
                   NULL);
  TEST_ASSERT(err == dr.exp_err,
              "Expected produce() to fail with ERR_TOPIC_AUTHORIZATION_FAILED, "
              "not %s",
              RdKafka::err2str(err).c_str());

  /* Specific partition */
  Test::Say("Producing message 4 to partition 0\n");
  err = p->produce(topic_unauth, 0, RdKafka::Producer::RK_MSG_COPY, (void *)"4",
                   1, NULL, 0, 0, NULL);
  TEST_ASSERT(err == dr.exp_err,
              "Expected produce() to fail with ERR_TOPIC_AUTHORIZATION_FAILED, "
              "not %s",
              RdKafka::err2str(err).c_str());

  /* Final flush just to make sure */
  p->flush(-1);

  TEST_ASSERT(exp_dr_cnt == dr.cnt, "Expected %d deliveries, not %d",
              exp_dr_cnt, dr.cnt);

  Test::Say(tostr() << _C_GRN << "[ Test producer auth with topic "
                    << (topic_known ? "" : "not ") << "known: PASS ]\n");

  delete p;
}

extern "C" {
int main_0115_producer_auth(int argc, char **argv) {
  /* We can't bother passing Java security config to kafka-acls.sh */
  if (test_needs_auth()) {
    Test::Skip("Cluster authentication required\n");
    return 0;
  }

  do_test_producer(true);
  do_test_producer(false);

  return 0;
}
}


text:
exports.initial = function () {
  var configPath = "./build/test/files/config.test.json";
  var tmpdirPath = "./build/test/tmp";
  var newPath = tmpdirPath + "/config.test.json";
  try {
    fs.mkdirSync(tmpdirPath, "777");

    var c = new Config({
      filepath : configPath
    });
    eql({
      number : 1,
      string : "str",
      bool : true
    }, c.contents);
    c.filepath = newPath;
    c.contents.number = 2;
    c.contents.bool = false;
    c.writeSync();

    var c2 = new Config({
      filepath : newPath
    });
    eql({
      number : 2,
      string : "str",
      bool : false
    }, c2.contents);
  } finally {
    fs.unlinkSync(newPath);
    fs.rmdirSync(tmpdirPath);
  }
};


text:
package shopify

import (
    "time"
    "fmt"
)

const webhookBasePath = "/admin/webhooks"

type Webhook struct {
    ID                  int64      `json:"id,omitempty"`
    Address             string     `json:"address,omitempty"`
    Topic               string     `json:"topic,omitempty"`
    CreatedAt           *time.Time `json:"created_at,omitempty"`
    UpdatedAt           *time.Time `json:"updated_at,omitempty"`
    Format              string     `json:"format,omitempty"`
    Fields              []string   `json:"fields,omitempty"`
    MetafieldNamespaces []string   `json:"metafield_namespaces"`
}

type WebhooksResource struct {
    Webhooks []Webhook `json:"webhooks"`
}

type WebhookResource struct {
    Webhook Webhook `json:"webhook"`
}

type WebhookService interface {
    Get(interface{}) ([]Webhook, error)
    Count(interface{}) (int64, error)
    Paginate(interface{}) (int64, []Webhook, error)
    Find(int64, interface{}) (Webhook, error)
    Create(interface{}) (Webhook, error)
    Update(int64, interface{}) (Webhook, error)
    Delete(int64) (error)
}

type WebhookServiceRequest struct {
    client *Client
}

func (r *WebhookServiceRequest) Get(params interface{}) ([]Webhook, error) {
    endpoint := fmt.Sprintf("%s.json", webhookBasePath)
    resource := new(WebhooksResource)
    err := r.client.Get(endpoint, params, resource)

    return resource.Webhooks, err
}

func (r *WebhookServiceRequest) Count(params interface{}) (int64, error) {
    endpoint := fmt.Sprintf("%s/count.json", webhookBasePath)
    resource := new(Count)
    err := r.client.Get(endpoint, params, resource)

    return resource.Count, err
}

func (r *WebhookServiceRequest) Paginate(params interface{}) (int64, []Webhook, error) {
    webhooks := new(WebhooksResource)
    total := new(Count)

    webhooksEndpoint := fmt.Sprintf("%s.json", webhookBasePath)
    err := r.client.Get(webhooksEndpoint, params, webhooks)

    totalEndpoint := fmt.Sprintf("%s/count.json", webhookBasePath)
    err = r.client.Get(totalEndpoint, params, total)

    return total.Count, webhooks.Webhooks, err
}

func (r *WebhookServiceRequest) Find(webhookID int64, params interface{}) (Webhook, error) {
    endpoint := fmt.Sprintf("%s/%d.json", webhookBasePath, webhookID)
    resource := new(WebhookResource)
    err := r.client.Get(endpoint, params, resource)

    return resource.Webhook, err
}

func (r *WebhookServiceRequest) Create(params interface{}) (Webhook, error) {
    endpoint := fmt.Sprintf("%s.json", webhookBasePath)
    resource := new(WebhookResource)
    err := r.client.Post(endpoint, params, resource)

    return resource.Webhook, err
}

func (r *WebhookServiceRequest) Update(webhookID int64, params interface{}) (Webhook, error) {
    endpoint := fmt.Sprintf("%s/%d.json", webhookBasePath, webhookID)
    resource := new(WebhookResource)
    err := r.client.Put(endpoint, params, resource)

    return resource.Webhook, err
}

func (r *WebhookServiceRequest) Delete(webhookID int64) (error) {
    endpoint := fmt.Sprintf("%s/%d.json", webhookBasePath, webhookID)
    err := r.client.Delete(endpoint, nil, nil)

    return err
}


text:
$(function(){

    var Todo = Backbone.Model.extend({
        defaults: function(){
            return {
                done: false,
                text: "empty todo",
                order: todos.nextOrder()
            };
        },
    });

    var TodoList = Backbone.Collection.extend({
        model: Todo,

        localStorage: new Backbone.LocalStorage("todos"),

        done: function() {
            return this.where({done: true});
        },

        remaining: function() {
            return this.where({done: false});
        },

        nextOrder: function(){
            if (!this.length) return 1;
            return this.last().get("order") + 1;
        },

        comparator: 'order'
    });

    var todos = new TodoList;

    var TodoView = Backbone.View.extend({
        initialize: function(){
        },

        tagName: 'li',

        template: _.template($('#todo-template').html()),

        events: {
            'click .toggle': 'toggleDone',
            'dbclick .view': 'edit',
            'keypress .edit': 'checkEnter',
            'click .remove': 'remove'
        },

        render: function(){
            this.$el.html(this.template(this.model.toJSON()));
            return this;
        },

        edit: function(){
            this.$el.addClass('editing');
            this.input.focus();
        },

        remove: function(){
            this.model.destroy();
        },

        checkEnter: function(event){
            console.log(event);
            if (event.keyCode == 13) {
                this.close();
            }
        },

        close: function(){
            var val = this.input.val();
            if(!val) {
                this.remove();
            }
            else {
                this.$el.removeClass('editing');
                this.model.save({text:val});
            }

        },
    });

    var AppView = Backbone.View.extend({

        el: $('#app'),

        events: {
            'keypress #new-todo': 'checkEnter'
        },

        initialize: function(){
            this.input = this.$('#new-todo');

            this.listenTo(todos, 'add', this.addOne);
        },

        addOne: function(todo){
            var view = new TodoView({model:todo});
            this.$('ul').append(view.render().el);
        },

        checkEnter: function(e){
            if(e.keyCode != 13) return;
            var val = this.input.val();
            if(!val) return;

            todos.create({text:val});
            this.input.val('');
        }
    });

    var app = new AppView;
});


text:
<?php

namespace Magento\Framework\Config;

interface CacheInterface extends \Magento\Framework\Cache\FrontendInterface
{
}


text:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SFormItemSimplified.java
 *
 * Created on 11/10/2010
 */

package erp.mitm.form;

import erp.data.SDataConstants;
import erp.data.SDataConstantsSys;
import erp.data.SDataReadDescriptions;
import erp.data.SDataUtilities;
import erp.lib.SLibConstants;
import erp.lib.SLibTimeUtilities;
import erp.lib.SLibUtilities;
import erp.lib.form.SFormComponentItem;
import erp.lib.form.SFormField;
import erp.lib.form.SFormUtilities;
import erp.lib.form.SFormValidation;
import erp.mitm.data.SDataBrand;
import erp.mitm.data.SDataItem;
import erp.mitm.data.SDataItemGeneric;
import erp.mitm.data.SDataManufacturer;
import erp.mitm.data.SDataVariety;
import erp.mod.SModConsts;
import erp.mod.SModSysConsts;
import erp.mtrn.data.STrnUtilities;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.KeyEvent;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import sa.lib.SLibConsts;
import sa.lib.gui.SGuiConsts;
import sa.lib.gui.SGuiUtils;

/**
 *
 * @author Néstor Ávalos, Sergio Flores
 */
public class SFormItemSimplified extends javax.swing.JDialog implements erp.lib.form.SFormInterface, java.awt.event.ActionListener, java.awt.event.FocusListener, java.awt.event.ItemListener {

    private int mnFormType;
    private int mnFormResult;
    private int mnFormStatus;
    private boolean mbFirstTime;
    private boolean mbResetingForm;
    private java.util.Vector<erp.lib.form.SFormField> mvFields;
    private erp.client.SClientInterface miClient;

    private erp.mitm.data.SDataItem moItem;
    private erp.mitm.data.SDataItemGeneric moItemGeneric;
    private erp.lib.form.SFormField moFieldFkItemGenericId;
    private erp.lib.form.SFormField moFieldName;
    private erp.lib.form.SFormField moFieldNameShort;
    private erp.lib.form.SFormField moFieldCode;
    private erp.lib.form.SFormField moFieldItemKey;
    private erp.lib.form.SFormField moFieldFkUnitId;
    private erp.lib.form.SFormField moFieldFkAccountEbitdaTypeId;
    private erp.lib.form.SFormField moFieldFkFiscalAccountIncId;
    private erp.lib.form.SFormField moFieldFkFiscalAccountExpId;
    private erp.lib.form.SFormField moFieldIsReference;
    private erp.lib.form.SFormField moFieldIsPrepayment;
    private erp.lib.form.SFormField moFieldIsDeleted;

    private int[] manItemClassKey;

    /** Creates new form SFormItemSimplified */
    public SFormItemSimplified(erp.client.SClientInterface client) {
        super(client.getFrame(), true);
        miClient = client;
        mnFormType = SDataConstants.ITMU_ITEM;

        initComponents();
        initComponentsExtra();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel52 = new javax.swing.JPanel();
        jlFkItemGenericId = new javax.swing.JLabel();
        jcbFkItemGenericId = new javax.swing.JComboBox<SFormComponentItem>();
        jbPickItemGeneric = new javax.swing.JButton();
        jbEditItemGeneric = new javax.swing.JButton();
        jPanel54 = new javax.swing.JPanel();
        jlName = new javax.swing.JLabel();
        jtfName = new javax.swing.JTextField();
        jPanel60 = new javax.swing.JPanel();
        jlNameShort = new javax.swing.JLabel();
        jtfNameShort = new javax.swing.JTextField();
        jbCopyName = new javax.swing.JButton();
        jPanel56 = new javax.swing.JPanel();
        jlCode = new javax.swing.JLabel();
        jtfCode = new javax.swing.JTextField();
        jbComputeNewCode = new javax.swing.JButton();
        jPanel57 = new javax.swing.JPanel();
        jlItemKey = new javax.swing.JLabel();
        jtfItemKey = new javax.swing.JTextField();
        jPanel58 = new javax.swing.JPanel();
        jlItem = new javax.swing.JLabel();
        jtfItemNameRo = new javax.swing.JTextField();
        jPanel59 = new javax.swing.JPanel();
        jlItemShort = new javax.swing.JLabel();
        jtfItemNameShortRo = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jlFkUnitId = new javax.swing.JLabel();
        jcbFkUnitId = new javax.swing.JComboBox<SFormComponentItem>();
        jbEditUnit = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        jckIsReference = new javax.swing.JCheckBox();
        jckIsPrepayment = new javax.swing.JCheckBox();
        jPanel47 = new javax.swing.JPanel();
        jlFkAccountEbitdaTypeId = new javax.swing.JLabel();
        jcbFkAccountEbitdaTypeId = new javax.swing.JComboBox();
        jbFkAccountEbitdaTypeId = new javax.swing.JButton();
        jPanel45 = new javax.swing.JPanel();
        jlFkFiscalAccountIncId = new javax.swing.JLabel();
        jcbFkFiscalAccountIncId = new javax.swing.JComboBox<SFormComponentItem>();
        jbFkFiscalAccountIncId = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jPanel46 = new javax.swing.JPanel();
        jlFkFiscalAccountExpId = new javax.swing.JLabel();
        jcbFkFiscalAccountExpId = new javax.swing.JComboBox<SFormComponentItem>();
        jbFkFiscalAccountExpId = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanel48 = new javax.swing.JPanel();
        jlFkCfdProdServId_n = new javax.swing.JLabel();
        moKeyCfdProdServId_n = new sa.lib.gui.bean.SBeanFieldKey();
        jPanel7 = new javax.swing.JPanel();
        jlTariff = new javax.swing.JLabel();
        moTextTariff = new sa.lib.gui.bean.SBeanFieldText();
        jPanel8 = new javax.swing.JPanel();
        jckIsDeleted = new javax.swing.JCheckBox();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jtfPkItemId_Ro = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        jbOK = new javax.swing.JButton();
        jbCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ítem");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos del registro:"));
        jPanel2.setLayout(new java.awt.BorderLayout());

        jPanel4.setLayout(new java.awt.GridLayout(15, 1, 0, 5));

        jPanel52.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlFkItemGenericId.setText("Ítem genérico: *");
        jlFkItemGenericId.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel52.add(jlFkItemGenericId);

        jcbFkItemGenericId.setMaximumRowCount(12);
        jcbFkItemGenericId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbFkItemGenericId.setPreferredSize(new java.awt.Dimension(300, 23));
        jPanel52.add(jcbFkItemGenericId);

        jbPickItemGeneric.setText("jButton1");
        jbPickItemGeneric.setToolTipText("Seleccionar ítem genérico");
        jbPickItemGeneric.setFocusable(false);
        jbPickItemGeneric.setPreferredSize(new java.awt.Dimension(23, 23));
        jPanel52.add(jbPickItemGeneric);

        jbEditItemGeneric.setIcon(new javax.swing.ImageIcon(getClass().getResource("/erp/img/icon_std_edit.gif"))); // NOI18N
        jbEditItemGeneric.setToolTipText("Modificar ítem genérico");
        jbEditItemGeneric.setMargin(new java.awt.Insets(2, 0, 2, 0));
        jbEditItemGeneric.setPreferredSize(new java.awt.Dimension(23, 23));
        jPanel52.add(jbEditItemGeneric);

        jPanel4.add(jPanel52);

        jPanel54.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlName.setText("Nombre: *");
        jlName.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel54.add(jlName);

        jtfName.setPreferredSize(new java.awt.Dimension(300, 23));
        jPanel54.add(jtfName);

        jPanel4.add(jPanel54);

        jPanel60.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlNameShort.setText("Nombre cto.: *");
        jlNameShort.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel60.add(jlNameShort);

        jtfNameShort.setPreferredSize(new java.awt.Dimension(300, 23));
        jPanel60.add(jtfNameShort);

        jbCopyName.setIcon(new javax.swing.ImageIcon(getClass().getResource("/erp/img/icon_std_action.gif"))); // NOI18N
        jbCopyName.setToolTipText("Copiar nombre");
        jbCopyName.setFocusable(false);
        jbCopyName.setPreferredSize(new java.awt.Dimension(23, 22));
        jPanel60.add(jbCopyName);

        jPanel4.add(jPanel60);

        jPanel56.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlCode.setText("Código del ítem: *");
        jlCode.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel56.add(jlCode);

        jtfCode.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel56.add(jtfCode);

        jbComputeNewCode.setIcon(new javax.swing.ImageIcon(getClass().getResource("/erp/img/icon_std_wizard.gif"))); // NOI18N
        jbComputeNewCode.setToolTipText("Generar nuevo código");
        jbComputeNewCode.setFocusable(false);
        jbComputeNewCode.setPreferredSize(new java.awt.Dimension(23, 23));
        jPanel56.add(jbComputeNewCode);

        jPanel4.add(jPanel56);

        jPanel57.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlItemKey.setText("Clave del ítem: *");
        jlItemKey.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel57.add(jlItemKey);

        jtfItemKey.setPreferredSize(new java.awt.Dimension(150, 23));
        jPanel57.add(jtfItemKey);

        jPanel4.add(jPanel57);

        jPanel58.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlItem.setText("Ítem:");
        jlItem.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel58.add(jlItem);

        jtfItemNameRo.setEditable(false);
        jtfItemNameRo.setFocusable(false);
        jtfItemNameRo.setMinimumSize(new java.awt.Dimension(6, 23));
        jtfItemNameRo.setPreferredSize(new java.awt.Dimension(400, 23));
        jPanel58.add(jtfItemNameRo);

        jPanel4.add(jPanel58);

        jPanel59.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlItemShort.setText("Ítem corto:");
        jlItemShort.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel59.add(jlItemShort);

        jtfItemNameShortRo.setEditable(false);
        jtfItemNameShortRo.setFocusable(false);
        jtfItemNameShortRo.setPreferredSize(new java.awt.Dimension(400, 23));
        jPanel59.add(jtfItemNameShortRo);

        jPanel4.add(jPanel59);

        jPanel5.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlFkUnitId.setText("Unidad física: *");
        jlFkUnitId.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel5.add(jlFkUnitId);

        jcbFkUnitId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbFkUnitId.setPreferredSize(new java.awt.Dimension(125, 23));
        jPanel5.add(jcbFkUnitId);

        jbEditUnit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/erp/img/icon_std_edit.gif"))); // NOI18N
        jbEditUnit.setToolTipText("Modificar unidad física");
        jbEditUnit.setMargin(new java.awt.Insets(2, 0, 2, 0));
        jbEditUnit.setPreferredSize(new java.awt.Dimension(23, 23));
        jPanel5.add(jbEditUnit);

        jPanel4.add(jPanel5);

        jPanel9.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));

        jckIsReference.setText("Referencia obligatoria");
        jckIsReference.setPreferredSize(new java.awt.Dimension(150, 23));
        jPanel9.add(jckIsReference);

        jckIsPrepayment.setText("Es anticipo");
        jckIsPrepayment.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel9.add(jckIsPrepayment);

        jPanel4.add(jPanel9);

        jPanel47.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel47.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlFkAccountEbitdaTypeId.setText("Tipo EBITDA: *");
        jlFkAccountEbitdaTypeId.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel47.add(jlFkAccountEbitdaTypeId);

        jcbFkAccountEbitdaTypeId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbFkAccountEbitdaTypeId.setPreferredSize(new java.awt.Dimension(300, 23));
        jPanel47.add(jcbFkAccountEbitdaTypeId);

        jbFkAccountEbitdaTypeId.setText("...");
        jbFkAccountEbitdaTypeId.setToolTipText("Seleccionar tipo de cuenta EBITDA");
        jbFkAccountEbitdaTypeId.setFocusable(false);
        jbFkAccountEbitdaTypeId.setPreferredSize(new java.awt.Dimension(23, 23));
        jPanel47.add(jbFkAccountEbitdaTypeId);

        jPanel4.add(jPanel47);

        jPanel45.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel45.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlFkFiscalAccountIncId.setText("Cód. agrupador: *");
        jlFkFiscalAccountIncId.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel45.add(jlFkFiscalAccountIncId);

        jcbFkFiscalAccountIncId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbFkFiscalAccountIncId.setPreferredSize(new java.awt.Dimension(500, 23));
        jPanel45.add(jcbFkFiscalAccountIncId);

        jbFkFiscalAccountIncId.setText("jButton1");
        jbFkFiscalAccountIncId.setToolTipText("Seleccionar código agrupador SAT (ingresos)");
        jbFkFiscalAccountIncId.setFocusable(false);
        jbFkFiscalAccountIncId.setPreferredSize(new java.awt.Dimension(23, 23));
        jPanel45.add(jbFkFiscalAccountIncId);

        jLabel1.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel1.setText("(Ingresos SAT)");
        jLabel1.setPreferredSize(new java.awt.Dimension(125, 23));
        jPanel45.add(jLabel1);

        jPanel4.add(jPanel45);

        jPanel46.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel46.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlFkFiscalAccountExpId.setText("Cód. agrupador: *");
        jlFkFiscalAccountExpId.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel46.add(jlFkFiscalAccountExpId);

        jcbFkFiscalAccountExpId.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbFkFiscalAccountExpId.setPreferredSize(new java.awt.Dimension(500, 23));
        jPanel46.add(jcbFkFiscalAccountExpId);

        jbFkFiscalAccountExpId.setText("jButton1");
        jbFkFiscalAccountExpId.setToolTipText("Seleccionar código agrupador SAT (egresos)");
        jbFkFiscalAccountExpId.setFocusable(false);
        jbFkFiscalAccountExpId.setPreferredSize(new java.awt.Dimension(23, 23));
        jPanel46.add(jbFkFiscalAccountExpId);

        jLabel2.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel2.setText("(Egresos SAT)");
        jLabel2.setPreferredSize(new java.awt.Dimension(125, 23));
        jPanel46.add(jLabel2);

        jPanel4.add(jPanel46);

        jPanel48.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel48.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlFkCfdProdServId_n.setText("ProdServ SAT:");
        jlFkCfdProdServId_n.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel48.add(jlFkCfdProdServId_n);

        moKeyCfdProdServId_n.setMaximumRowCount(20);
        moKeyCfdProdServId_n.setPreferredSize(new java.awt.Dimension(500, 23));
        jPanel48.add(moKeyCfdProdServId_n);

        jPanel4.add(jPanel48);

        jPanel7.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0));

        jlTariff.setText("Fracc. arancelaria:");
        jlTariff.setPreferredSize(new java.awt.Dimension(100, 23));
        jPanel7.add(jlTariff);
        jPanel7.add(moTextTariff);

        jPanel4.add(jPanel7);

        jPanel8.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 0, 0));

        jckIsDeleted.setForeground(new java.awt.Color(204, 0, 0));
        jckIsDeleted.setText("Registro eliminado");
        jckIsDeleted.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
        jckIsDeleted.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jckIsDeleted.setPreferredSize(new java.awt.Dimension(200, 23));
        jPanel8.add(jckIsDeleted);

        jPanel4.add(jPanel8);

        jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH);

        getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

        jPanel1.setPreferredSize(new java.awt.Dimension(400, 33));
        jPanel1.setLayout(new java.awt.GridLayout(1, 2));

        jPanel3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jtfPkItemId_Ro.setEditable(false);
        jtfPkItemId_Ro.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jtfPkItemId_Ro.setToolTipText("ID del registro");
        jtfPkItemId_Ro.setFocusable(false);
        jtfPkItemId_Ro.setPreferredSize(new java.awt.Dimension(65, 23));
        jPanel3.add(jtfPkItemId_Ro);

        jPanel1.add(jPanel3);

        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));

        jbOK.setText("Aceptar");
        jbOK.setToolTipText("[Ctrl + Enter]");
        jbOK.setPreferredSize(new java.awt.Dimension(75, 23));
        jPanel6.add(jbOK);

        jbCancel.setText("Cancelar");
        jbCancel.setToolTipText("[Escape]");
        jPanel6.add(jbCancel);

        jPanel1.add(jPanel6);

        getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

        setSize(new java.awt.Dimension(816, 539));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        windowActivated();
    }//GEN-LAST:event_formWindowActivated

    private void initComponentsExtra() {
        mvFields = new Vector<SFormField>();
        manItemClassKey = null;

        moFieldFkItemGenericId = new SFormField(miClient, SLibConstants.DATA_TYPE_KEY, true, jcbFkItemGenericId, jlFkItemGenericId);
        moFieldName = new SFormField(miClient, SLibConstants.DATA_TYPE_STRING, true, jtfName, jlName);
        moFieldName.setLengthMax(50);
        moFieldNameShort = new SFormField(miClient, SLibConstants.DATA_TYPE_STRING, true, jtfNameShort, jlNameShort);
        moFieldNameShort.setLengthMax(25);
        moFieldCode = new SFormField(miClient, SLibConstants.DATA_TYPE_STRING, true, jtfCode, jlCode);
        moFieldCode.setLengthMax(10);
        moFieldItemKey = new SFormField(miClient, SLibConstants.DATA_TYPE_STRING, false, jtfItemKey, jlItemKey);
        moFieldItemKey.setLengthMax(35);
        moFieldFkUnitId = new SFormField(miClient, SLibConstants.DATA_TYPE_KEY, true, jcbFkUnitId, jlFkUnitId);
        moFieldFkAccountEbitdaTypeId = new SFormField(miClient, SLibConstants.DATA_TYPE_KEY, true, jcbFkAccountEbitdaTypeId, jlFkAccountEbitdaTypeId);
        moFieldFkAccountEbitdaTypeId.setPickerButton(jbFkAccountEbitdaTypeId);
        moFieldFkFiscalAccountIncId = new SFormField(miClient, SLibConstants.DATA_TYPE_KEY, true, jcbFkFiscalAccountIncId, jlFkFiscalAccountIncId);
        moFieldFkFiscalAccountIncId.setPickerButton(jbFkFiscalAccountIncId);
        moFieldFkFiscalAccountExpId = new SFormField(miClient, SLibConstants.DATA_TYPE_KEY, true, jcbFkFiscalAccountExpId, jlFkFiscalAccountExpId);
        moFieldFkFiscalAccountExpId.setPickerButton(jbFkFiscalAccountExpId);
        moFieldIsReference = new SFormField(miClient, SLibConstants.DATA_TYPE_BOOLEAN, false, jckIsReference);
        moFieldIsPrepayment = new SFormField(miClient, SLibConstants.DATA_TYPE_BOOLEAN, false, jckIsPrepayment);
        moFieldIsDeleted = new SFormField(miClient, SLibConstants.DATA_TYPE_BOOLEAN, false, jckIsDeleted);

        mvFields.add(moFieldFkItemGenericId);
        mvFields.add(moFieldName);
        mvFields.add(moFieldNameShort);
        mvFields.add(moFieldCode);
        mvFields.add(moFieldItemKey);
        mvFields.add(moFieldFkUnitId);
        mvFields.add(moFieldFkAccountEbitdaTypeId);
        mvFields.add(moFieldFkFiscalAccountIncId);
        mvFields.add(moFieldFkFiscalAccountExpId);
        mvFields.add(moFieldIsReference);
        mvFields.add(moFieldIsPrepayment);
        mvFields.add(moFieldIsDeleted);

        jbOK.addActionListener(this);
        jbCancel.addActionListener(this);
        jbCopyName.addActionListener(this);
        jbPickItemGeneric.addActionListener(this);
        jbEditItemGeneric.addActionListener(this);
        jbComputeNewCode.addActionListener(this);
        jbEditUnit.addActionListener(this);
        jbFkAccountEbitdaTypeId.addActionListener(this);
        jbFkFiscalAccountIncId.addActionListener(this);
        jbFkFiscalAccountExpId.addActionListener(this);

        jcbFkItemGenericId.addItemListener(this);

        jtfName.addFocusListener(this);
        jtfNameShort.addFocusListener(this);
        jtfCode.addFocusListener(this);

        AbstractAction actionOk = new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) { actionOk(); }
        };

        SFormUtilities.putActionMap(getRootPane(), actionOk, "ok", KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK);

        AbstractAction actionCancel = new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) { actionCancel(); }
        };

        SFormUtilities.putActionMap(getRootPane(), actionCancel, "cancel", KeyEvent.VK_ESCAPE, 0);
    }

    private void windowActivated() {
        if (mbFirstTime) {
            mbFirstTime = false;
            if (jcbFkItemGenericId.isEnabled()) {
                jcbFkItemGenericId.requestFocus();
            }
            else {
                jtfName.requestFocus();
            }
        }
    }

    private void setFormTitle() {
        setTitle("Ítem " + SDataReadDescriptions.getCatalogueDescription(miClient, SDataConstants.ITMS_CL_ITEM, manItemClassKey).toLowerCase());
    }

    private void actionPickItemGeneric() {
        miClient.pickOption(SDataConstants.ITMU_IGEN, moFieldFkItemGenericId, manItemClassKey);
    }

    private void actionEditItemGeneric() {
        if (getStock() != 0) {
            miClient.showMsgBoxWarning("No puede cambiar el valor del campo '" + jlFkItemGenericId.getText() + "' debido a que hay existencias en los inventarios.");
        }
        else {
            if (miClient.showMsgBoxConfirm("Cambiar el valor del campo '" + jlFkItemGenericId.getText() + "' afectará considerablemente la configuración del ítem.\n¿Está seguro que desea hacerlo?") == JOptionPane.YES_OPTION) {
                jbEditItemGeneric.setEnabled(false);
                jbPickItemGeneric.setEnabled(true);
                jcbFkItemGenericId.setEnabled(true);
                jcbFkItemGenericId.requestFocus();
            }
        }
    }

    private void actionEditUnit() {
        if (getStock() != 0) {
            miClient.showMsgBoxWarning("No puede cambiar el valor del campo '" + jlFkUnitId.getText() + "' debido a que hay existencias en los inventarios.");
        }
        else {
            jbEditUnit.setEnabled(false);
            jcbFkUnitId.setEnabled(true);
            jcbFkUnitId.requestFocus();
        }
    }

    private void actionFkAccountEbitdaTypeId() {
        miClient.pickOption(SDataConstants.FINU_TP_ACC_EBITDA, moFieldFkAccountEbitdaTypeId, null);
    }

    private void actionFkFiscalAccountIncId() {
        miClient.pickOption(SDataConstants.FINS_FISCAL_ACC, moFieldFkFiscalAccountIncId, null);
    }

    private void actionFkFiscalAccountExpId() {
        miClient.pickOption(SDataConstants.FINS_FISCAL_ACC, moFieldFkFiscalAccountExpId, null);
    }

    private double getStock() {
        double stock = 0;
        int nYear = 0;

        nYear = miClient.getSessionXXX().getSystemYear();

        try {
            stock = STrnUtilities.obtainStock(miClient, nYear, moItem.getPkItemId(), moItem.getFkUnitId(), SLibConstants.UNDEFINED, SLibConstants.UNDEFINED, SLibConstants.UNDEFINED, SLibConstants.UNDEFINED, SLibTimeUtilities.getEndOfYear(miClient.getSessionXXX().getSystemDate()), null);
        }
        catch (Exception e) {
            SLibUtilities.printOutException(this, e);
        }

        return stock;
    }

    private java.lang.String getItemKeyAndNameByPosition(SDataBrand brd, SDataManufacturer mfr, int position, int fieldType) {
        String text = "";

        switch (fieldType) {
            case SDataConstantsSys.ITMS_DEF_ITEM_KEY:
                if (!moItemGeneric.getIsItemLineApplying()) {
                    if (moItemGeneric.getKeyOrdinaryPosItemGeneric() == position) {
                        text = moItemGeneric.getCode();
                    }
                    else if (moItemGeneric.getKeyOrdinaryPosBrand() == position && brd.getPkBrandId() != SDataConstantsSys.ITMU_BRD_NA) {
                        text = brd.getCode();
                    }
                    else if (moItemGeneric.getKeyOrdinaryPosManufacturer() == position && mfr.getPkManufacturerId() != SDataConstantsSys.ITMU_MFR_NA) {
                        text = mfr.getCode();
                    }
                    else if (moItemGeneric.getKeyOrdinaryPosCode() == position) {
                        text = SLibUtilities.textTrim(moFieldCode.getString()).toUpperCase();
                    }
                }
                else {
                    if (moItemGeneric.getKeyLinePosItemGeneric() == position) {
                        text = moItemGeneric.getCode();
                    }
                    else if (moItemGeneric.getKeyLinePosBrand() == position && brd.getPkBrandId() != SDataConstantsSys.ITMU_BRD_NA) {
                        text = brd.getCode();
                    }
                    else if (moItemGeneric.getKeyLinePosManufacturer() == position && mfr.getPkManufacturerId() != SDataConstantsSys.ITMU_MFR_NA) {
                        text = mfr.getCode();
                    }
                }
                break;

            case SDataConstantsSys.ITMS_DEF_ITEM:
                if (!moItemGeneric.getIsItemLineApplying()) {
                    if (moItemGeneric.getNamingOrdinaryPosItemGeneric() == position) {
                        text = moItemGeneric.getItemGeneric();
                    }
                    else if (moItemGeneric.getNamingOrdinaryPosBrand() == position && brd.getPkBrandId() != SDataConstantsSys.ITMU_BRD_NA) {
                        text = brd.getBrand();
                    }
                    else if (moItemGeneric.getNamingOrdinaryPosManufacturer() == position && mfr.getPkManufacturerId() != SDataConstantsSys.ITMU_MFR_NA) {
                        text = mfr.getManufacturer();
                    }
                    else if (moItemGeneric.getNamingOrdinaryPosName() == position) {
                        text = SLibUtilities.textTrim(moFieldName.getString()).toUpperCase();
                    }
                }
                else {
                    if (moItemGeneric.getNamingLinePosItemGeneric() == position) {
                        text = moItemGeneric.getItemGeneric();
                    }
                    else if (moItemGeneric.getNamingLinePosBrand() == position && brd.getPkBrandId() != SDataConstantsSys.ITMU_BRD_NA) {
                        text = brd.getBrand();
                    }
                    else if (moItemGeneric.getNamingLinePosManufacturer() == position && mfr.getPkManufacturerId() != SDataConstantsSys.ITMU_MFR_NA) {
                        text = mfr.getManufacturer();
                    }
                }
                break;

            case SDataConstantsSys.ITMS_DEF_ITEM_SHORT:
                if (!moItemGeneric.getIsItemLineApplying()) {
                    if (moItemGeneric.getNamingOrdinaryPosItemGeneric() == position) {
                        text = moItemGeneric.getItemGenericShort();
                    }
                    else if (moItemGeneric.getNamingOrdinaryPosBrand() == position && brd.getPkBrandId() != SDataConstantsSys.ITMU_BRD_NA) {
                        text = brd.getBrand();
                    }
                    else if (moItemGeneric.getNamingOrdinaryPosManufacturer() == position && mfr.getPkManufacturerId() != SDataConstantsSys.ITMU_MFR_NA) {
                        text = mfr.getManufacturer();
                    }
                    else if (moItemGeneric.getNamingOrdinaryPosName() == position) {
                        text = moFieldNameShort.getString().toUpperCase();
                    }
                }
                else {
                    if (moItemGeneric.getNamingLinePosItemGeneric() == position) {
                        text = moItemGeneric.getItemGenericShort();
                    }
                    else if (moItemGeneric.getNamingLinePosBrand() == position && brd.getPkBrandId() != SDataConstantsSys.ITMU_BRD_NA) {
                        text = brd.getBrand();
                    }
                    else if (moItemGeneric.getNamingOrdinaryPosManufacturer() == position && mfr.getPkManufacturerId() != SDataConstantsSys.ITMU_MFR_NA) {
                        text = mfr.getManufacturer();
                    }
                }
                break;

            default:
                miClient.showMsgBoxWarning(SLibConstants.MSG_ERR_UTIL_UNKNOWN_OPTION);
        }

        return text;
    }

    private void readItemGenericParams() {
        jtfItemNameRo.setText("");
        jtfItemNameShortRo.setText("");

        if (jcbFkItemGenericId.getSelectedIndex() <= 0) {
            moItemGeneric = null;

            jtfNameShort.setEnabled(false);
            jbCopyName.setEnabled(false);

            jtfNameShort.setText("");
            jtfItemNameShortRo.setText("");

            jtfCode.setEnabled(false);
            jbComputeNewCode.setEnabled(false);
            jtfItemKey.setEditable(false);
            jtfItemKey.setFocusable(false);

            jtfCode.setText("");
            jtfItemKey.setText("");

            jcbFkUnitId.removeAllItems();
            jcbFkUnitId.setEnabled(false);
            jbEditUnit.setEnabled(false);
        }
        else {
            moItemGeneric = (SDataItemGeneric) SDataUtilities.readRegistry(miClient, SDataConstants.ITMU_IGEN, moFieldFkItemGenericId.getKey(), SLibConstants.EXEC_MODE_SILENT);

            if (moItemGeneric.getIsItemShortApplying()) {
                jtfNameShort.setEnabled(true);
                jbCopyName.setEnabled(true);
            }
            else {
                jtfNameShort.setEnabled(false);
                jbCopyName.setEnabled(false);

                jtfNameShort.setText("");
                jtfItemNameShortRo.setText("");
            }

            if (moItemGeneric.getIsItemKeyApplying()) {
                if (moItemGeneric.getIsItemKeyAutomatic()) {
                    jtfCode.setEnabled(true);
                    jbComputeNewCode.setEnabled(true);
                    jtfItemKey.setEditable(false);
                    jtfItemKey.setFocusable(false);
                }
                else {
                    jtfCode.setEnabled(false);
                    jbComputeNewCode.setEnabled(false);
                    jtfItemKey.setEditable(true);
                    jtfItemKey.setFocusable(true);
                }
            }
            else {
                jtfCode.setEnabled(false);
                jbComputeNewCode.setEnabled(false);
                jtfItemKey.setEditable(false);
                jtfItemKey.setFocusable(false);
            }

            if (!jtfCode.isEnabled()) {
                jtfCode.setText("");
            }

            if (!jtfItemKey.isEnabled()) {
                jtfItemKey.setText("");
            }

            SFormUtilities.populateComboBox(miClient, jcbFkUnitId, SDataConstants.ITMU_UNIT, new int[] { moItemGeneric.getFkUnitTypeId() });

            jcbFkUnitId.setEnabled(true);
            jbEditUnit.setEnabled(false);
        }
    }

    private void computeItemKeyAndName() {
        computeItemKey();
        computeItemName();
        computeItemNameShort();
    }

    private void computeItemKey() {
        String text = "";
        SDataBrand brd = null;
        SDataManufacturer mfr = null;
        SDataVariety var = null;

        if (jcbFkItemGenericId.getSelectedIndex() > 0) {
            if (moItemGeneric.getIsItemKeyApplying() && moItemGeneric.getIsItemKeyAutomatic()) {
                brd = (SDataBrand) SDataUtilities.readRegistry(miClient, SDataConstants.ITMU_BRD, new int[] { SDataConstantsSys.ITMU_BRD_NA }, SLibConstants.EXEC_MODE_SILENT);
                mfr = (SDataManufacturer) SDataUtilities.readRegistry(miClient, SDataConstants.ITMU_MFR, new int[] { SDataConstantsSys.ITMU_MFR_NA }, SLibConstants.EXEC_MODE_SILENT);

                if (!moItemGeneric.getIsItemLineApplying()) {
                    for (int pos = 1; pos <= SDataConstantsSys.ITMS_KEY_ORD_POS_QTY; pos++) {
                        text += SLibUtilities.textTrim(getItemKeyAndNameByPosition(brd, mfr, pos, SDataConstantsSys.ITMS_DEF_ITEM_KEY));
                    }
                }
                else {
                    for (int pos = 1; pos <= SDataConstantsSys.ITMS_KEY_LINE_POS_QTY; pos++) {
                        text += SLibUtilities.textTrim(getItemKeyAndNameByPosition(brd, mfr, pos, SDataConstantsSys.ITMS_DEF_ITEM_KEY));
                    }

                    text += moFieldCode.getString();
                }

                moFieldItemKey.setFieldValue(text);
            }
        }
    }

    private void computeItemName() {
        String text = "";
        SDataBrand brd = null;
        SDataManufacturer mfr = null;
        SDataVariety var = null;

        if (jcbFkItemGenericId.getSelectedIndex() > 0) {
            brd = (SDataBrand) SDataUtilities.readRegistry(miClient, SDataConstants.ITMU_BRD, new int[] { SDataConstantsSys.ITMU_BRD_NA }, SLibConstants.EXEC_MODE_SILENT);
            mfr = (SDataManufacturer) SDataUtilities.readRegistry(miClient, SDataConstants.ITMU_MFR, new int[] { SDataConstantsSys.ITMU_MFR_NA }, SLibConstants.EXEC_MODE_SILENT);

            if (!moItemGeneric.getIsItemLineApplying()) {
                for (int pos = 1; pos <= SDataConstantsSys.ITMS_NAM_ORD_POS_QTY; pos++) {
                    text += (text.length() == 0 ? "" : " ") + SLibUtilities.textTrim(getItemKeyAndNameByPosition(brd, mfr, pos, SDataConstantsSys.ITMS_DEF_ITEM));
                }
            }
            else {
                for (int pos = 1; pos <= SDataConstantsSys.ITMS_NAM_LINE_POS_QTY; pos++) {
                    text += (text.length() == 0 ? "" : " ") + SLibUtilities.textTrim(getItemKeyAndNameByPosition(brd, mfr, pos, SDataConstantsSys.ITMS_DEF_ITEM));
                }

                text += (text.length() == 0 ? "" : " ") + moFieldName.getString();
            }

            jtfItemNameRo.setText(SLibUtilities.textTrim(text));
            jtfItemNameRo.setCaretPosition(0);
        }
    }

    private void computeItemNameShort() {
        String text = "";
        SDataBrand brd = null;
        SDataManufacturer mfr = null;
        SDataVariety var = null;

        if (jcbFkItemGenericId.getSelectedIndex() > 0) {
            if (moItemGeneric.getIsItemShortApplying()) {
                brd = (SDataBrand) SDataUtilities.readRegistry(miClient, SDataConstants.ITMU_BRD, new int[] { SDataConstantsSys.ITMU_BRD_NA }, SLibConstants.EXEC_MODE_SILENT);
                mfr = (SDataManufacturer) SDataUtilities.readRegistry(miClient, SDataConstants.ITMU_MFR, new int[] { SDataConstantsSys.ITMU_MFR_NA }, SLibConstants.EXEC_MODE_SILENT);

                if (!moItemGeneric.getIsItemLineApplying()) {
                    for (int pos = 1; pos <= SDataConstantsSys.ITMS_NAM_ORD_POS_QTY; pos++) {
                        text += (text.length() == 0 ? "" : " ") + SLibUtilities.textTrim(getItemKeyAndNameByPosition(brd, mfr, pos, SDataConstantsSys.ITMS_DEF_ITEM_SHORT));
                    }
                }
                else {
                    for (int pos = 1; pos <= SDataConstantsSys.ITMS_NAM_LINE_POS_QTY; pos++) {
                        text += (text.length() == 0 ? "" : " ") + SLibUtilities.textTrim(getItemKeyAndNameByPosition(brd, mfr, pos, SDataConstantsSys.ITMS_DEF_ITEM_SHORT));
                    }

                    text += (text.length() == 0 ? "" : " ") + moFieldNameShort.getString();
                }

                jtfItemNameShortRo.setText(SLibUtilities.textTrim(text));
                jtfItemNameShortRo.setCaretPosition(0);
            }
        }
    }

    private void itemStateFkItemGenericId() {
        readItemGenericParams();
        computeItemKeyAndName();
    }

    private void actionCopyName() {
        if (jtfName.getText().length() > moFieldName.getLengthMax()) {
            jtfNameShort.setText(jtfName.getText().substring(0, moFieldName.getLengthMax() - 1));
        }
        else {
            jtfNameShort.setText(jtfName.getText());
        }
    }

    /*
     * Focus listener methods:
     */

    private void focusLostName() {
        computeItemKeyAndName();

        if (jtfNameShort.isEnabled() && SLibUtilities.textTrim(jtfNameShort.getText()).length() == 0) {
            actionCopyName();
        }
    }

    private void focusLostNameShort() {
        computeItemKeyAndName();
    }

    private void focusLostCode() {
        computeItemKeyAndName();
    }

    private void actionOk() {
        SFormValidation validation = formValidate();

        if (validation.getIsError()) {
            if (validation.getComponent() != null) {
                validation.getComponent().requestFocus();
            }
            if (validation.getMessage().length() > 0) {
                miClient.showMsgBoxWarning(validation.getMessage());
            }
        }
        else {
            mnFormResult = SLibConstants.FORM_RESULT_OK;
            setVisible(false);
        }
    }

    private void actionCancel() {
        mnFormResult = SLibConstants.FORM_RESULT_CANCEL;
        setVisible(false);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel45;
    private javax.swing.JPanel jPanel46;
    private javax.swing.JPanel jPanel47;
    private javax.swing.JPanel jPanel48;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel52;
    private javax.swing.JPanel jPanel54;
    private javax.swing.JPanel jPanel56;
    private javax.swing.JPanel jPanel57;
    private javax.swing.JPanel jPanel58;
    private javax.swing.JPanel jPanel59;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel60;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JButton jbCancel;
    private javax.swing.JButton jbComputeNewCode;
    private javax.swing.JButton jbCopyName;
    private javax.swing.JButton jbEditItemGeneric;
    private javax.swing.JButton jbEditUnit;
    private javax.swing.JButton jbFkAccountEbitdaTypeId;
    private javax.swing.JButton jbFkFiscalAccountExpId;
    private javax.swing.JButton jbFkFiscalAccountIncId;
    private javax.swing.JButton jbOK;
    private javax.swing.JButton jbPickItemGeneric;
    private javax.swing.JComboBox jcbFkAccountEbitdaTypeId;
    private javax.swing.JComboBox<SFormComponentItem> jcbFkFiscalAccountExpId;
    private javax.swing.JComboBox<SFormComponentItem> jcbFkFiscalAccountIncId;
    private javax.swing.JComboBox<SFormComponentItem> jcbFkItemGenericId;
    private javax.swing.JComboBox<SFormComponentItem> jcbFkUnitId;
    private javax.swing.JCheckBox jckIsDeleted;
    private javax.swing.JCheckBox jckIsPrepayment;
    private javax.swing.JCheckBox jckIsReference;
    private javax.swing.JLabel jlCode;
    private javax.swing.JLabel jlFkAccountEbitdaTypeId;
    private javax.swing.JLabel jlFkCfdProdServId_n;
    private javax.swing.JLabel jlFkFiscalAccountExpId;
    private javax.swing.JLabel jlFkFiscalAccountIncId;
    private javax.swing.JLabel jlFkItemGenericId;
    private javax.swing.JLabel jlFkUnitId;
    private javax.swing.JLabel jlItem;
    private javax.swing.JLabel jlItemKey;
    private javax.swing.JLabel jlItemShort;
    private javax.swing.JLabel jlName;
    private javax.swing.JLabel jlNameShort;
    private javax.swing.JLabel jlTariff;
    private javax.swing.JTextField jtfCode;
    private javax.swing.JTextField jtfItemKey;
    private javax.swing.JTextField jtfItemNameRo;
    private javax.swing.JTextField jtfItemNameShortRo;
    private javax.swing.JTextField jtfName;
    private javax.swing.JTextField jtfNameShort;
    private javax.swing.JTextField jtfPkItemId_Ro;
    private sa.lib.gui.bean.SBeanFieldKey moKeyCfdProdServId_n;
    private sa.lib.gui.bean.SBeanFieldText moTextTariff;
    // End of variables declaration//GEN-END:variables

    @Override
    public void formClearRegistry() {
        moItem = null;
    }

    @Override
    public void formReset() {
        mnFormResult = SLibConstants.UNDEFINED;
        mnFormStatus = SLibConstants.UNDEFINED;
        mbFirstTime = true;

        moItem = null;

        for (int i = 0; i < mvFields.size(); i++) {
            ((erp.lib.form.SFormField) mvFields.get(i)).resetField();
        }

        jcbFkItemGenericId.setEnabled(true);
        jbPickItemGeneric.setEnabled(true);
        jbEditItemGeneric.setEnabled(false);

        readItemGenericParams();

        jtfItemNameRo.setText("");
        jtfItemNameShortRo.setText("");
        jtfPkItemId_Ro.setText("");

        moFieldFkAccountEbitdaTypeId.setFieldValue(new int[] { SDataConstantsSys.NA });
        moFieldFkFiscalAccountIncId.setFieldValue(new int[] { SModSysConsts.FINS_FISCAL_ACC_NA });
        moFieldFkFiscalAccountExpId.setFieldValue(new int[] { SModSysConsts.FINS_FISCAL_ACC_NA });

        jckIsDeleted.setEnabled(false);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void formRefreshCatalogues() {
        mbResetingForm = true;

        SFormUtilities.populateComboBox(miClient, jcbFkItemGenericId, SDataConstants.ITMU_IGEN, manItemClassKey);
        SFormUtilities.populateComboBox(miClient, jcbFkUnitId, SDataConstants.ITMU_UNIT);
        SFormUtilities.populateComboBox(miClient, jcbFkAccountEbitdaTypeId, SDataConstants.FINU_TP_ACC_EBITDA);
        SFormUtilities.populateComboBox(miClient, jcbFkFiscalAccountIncId, SDataConstants.FINS_FISCAL_ACC);
        SFormUtilities.populateComboBox(miClient, jcbFkFiscalAccountExpId, SDataConstants.FINS_FISCAL_ACC);
        miClient.getSession().populateCatalogue(moKeyCfdProdServId_n, SModConsts.ITMS_CFD_PROD_SERV, SLibConsts.UNDEFINED, null);

        mbResetingForm = false;
    }

    @Override
    public erp.lib.form.SFormValidation formValidate() {
        SFormValidation validation = new SFormValidation();

        for (int i = 0; i < mvFields.size(); i++) {
            if (!((erp.lib.form.SFormField) mvFields.get(i)).validateField()){
                validation.setIsError(true);
                validation.setComponent(((erp.lib.form.SFormField) mvFields.get(i)).getComponent());
                break;
            }
        }

        if (!validation.getIsError()) {
            if (jcbFkItemGenericId.getSelectedIndex() <= 0) {
                validation.setMessage(SGuiConsts.ERR_MSG_FIELD_REQ + "'" + SGuiUtils.getLabelName(jlFkItemGenericId.getText())+ "'.");
            }
            else if (jcbFkUnitId.getSelectedIndex() <= 0) {
                validation.setMessage(SGuiConsts.ERR_MSG_FIELD_REQ + "'" + SGuiUtils.getLabelName(jlFkUnitId.getText())+ "'.");
            }
        }

        return validation;
    }

    @Override
    public void setFormStatus(int status) {
        mnFormStatus = status;
    }

    @Override
    public void setFormVisible(boolean visible) {
        setVisible(visible);
    }

    @Override
    public int getFormStatus() {
        return mnFormStatus;
    }

    @Override
    public int getFormResult() {
        return mnFormResult;
    }

    @Override
    public void setRegistry(erp.lib.data.SDataRegistry registry) {
        moItem = (SDataItem) registry;

        if (!moItem.getIsRegistryNew()) {
            manItemClassKey = new int[] { moItem.getDbmsDataItemGeneric().getFkItemCategoryId(), moItem.getDbmsDataItemGeneric().getFkItemClassId() };
            SFormUtilities.populateComboBox(miClient, jcbFkItemGenericId, SDataConstants.ITMU_IGEN, manItemClassKey);
            setFormTitle();
        }

        moFieldFkItemGenericId.setFieldValue(new int[] { moItem.getFkItemGenericId() });
        moFieldName.setFieldValue(moItem.getName());
        moFieldNameShort.setFieldValue(moItem.getNameShort());
        moFieldItemKey.setFieldValue(moItem.getKey());
        moFieldCode.setFieldValue(moItem.getCode());
        moFieldFkUnitId.setFieldValue(new int[] { moItem.getFkUnitId() });
        moFieldIsReference.setFieldValue(moItem.getIsReference());
        moFieldIsPrepayment.setFieldValue(moItem.getIsPrepayment());
        moFieldFkAccountEbitdaTypeId.setFieldValue(new int[] { moItem.getFkAccountEbitdaTypeId() });
        moFieldFkFiscalAccountIncId.setFieldValue(new int[] { moItem.getFkFiscalAccountIncId() });
        moFieldFkFiscalAccountExpId.setFieldValue(new int[] { moItem.getFkFiscalAccountExpId() });
        moKeyCfdProdServId_n.setValue(new int[] { moItem.getFkCfdProdServId_n() });
        moTextTariff.setValue(moItem.getTariff());
        moFieldIsDeleted.setFieldValue(moItem.getIsDeleted());

        if (moItem.getIsRegistryNew()) {
            jcbFkItemGenericId.setEnabled(true);
            jbPickItemGeneric.setEnabled(true);
            jbEditItemGeneric.setEnabled(false);
            jcbFkUnitId.setEnabled(true);
            jbEditUnit.setEnabled(false);
        }
        else {
            jcbFkItemGenericId.setEnabled(false);
            jbPickItemGeneric.setEnabled(false);
            jbEditItemGeneric.setEnabled(true);
            jcbFkUnitId.setEnabled(false);
            jbEditUnit.setEnabled(true);
        }

        computeItemKeyAndName();
        jtfPkItemId_Ro.setText("" + moItem.getPkItemId());

        jckIsDeleted.setEnabled(true);
    }

    @Override
    public erp.lib.data.SDataRegistry getRegistry() {
        if (moItem == null) {
            moItem = new SDataItem();
            moItem.setFkUserNewId(miClient.getSession().getUser().getPkUserId());

            moItem.setFkItemLineId_n(SLibConstants.UNDEFINED);
            moItem.setIsInventoriable(false);

            moItem.setFkItemStatusId(SModSysConsts.ITMS_ST_ITEM_ACT);
            moItem.setFkUnitUnitsContainedId(SDataConstantsSys.ITMU_UNIT_NA);
            moItem.setFkUnitUnitsVirtualId(SDataConstantsSys.ITMU_UNIT_NA);
            moItem.setFkUnitNetContentId(SDataConstantsSys.ITMU_UNIT_NA);
            moItem.setFkUnitNetContentUnitaryId(SDataConstantsSys.ITMU_UNIT_NA);
            moItem.setFkUnitAlternativeTypeId(SDataConstantsSys.ITMU_TP_UNIT_NA);
            moItem.setFkLevelTypeId(SDataConstantsSys.ITMU_TP_LEV_NA);
            moItem.setFkBrandId(SDataConstantsSys.ITMU_BRD_NA);
            moItem.setFkManufacturerId(SDataConstantsSys.ITMU_MFR_NA);
            moItem.setFkElementId(SDataConstantsSys.ITMU_EMT_NA);
            moItem.setFkVariety01Id(SDataConstantsSys.ITMU_VAR_NA);
            moItem.setFkVariety02Id(SDataConstantsSys.ITMU_VAR_NA);
            moItem.setFkVariety03Id(SDataConstantsSys.ITMU_VAR_NA);
            moItem.setFkAdministrativeConceptTypeId(SDataConstantsSys.NA);
            moItem.setFkTaxableConceptTypeId(SDataConstantsSys.NA);
            moItem.setFkItemPackageId_n(SLibConstants.UNDEFINED);
            moItem.setFkDefaultItemRefId_n(SLibConstants.UNDEFINED);

        }
        else {
            moItem.setFkUserEditId(miClient.getSession().getUser().getPkUserId());
        }

        moItem.setFkItemGenericId(moFieldFkItemGenericId.getKeyAsIntArray()[0]);
        moItem.setKey(moFieldItemKey.getString());
        moItem.setItem(jtfItemNameRo.getText());
        moItem.setItemShort(jtfItemNameShortRo.getText());
        moItem.setName(moFieldName.getString());
        moItem.setCode(moFieldCode.getString());
        moItem.setIsReference(moFieldIsReference.getBoolean());
        moItem.setIsPrepayment(moFieldIsPrepayment.getBoolean());
        moItem.setIsDeleted(moFieldIsDeleted.getBoolean());
        moItem.setFkUnitId(moFieldFkUnitId.getKeyAsIntArray()[0]);
        moItem.setFkAccountEbitdaTypeId(moFieldFkAccountEbitdaTypeId.getKeyAsIntArray()[0]);
        moItem.setFkFiscalAccountIncId(moFieldFkFiscalAccountIncId.getKeyAsIntArray()[0]);
        moItem.setFkFiscalAccountExpId(moFieldFkFiscalAccountExpId.getKeyAsIntArray()[0]);
        moItem.setFkCfdProdServId_n(moKeyCfdProdServId_n.getSelectedIndex() <= 0 ? 0 : moKeyCfdProdServId_n.getValue()[0]);
        moItem.setTariff(moTextTariff.getValue());

        return moItem;
    }

    @Override
    public void setValue(int type, Object value) {
        switch (type) {
            case SDataConstants.ITMX_ITEM_SIMPLE:
                switch ((Integer) value) {
                    case SDataConstants.ITMX_ITEM_IDX_SAL_PRO:
                        manItemClassKey = SDataConstantsSys.ITMS_CL_ITEM_SAL_PRO;
                        break;
                    case SDataConstants.ITMX_ITEM_IDX_SAL_SRV:
                        manItemClassKey = SDataConstantsSys.ITMS_CL_ITEM_SAL_SRV;
                        break;
                    case SDataConstants.ITMX_ITEM_IDX_ASS_ASS:
                        manItemClassKey = SDataConstantsSys.ITMS_CL_ITEM_ASS_ASS;
                        break;
                    case SDataConstants.ITMX_ITEM_IDX_PUR_CON:
                        manItemClassKey = SDataConstantsSys.ITMS_CL_ITEM_PUR_CON;
                        break;
                    case SDataConstants.ITMX_ITEM_IDX_PUR_EXP:
                        manItemClassKey = SDataConstantsSys.ITMS_CL_ITEM_PUR_EXP;
                        break;
                    case SDataConstants.ITMX_ITEM_IDX_EXP_MFG:
                        manItemClassKey = SDataConstantsSys.ITMS_CL_ITEM_EXP_MFG;
                        break;
                    case SDataConstants.ITMX_ITEM_IDX_EXP_OPE:
                        manItemClassKey = SDataConstantsSys.ITMS_CL_ITEM_EXP_OPE;
                        break;
                    default:
                }
                setFormTitle();
            default:
        }
    }

    @Override
    public Object getValue(int type) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public javax.swing.JLabel getTimeoutLabel() {
        return null;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() instanceof javax.swing.JButton) {
            javax.swing.JButton button = (javax.swing.JButton) e.getSource();

            if (button == jbOK) {
                actionOk();
            }
            else if (button == jbCancel) {
                actionCancel();
            }
            else if (button == jbPickItemGeneric) {
                actionPickItemGeneric();
            }
            else if (button == jbEditItemGeneric) {
                actionEditItemGeneric();
            }
            else if (button == jbEditUnit) {
                actionEditUnit();
            }
            else if (button == jbFkAccountEbitdaTypeId) {
                actionFkAccountEbitdaTypeId();
            }
            else if (button == jbFkFiscalAccountIncId) {
                actionFkFiscalAccountIncId();
            }
            else if (button == jbFkFiscalAccountExpId) {
                actionFkFiscalAccountExpId();
            }
        }
    }

    @Override
    public void itemStateChanged(ItemEvent e) {
        if (e.getSource() instanceof JComboBox) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                JComboBox comboBox = (JComboBox) e.getSource();

                if (comboBox == jcbFkItemGenericId) {
                    itemStateFkItemGenericId();
                }
            }
        }
    }

    @Override
    public void focusGained(FocusEvent e) {

    }

    @Override
    public void focusLost(FocusEvent e) {
        if (e.getSource() instanceof JTextField) {
            JTextField textField = (JTextField) e.getSource();

            if (textField == jtfName) {
                focusLostName();
            }
            else if (textField == jtfNameShort) {
                focusLostNameShort();
            }
            else if (textField == jtfCode) {
                focusLostCode();
            }
        }
    }
}


text:
require 'test_helper'

class HTMLTOCRenderTest < Greenmat::TestCase
  def setup
    @renderer = Greenmat::Render::HTML_TOC
    @markdown = <<-Markdown.strip_heredoc
      # A title
      ## A __nice__ subtitle
      ## Another one
      ### A sub-sub-title
      ### 見出し
    Markdown
  end

  def test_simple_toc_render
    output = render(@markdown)

    assert output.start_with?("
")
    assert output.end_with?("
")

    assert_equal 3, output.scan("
").length
    assert_equal 5, output.scan("
").length
  end

  def test_granular_toc_render
    output = render(@markdown, with: { nesting_level: 2 })

    assert output.start_with?("
")
    assert output.end_with?("
")

    assert_equal 3, output.scan("
").length
    assert !output.include?("A sub-sub title")
  end

  def test_granular_toc_render_with_range
    output = render(@markdown, with: { nesting_level: 2..5 }).strip

    assert output.start_with?("
")
    assert output.end_with?("
")

    assert output.match("Another one")
    assert output.match("A sub-sub-title")
    assert output.match("見出し")

    refute output.match("A title")
    refute output.match("A really tiny title")
  end

  def test_toc_heading_id
    output = render(@markdown)

    assert_match /a-title/, output
    assert_match /a-nice-subtitle/, output
    assert_match /another-one/, output
    assert_match /a-sub-sub-title/, output
    # the part number length varies depending on architecture (32b or 64b)
    assert_match /part-(37870bf)?a194139f/, output
  end

  def test_toc_heading_with_hyphen_and_equal
    output = render("# Hello World\n\n-\n\n=")

    assert_equal 1, output.scan("
").length
    assert !output.include?('')
  end

  def test_anchor_generation_with_edge_cases
    # Imported from ActiveSupport::Inflector#parameterize's tests
    titles = {
      "Donald E. Knuth"                     => "donald-e-knuth",
      "Random text with *(bad)* characters" => "random-text-with-bad-characters",
      "!@#Surrounding bad characters!@#"    => "surrounding-bad-characters",
      "Squeeze   separators"                => "squeeze-separators",
      "Test with + sign"                    => "test-with-sign",
      "Test with a Namespaced::Class"       => "test-with-a-namespaced-class"
    }

    titles.each do |title, anchor|
      assert_match %("##{anchor}"), render("# #{title}")
    end
  end

  def test_inline_markup_is_not_escaped
    output = render(@markdown)

    assert_match "A nice subtitle", output
    assert_no_match %r{<}, output
  end

  def test_inline_markup_escaping
    output = render(@markdown, with: [:escape_html])

    assert_match "<strong>", output
    assert_no_match %r{}, output
  end

  def test_ignoring_fenced_code_blocks_comments
    markdown = <<-Markdown.strip_heredoc
    # Hello world !

    ~~~ruby
    # This is a comment
    ~~~
    Markdown

    output = render(markdown)

    assert output.match("Hello world")
    refute output.match("This is a comment")
  end
end


text:
e(document).ready(function(){
			$('#email').autocomplete('dom_autocomplete.pl',{extraParams:{cities:1},cacheLength:10,delay:10,matchSubset:1,autoFill:true,maxItemsToShow:10});

			});