========
Workflow
========

In Jam.py framework two tasks work at the same time: Administrator and Project. 
Each of which represents a tree of objects - there are the Administrator task 
tree and the Project task tree. So prior to consideration of the Jam.py workflow,
it's necessary to be familiar with the concept of the 
:doc:`task tree <task_tree>`.

The the Jam.py workflow is the following:

* When server.py is run it creates WSGI application that, in its own turn, 
  creates the Administrator task tree.
* The Project task tree is created on the server by Administrator after the 
  server receives first request from the Project client. To do so, the 
  Administrator uses metadata stored in admin.sqlite database in the root folder
  of the project. After creating a task tree the server application triggers the
  :doc:`on_created </refs/server/task/on_created>`
  event, that can be used to initialize the server task tree.
* When an application on the client (Administrator or Project) is first run in 
  the browser (after ``admin.html`` or ``index.html`` have been loaded) the 
  empty task object is built that sends to the server a request to initialize 
  itself.
* If the project 
  :doc:`safe mode </admin/project/parameters>`
  parameter is set, the framework checks if a user is logged, before executing 
  any request. If not, then it notifies the user that it must to login, the 
  application on the client creates a login form, and after the user inputs its 
  login and password, the client task sends the server a request to login.
* After successfull login or if the project
  :doc:`safe mode </admin/project/parameters>`
  parameter is not set, the server sends the client iformation about the 
  requested task. The task on the client builds its tree, based on this 
  information, assigns event handlers to its objects and executes 
  :doc:`on_page_loaded </refs/client/task/on_page_loaded>`
  event handler. 
* In this event handler a developer should attache JQuery event handler 
  functions to HTML elements of the DOM, defined in the ``index.html`` file. 
  In these functions a developer can use methods of items of the 
  :doc:`task tree <task_tree>`
  to perform some specific tasks. 
  These methods, when executed, trigger different events in which other methods 
  could be called and so on. See
  :doc:`Client side programming <interface/index>`.
* Items of the task tree, that have corresponding database tables, have methods 
  to read and write data in the server database. See 
  :doc:`Data programming <data/index>`.
* The report items generate the reports on the server, based on the LibrOffice
  teplates. See
  :doc:`Programming reports <reports/index>`.
* All the items, whose methods generate a request to the server, do it the 
  following way: they call the method of the task that sends to the server the 
  :doc:`ID </refs/client/abstr_item/at_id>`
  of the task, the
  :doc:`ID </refs/client/abstr_item/at_id>`
  the item, the type of the request and its parameters.
  The server on receiving the request, based on passed IDs, finds the task 
  (it can be Project task or Administrator task) and the item on the server, 
  executes the corresponing method with passed parameters and returns the result 
  of the execution to the client. These server methods could trigger their own 
  events that can override the default behavior. See
  :doc:`Server side programming <server/index>`

  
