< Overview | Table of content | Task tree >
Jam.py requires Python. If it is not installed you can get the latest version of Python at Python 3.7.7. From now on, we will only consider working with version 3 of the Python interpreter.
In a working directory we should create virtual environment:
mkdir myenv
cd my myenv
py -3.7 -m venv .Now, we activating our virtual enviroment:
Scripts\activate.batNow, we can installing Jam.py package
(myenv) > pip install jam.pyWe want to make a simple CRM application.
First we will create a folder for the new project, and in this folder we will run the jam-project.py script to create the project structures:
(myenv) > mkdir crm
(myenv) > cd crm
(myenv) > python <where is myenv dir>\bin\jam-project.pyThen run the server.py script created by jam-project.py.
(myenv) > python server.pyTo complete the creation of the project we'll start appbuilder page in any browser:
- First we are selecting the
project language, - After that, the
project parametersdialog will appear. Now we specify- The
captionand - The
nameof the project. - We will use
SQLITEdatabase. Let's name itcrm.sqlite.
- The
We completed the project creation.
Let's go to the project - application home page, and refresh it ( F5 ).
Here is now an empty menu.
-
Let's go back to the appbuilder page.
-
Go to the
Catalogsgroup and createCustomersitem. -
Now we specify its attributes:
Caption(that a user can see)Name(used in the programming code)Database table name
-
And three text fields
Firstname,LastnameandPhone.
As can be seen, while saving the
Customersitem, the server created a corresponding table in the project database. -
Let's go to the application home page and refresh it ( F5 ).
-
After that, in the appbuilder page, we open the
Customerscatalog again and for Lastname field specify:- the
requiredattribut, - the
defaultatribut
For
Catalogitem fields, whose default attribute is set, the default code creates a search functionality.[!Note]
This behaviour is changed, all viewed fields are searchable!
- the
Let's add a customer.
John Gordon 999-111-2222
Now in the Journals group we create Contacts item, and its fields
Date, datetime field,Customer, lookup field, that will store a reference to a record in theCustomerstable,FirstnameandPhone, lookup fields, but for this fields we specify theCustomerfield as amaster_fieldattribute. In this case theJam.pywon't create fields in the databaseContactstable.Notes, text field, lenght = 100
Let's open the Contacts item in the application home page.
Now, for convenience, we duplicate appbuilder page, then select the Task and create a lookup list Status, with next key, value pairs:
- 1: Contact
- 2: Meeting
- 3: Proposal
- 4: Close
-
Let's open
Contactsitem again and add alookup field Statusby specifying theStatus lookup list. -
Let's specify the
Customerfield attributes:is requiredtypeahead
Let's create the on_after_append event handler, will be triggered when a new record is added to the Contacts journal.
function on_after_append(item) {
item.date.value = new Date();
item.status.value = 1;
}and will set:
Datefield to the current date andStatusfield to theContactlookup value.
Let's write the on_field_get_text event handler
function on_field_get_text(field) {
if (field.field_name === 'customer' && field.value) {
return field.owner.firstname.lookup_value + ' ' + field.lookup_value;
}
}that will display in the Customer field as the customer's first and last name.
Now let's change the display order of the fields when viewing the journal,
and when editing. We can do this in the appbuilder page by clicking on the View form and Edit form buttons, respectively.
Let's change the default code. We delete the dynamic menu, created in the on_page_loaded event handler and instead, we will open to view form of the Contacts journal.
task.contacts.view($('#content'));For journals the default code allows to use filters.
Let's create filters for journal fields.
To demonstrate the filters we'll add another customer. We add a new customer:
Kathy Chase 111-22-3333
By default, html template with class default-view is used to creating a view form for all journals and catalogs, for which their own view form template is not defined.
Let's create a view form template for Contacts journal, by copying default-view template. We define its class as contacts-view. And now we add Customers button.
<div class="contacts-view">
<div class="form-body">
<div class="view-table"></div>
<div class="view-detail"></div>
</div>
<div class="form-footer">
<button id="delete-btn" class="btn expanded-btn pull-left" type="button">
<i class="icon-trash"></i> Delete<small class="muted"> [Ctrl+Del]</small>
</button>
<div id="report-btn" class="btn-group dropup">
<a class="btn expanded-btn dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-print"></i> Reports
<span class="caret"></span>
</a>
<ul class="dropdown-menu bottom-up">
</ul>
</div>
<button id="customers-btn" class="btn expanded-btn" type="button">
Customers
</button>
<button id="edit-btn" class="btn expanded-btn" type="button">
<i class="icon-edit"></i> Edit
</button>
<button id="new-btn" class="btn expanded-btn" type="button">
<i class="icon-plus"></i> New <small class="muted"> [Ctrl+Ins]</small>
</button>
</div>
</div>Let's create a event handler for the on_view_form_created event.
function on_view_form_created(item) {
item.view_form.find('#customers-btn').click(function() {
task.customers.view();
});
}So that click on the Customers button will open view form for Customers item.
We can define the display order of Contact journal records and create corresponding index for its database table.
Now we'll open the project.css file and change a bit the appearance of the application using css.
.dbtable {
border: 2px solid blue;
border-radius: 6px;
}
.dbtable td.customers {
color: black;
font-weight: bold;
}