text: (function(a,b){"use strict";function c(){var c={"ROOT_TYPE":1,"USERS_TYPE":2,"ROLES_TYPE":3,"TASKS_TYPE":4,"TASK_TYPE":5,"ITEMS_TYPE":6,"JOURNALS_TYPE":7,"TABLES_TYPE":8,"REPORTS_TYPE":9,"ITEM_TYPE":10,"JOURNAL_TYPE":11,"TABLE_TYPE":12,"REPORT_TYPE":13,"DETAIL_TYPE":14},d={"SQLITE":1,"FIREBIRD":2,"POSTGRESQL":3,"MYSQL":4};function e(a){var d;b.btns_panel.show();a.task.cur_item_title=a.f_name.value;if(a.type_id.value===c.ROOT_TYPE){b.view_panel.empty();b.view_panel.append('<div class="admin-task-info"></div>');u(b);b.right_panel.show();b.btns_panel.empty();s(a.task);}else if(a.type_id.value===c.USERS_TYPE){b.right_panel.hide();a.task.sys_users.view_options.fields=['id','f_name','f_login','f_password','f_role','f_admin'];a.task.sys_users.view(b.view_panel);}else if(a.type_id.value===c.ROLES_TYPE){b.right_panel.hide();a.task.sys_roles.view(b.view_panel);}else{b.right_panel.show();a.task.sys_items.tree_changed(a.task.sys_items);}}function f(a,b){a.server('server_update_has_children',[]);a.item_tree.set_where({has_children:true});a.item_tree.set_order_by(['f_index']);a.item_tree.open({fields:['id','parent','f_name','f_item_name','type_id','task_id','f_index']});a.item_tree.locate('type_id',c.TASK_TYPE);a.tree.expand(a.tree.selected_node);a.item_tree.on_after_scroll=e;if(b)a.item_tree.locate('id',b);else a.item_tree.locate('type_id',c.ROOT_TYPE);a.tree_panel.show();e(a.item_tree);}function g(a){var b=a.sys_params.view_options.fields;b.splice(b.indexOf('f_field_id_gen'),1);b.push('id');a.sys_params.open({fields:b});}function h(a){a.server('server_get_task_dict',function(b){a.task_dict=b[0];a.task_item_fields=b[1];});}function i(b){var e,i,j;b._manual_update=false;b.init_project=true;b.item_types=c;b.db_types=d;b.old_forms=true;g(b);if(!b.sys_params.f_language.value){b.sys_params.edit_options.title='Project language';b.sys_params.edit_record();return;}b.sys_tasks.open();if(!b.sys_tasks.f_db_type.value){j=['f_name','f_item_name','f_db_type','f_server','f_alias','f_login','f_password','f_host','f_port','f_encoding'];b.sys_tasks.set_edit_fields(j);b.server('server_set_project_langage',[b.sys_params.f_language.value]);b.sys_tasks.edit_options.title=b.language.project_params;b.sys_tasks.edit_record();return;}if(b.sys_params.f_language.value&&b.sys_tasks.f_db_type.value){b.init_project=false;b.server('server_get_db_options',[b.sys_tasks.f_db_type.value],function(a){b.db_options=a[0];i=a[1];if(i){b.warning(i);return;}});b.buttons_info={divider:{},project_params:{handler:E,short_cut:'F2',key_code:113,editor:true},db:{handler:F,short_cut:'F4',key_code:115,editor:true},'export':{handler:M,short_cut:'Ctrl-E',key_code:69,key_ctrl:true},'import':{handler:L,short_cut:'Ctrl-I',key_code:73,key_ctrl:true},find:{handler:H,short_cut:'Alt-F',key_code:70,key_alt:true},print:{handler:J},client_module:{handler:b.sys_items.edit_client,item:b.sys_items,short_cut:'F8',key_code:119,editor:true},server_module:{handler:b.sys_items.edit_server,item:b.sys_items,short_cut:'F9',key_code:120,editor:true},'index.html':{handler:b.sys_items.edit_index_html,item:b.sys_items,short_cut:'F10',key_code:121,editor:true},'project.css':{handler:b.sys_items.edit_project_css,item:b.sys_items,short_cut:'F11',key_code:122,editor:true},'Lookup lists':{handler:G,editor:true},viewing:{handler:b.sys_items.view_setup,item:b.sys_items,editor:true},editing:{handler:b.sys_items.edit_setup,item:b.sys_items,editor:true},filters:{handler:b.sys_items.filters_setup,item:b.sys_items,editor:true},details:{handler:b.sys_items.details_setup,item:b.sys_items,editor:true},order:{handler:b.sys_items.order_setup,item:b.sys_items,editor:true},indices:{handler:b.sys_items.indices_setup,item:b.sys_items,editor:true},foreign_keys:{handler:b.sys_items.foreign_keys_setup,item:b.sys_items,editor:true},reports:{handler:b.sys_items.reports_setup,item:b.sys_items,editor:true},report_params:{handler:b.sys_items.report_params_setup,item:b.sys_items,editor:true,short_cut:'F7',key_code:118,editor:true},privileges:{handler:b.sys_items.privileges_setup,item:b.sys_items,editor:true}};a("#content").show();a("#title").html('Application builder');if(b.safe_mode){a("#user-info").text(b.user_info.role_name+' '+b.user_info.user_name);a('#log-out').show().click(function(a){a.preventDefault();b.logout();});}b.left_panel=a("#left-panel");b.center_panel=a("#center-panel");b.right_panel=a("#right-panel");b.btns_panel=a("#btns-panel");b.view_panel=a("#view-panel");b.tree_panel=a("#tree-panel");b.code_editor=a("#code-editor");b.sys_code_editor.init_tabs(b);b.item_tree=b.sys_items.copy({handlers:false,details:false});b.item_tree.on_field_get_text=function(a){if(a.field_name==='f_name')if(a.owner.type_id.value===c.TASK_TYPE)return b.language.groups;};b.tree=b.item_tree.create_tree(b.tree_panel,{id_field:'id',parent_field:'parent',text_field:'f_name',parent_of_root_value:0});b.tree.$element.height(a("#left-panel").height());f(b);h(b);Q(b);a(window).on('focus.task',function(a){u(b);});a(window).on('resize.task',function(){k(b);});l(b);}}var j;function k(a){clearTimeout(j);j=setTimeout(function(){l(a);},100);}function l(b){var c=a(window).height()-(a('#task-tabs').offset().top+a('#task-tabs').outerHeight(true))-10;m(b,c);o(b,c);if(a('ul#task-tabs li.active').attr('id')==='admin'){n(b,c);b.sys_items.update_controls();}}function m(b,c){var d=a('#left-panel #tree-panel .dbtree');if(b.tree_panel.outerHeight(true)!==c){d.hide();b.tree_panel.outerHeight(c,true);b.right_panel.outerHeight(c,true);c=b.tree_panel.height();d.outerHeight(b.tree_panel.height(),true);d.show();b.btns_panel.outerHeight(b.right_panel.height(),true);}}function n(b,c){var d=a('#center-panel .dbtable'),e=a('#center-panel .title').outerHeight(true),f=a('#center-panel .modal-footer').outerHeight(true),g;if(d.length){g=d.data('dbtable');if(g.height()!==c-e-f)g.height(c-e-f);}}function o(a,b){a.sys_code_editor.resize(a,b);}function p(b,c,d,e,f,g,h,i,j,k,l){function m(a){var f,g,h,i;a.preventDefault();a.stopImmediatePropagation();a.stopPropagation();if(e)h=e,i=e.id.value;else{h=b;i=0;}d.call(h,h,b.language[c]);}var n='',o='',p='',q;if(c){n=b.language[c];if(!n)n=c;}if(f)o='<i class="'+f+'"></i>';if(g)p='<small class="muted">&nbsp;['+g+']</small>';q=a('<button class="btn vert-btn text-center '+c+'" type="button">'+o+' '+n+p+'</button>');b.btns_panel.append(q);if(d)q.click(function(a){m(a);});if(h){a(window).off('keydown.'+c);a(window).on('keydown.'+c,(function(a){var b=(a.keyCode?a.keyCode:a.which);if(i&&a.ctrlKey&&h===a.keyCode||j&&a.shiftKey&&h===a.keyCode||k&&a.altKey&&h===a.keyCode||!i&&!j&&!k&&h===a.keyCode){a.preventDefault();m(a);}}));}}function q(){b.btns_panel.append('<div class="btns-divider">');}function r(a,b){var c=0,d=b.length,e,f;for(;c<d;c++){e=b[c];if(e==='divider')q();else{f=a.buttons_info[e];p(a,e,f.handler,f.item,f.icon,f.short_cut,f.key_code,f.key_ctrl,f.key_shift,f.key_alt,f.editor);}}}function s(a){r(a,['project_params','divider','db','divider','export','import','divider','find','print']);}function t(b){var c,d,e=[];if(b.reports){for(var f=0;f<b.reports.length;f++)if(b.reports[f].can_view())e.push(b.reports[f]);if(e.length){c=b.view_form.find("#report-btn ul");for(var f=0;f<e.length;f++){d=a('<li><a href="#">'+e[f].item_caption+'</a></li>');d.find('a').data('report',e[f]);d.on('click','a',function(){a(this).data('report').print();});c.append(d);}}else b.view_form.find("#report-btn").hide();}else b.view_form.find("#report-btn").hide();}function u(b){if(b._importing)return;if(b.cur_task_info)a('.admin-task-info').html(b.cur_task_info);b.server('server_get_task_info',function(c){var d=c[1],e=c[2],f=c[3];b.task_name=c[0];b.server_started=c[4];b.cur_task_info='<h4><span class="editor-title">'+d+'</span> <span class="muted">'+f+'</span> v. '+e+'</h4>';a('.admin-task-info').html(b.cur_task_info);});}function v(a){var b=a.sys_items.copy();b.set_where({type_id:c.TASK_TYPE});b.open({fields:['f_item_name','f_name']});a.task_name=b.f_item_name.value;a.task_caption=b.f_name.value;}function w(a){var b=a.task,c,d,e;a.view_options.refresh_button=false;if(a.item_name==='sys_fields_editor'||a.item_name==='sys_code_editor'||a.item_name==='sys_lang')return;a.paginate=false;if(a.view_form.hasClass('modal')){a.view_form.find("#select-btn").on('click.task',function(){a.set_lookup_field_value();});a.view_options.width=1170;d=480;if(a.item_name==='sys_items'||a.item_name==='sys_fields'){a.view_options.width=560;a.view_form.find('.title').hide();if(a.view_form.find('.sys_items_system').length)a.task.sys_params.init_lookup_form(a);else a.view_form.find('.modal-footer').hide();c={id:'10%'};}else if(a.item_name==='sys_filters'||a.item_name==='sys_indices'){a.view_options.width=680;d=460;}else if(a.item_name==='sys_report_params'){a.view_options.width=900;d=560;}}else{a.view_options.close_on_escape=false;b.cur_item=a;a.view_form.find(".modal-body").css('padding',0);a.view_form.find("#title-left").html('<h4>'+'<span class="editor-title">'+b.cur_item_title+'</span>'+'</h4>');a.view_form.find("#select-btn").hide();d=b.center_panel.height()-104;a.view_form.find("#title-right").addClass('admin-task-info');u(b);}if(a.item_name==='sys_items')c={id:'5%',f_visible:'10%',f_soft_delete:'10%'};if(a.item_name!=="sys_roles"){a.view_form.find("#new-btn").text(a.task.language['new']).on('click.task',function(){a.append_record();});a.view_form.find("#edit-btn").text(a.task.language.edit).on('click.task',function(){a.edit_record();});a.view_form.find("#delete-btn").text(a.task.language['delete']).on('click.task',function(){a.delete_record();});e={height:d,word_wrap:false,column_width:c};if(a.init_view_table)a.init_view_table(a,e);a.view_table=a.create_table(a.view_form.find(".view-table"),e);if(!a.view_form.hasClass('modal')&&a.item_name==='sys_items')l(b);}t(a);}function x(a){if(a.item_name==='sys_fields_editor'||a.item_name==='sys_code_editor')return;if(a===a.task.sys_privileges)a.open({params:{item_id:a.task.sys_items.id.value}});else if(a.item_name==='sys_items'){a.open({fields:['id','deleted','parent','task_id','type_id','table_id','has_children','f_index','f_name','f_item_name','f_table_name','f_gen_name','f_view_template','f_visible','f_soft_delete','f_virtual_table','f_js_external','f_primary_key','f_deleted_flag','f_master_id','f_master_rec_id','f_keep_history','f_edit_lock','sys_id']});l(b);}else a.open();if(a.active)a.view_table.focus();}function y(c){var d=['Cancel','OK','Delete','Edit','New'];c.find('button.btn').each(function(){var c=a(this),e=c.text(),f;for(f=0;f<d.length;f++)if(e.indexOf(d[f])!==-1)c.text(c.text().replace(d[f],b.language[d[f].toLowerCase()]));});}function z(a){var b={};if(a.item_name!=='sys_items'&&a.item_name!=='sys_fields'&&a.item_name!=='sys_code_editor'){a.edit_options.width=560;if(a.init_edit_options)a.init_edit_options(a,b);a.create_inputs(a.edit_form.find(".edit-body"),b);a.edit_form.find("#cancel-btn").text(a.task.language.cancel).on('click.task',function(b){a.cancel_edit(b);return false;});a.edit_form.find("#ok-btn").text(a.task.language.ok).on('click.task',function(){a.apply_record();});}y(a.edit_form);}function A(a){}function B(a){var c;if(a.item_name!=='sys_search')if(a.is_changing())if(a.is_modified()){a.yes_no_cancel(b.language.save_changes,function(){a.apply_record();},function(){a.cancel_edit();});c=false;}else{a.cancel();c=true;}return c;}function C(a){a.filter_form.title=a.item_caption+' - filter';a.create_filter_inputs(a.filter_form.find(".edit-body"));a.filter_form.find("#cancel-btn").on('click.task',function(){a.close_filter();});a.filter_form.find("#ok-btn").on('click.task',function(){a.apply_filter();});}function D(a){a.create_param_inputs(a.param_form.find(".edit-body"));a.param_form.find("#cancel-btn").on('click.task',function(){a.close_param_form();});a.param_form.find("#ok-btn").on('click.task',function(){a.process_report();});}function E(a,b){g(a);a.sys_params.params=true;a.sys_params.edit_options.fields=['f_language','f_safe_mode','f_debugging','f_theme','f_con_pool_size','f_mp_pool','f_persist_con','f_compressed_js','f_single_file_js','f_dynamic_js','f_history_item','f_timeout','f_ignore_change_ip','f_delete_reports_after','f_version'];a.sys_params.edit_options.title=b;a.sys_params.edit_record();}function F(a,b){var c=['f_manual_update','f_db_type','f_server','f_alias','f_login','f_password','f_host','f_port','f_encoding'];a.sys_tasks.open();a.sys_tasks.edit_options.fields=c;a.sys_tasks.f_name.required=false;a.sys_tasks.f_item_name.required=false;a.sys_tasks.edit_options.title=b;a.sys_tasks.edit_record();}function G(a){a.sys_lookup_lists.view_options.fields=['f_name'];a.sys_lookup_lists.edit_options.fields=['f_name'];a.sys_lookup_lists.view();}function H(a){a.sys_search.find_in_task(a);}function I(b,c){var d,e,f,g,h=0,i,j;for(d=0;d<b.length;d++){c.append(a('<h4>'+b[d][0]+'</h4>'));i=b[d][1].split('\n');for(e=0;e<i.length;e++){g=i[e];h=0;for(f=0;f<g.length;f++)if(g[f]===' ')h+=1;else if(g[f]==='\t ')h+=4;else break;g=g.trim();if(g.length===0)j=a('<p style="line-height: 16px; margin: 0px;">').html('&nbsp;');else j=a('<p style="line-height: 16px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: '+h*6+'px">').text(g);j.css("font-family","'Courier New', Courier, monospace");c.append(j);}}}function J(b){var c=a(window).width()-50,d=a(window).height()-200,e=a('<div>'),f=b.server('server_web_print_code',[b.sys_tasks.task_id.value]);if(f){e.append(a('<h2>'+f.task+'</h2>'));e.append(a('<h3>Client</h3>'));I(f.client,e);e.append(a('<h3>Server</h3>'));I(f.server,e);b.message(e,{title:'Project code',margin:10,width:c,height:d,text_center:false,buttons:{"Close":undefined},center_buttons:false,print:true});}}function K(c){var d;d=b.show_message(a('<h5>'+b.language.import_under_way+'</h5>'),{margin:"20px 20px",text_center:true});b._importing=true;b.server('server_import_task',[b.sys_tasks.task_id.value,'static/internal/'+c,true],function(a){var c=a[0],e=a[1],f=a[2],g,h=function(){location.reload();},i={text_center:false,width:720,height:400,title:'Import result',close_button:false,margin:0};b.hide_message(d);if(c){g=b.language.import_success;if(e)g=b.language.import_errors;g='<h3 class="text-center">'+g+'</h3>';}else g='<h3 class="text-center text-error">'+b.language.import_failed+'</h3>';if(f)g+='<h4 class="text-info">'+b.language.import_log+'</h4><div>'+f+'</div>';b.warning(g,h,i);b._importing=false;});}function L(a){a.upload('static/internal',{multiple:false,callback:K});}function M(a){var b,c=location.protocol+'/'+'/'+location.hostname+(location.port?':'+location.port:''),d=a.server('server_export_task',[a.sys_tasks.task_id.value,c]);window.open(d,"_self");}function N(a,b,c){var d=a._dataset[b],e=a._dataset[c],f,g;for(f=0;f<d.length-1;f++){g=d[f];d[f]=e[f];e[f]=g;}a.update_controls();a.rec_no=c;}function O(a){if(a.rec_no>0)N(a,a.rec_no,a.rec_no-1);}function P(a){if(a.rec_no<a.record_count()-1)N(a,a.rec_no,a.rec_no+1);}function Q(b){if(b._manual_update)a("#project-mode").text('DB manual mode').css("color","red");else a("#project-mode").text('');}function R(a,b){if(a.item_name==='sys_users'||a.item_name==='sys_report_params'||a.item_name==='sys_filters')if(b.keyCode===45&&b.ctrlKey===true){b.preventDefault();a.append_record();}else if(b.keyCode===46&&b.ctrlKey===true){b.preventDefault();a.delete_record();}}function S(a,b){if(a.item_name==='sys_users'||a.item_name==='sys_indices'||a.item_name==='sys_report_params'||a.item_name==='sys_filters')if(b.keyCode===13&&b.ctrlKey===true){b.preventDefault();a.edit_form.find("#ok-btn").focus();a.apply_record();}}this.tree_changed=e;this.refresh_tree=f;this.open_sys_params=g;this.refresh_task_dict=h;this.on_page_loaded=i;this.resize=k;this.resize_elements=l;this.resize_panels=m;this.resize_item=n;this.resize_editor=o;this.add_button=p;this.add_divider=q;this.add_buttons=r;this.create_params_btn=s;this.create_print_btns=t;this.update_task_info=u;this.read_task_name=v;this.on_view_form_created=w;this.on_view_form_shown=x;this.set_btn_lang=y;this.on_edit_form_created=z;this.on_edit_form_shown=A;this.on_edit_form_close_query=B;this.on_filter_form_created=C;this.on_param_form_created=D;this.set_project_params=E;this.edit_database=F;this.show_lookup_lists=G;this.find_in_task=H;this.print_section=I;this.print_code=J;this.do_import=K;this.import_task=L;this.export_task=M;this.move_vert=N;this.move_record_up=O;this.move_record_down=P;this.update_db_manual_mode=Q;this.on_view_form_keydown=R;this.on_edit_form_keydown=S;}b.events.events0=new c();function d(){function c(a){var b=a.task;a.fields_editor=false;if(b.item_tree.type_id.value===b.item_types.TASKS_TYPE){a.view_options.fields=['id','f_name','f_item_name'];a.edit_options.fields=['f_name','f_item_name'];}else if(b.item_tree.type_id.value===b.item_types.TASK_TYPE){a.fields_editor=true;a.view_options.fields=['id','f_name','f_item_name','f_visible'];a.edit_options.fields=['f_name','f_item_name','f_visible'];if(a.task._manual_update)a.sys_fields.view_options.fields=['f_name','f_field_name','f_db_field_name','f_data_type','f_size','f_required','f_read_only','f_object','f_object_field','f_master_field','f_enable_typehead','f_lookup_values'];else a.sys_fields.view_options.fields=['f_name','f_field_name','f_data_type','f_size','f_required','f_read_only','f_object','f_object_field','f_master_field','f_enable_typehead','f_lookup_values'];}else if(b.item_tree.type_id.value===b.item_types.ITEMS_TYPE||b.item_tree.type_id.value===b.item_types.TABLES_TYPE){a.fields_editor=true;a.view_options.fields=['id','f_name','f_item_name','f_table_name','f_visible','f_soft_delete','f_keep_history'];a.edit_options.fields=['f_name','f_item_name','f_table_name'];if(a.task._manual_update)a.sys_fields.view_options.fields=['f_name','f_field_name','f_db_field_name','f_data_type','f_size','f_required','f_read_only','f_object','f_object_field','f_master_field','f_enable_typehead','f_lookup_values'];else a.sys_fields.view_options.fields=['f_name','f_field_name','f_data_type','f_size','f_required','f_read_only','f_object','f_object_field','f_master_field','f_enable_typehead','f_lookup_values'];}else if(b.item_tree.type_id.value===b.item_types.REPORTS_TYPE){a.view_options.fields=['id','f_name','f_item_name','f_view_template','f_visible'];a.edit_options.fields=['f_name','f_item_name','f_view_template','f_visible','f_js_external'];}else if(b.item_tree.type_id.value===b.item_types.ITEM_TYPE||b.item_tree.type_id.value===b.item_types.TABLE_TYPE){a.view_options.fields=['id','f_name','f_item_name','f_table_name'];a.edit_options.fields=['f_name','f_item_name'];}}function d(a){var b=a.task,c;b.btns_panel.empty();if(b.item_tree.type_id.value===b.item_types.TASKS_TYPE)b.add_buttons(b,['client_module','server_module','index.html','project.css','divider','Lookup lists']);else if(b.item_tree.type_id.value===b.item_types.TASK_TYPE)b.add_buttons(b,['client_module','server_module']);else if(b.item_tree.type_id.value===b.item_types.ITEMS_TYPE||b.item_tree.type_id.value===b.item_types.TABLES_TYPE){c=['client_module','server_module','divider','viewing','editing','filters','divider','details','divider','order','indices','foreign_keys','divider','reports','divider','privileges'];b.add_buttons(b,c);}else if(b.item_tree.type_id.value===b.item_types.ITEM_TYPE||b.item_tree.type_id.value===b.item_types.TABLE_TYPE)b.add_buttons(b,['client_module','server_module','divider','viewing','editing','divider','order','divider','privileges']);else if(b.item_tree.type_id.value===b.item_types.REPORTS_TYPE)b.add_buttons(b,['client_module','server_module','divider','report_params']);}function e(a){var b=a.task,e=a.task.item_tree,f;a.filters.parent.value=e.id.value;c(a);a.view(b.view_panel);d(a);}function f(a){var b=a.task.item_tree.type_id.value,c=a.task.item_types,d=a.task;if(b===c.TASKS_TYPE)return c.TASK_TYPE;else if(b===c.TASK_TYPE)return c.ITEMS_TYPE;else if(b===c.ITEMS_TYPE)return c.ITEM_TYPE;else if(b===c.TABLES_TYPE)return c.TABLE_TYPE;else if(b===c.REPORTS_TYPE)return c.REPORT_TYPE;else if(b===c.ITEM_TYPE||b===c.TABLE_TYPE)return c.DETAIL_TYPE;}function g(a){var b=0,c=a.rec_no,d=a.store_handlers();a.clear_handlers();a.disable_controls();try{a.each(function(a){a.edit();a.f_index.value=b;a.post();b++;});}finally{a.rec_no=c;a.load_handlers(d);a.enable_controls();}a.apply();}function h(a){var b=a.task.item_types;a.task.sys_new_group.on_edit_form_created=function(a){a.edit_form.find("#ok-btn").off('click.task').on('click',function(){a.post_record();});};a.task.sys_new_group.on_after_post=function(c){var d=c.group_type.value,e=[b.ITEMS_TYPE,b.TABLES_TYPE,b.REPORTS_TYPE];if(d){a.append();a.type_id.value=e[d-1];}setTimeout(function(){a.edit_record();},300);};a.task.sys_new_group.open({open_empty:true});a.task.sys_new_group.append_record();}function i(a){var b='';if(a.id.value)if(a.type_id.value===a.task.item_types.ITEMS_TYPE||a.type_id.value===a.task.item_types.TABLES_TYPE||a.type_id.value===a.task.item_types.REPORTS_TYPE){if(!a.server('server_group_is_empty',[a.id.value]))b='You can not delete the group. The group is not empty.';}else b=a.server('server_can_delete',[a.id.value]);return b;}function j(a){var b=a.task.item_tree.type_id.value,c=a.task.item_types;a.cur_record_count=undefined;a.set_order_by(['f_index']);if(b===c.TASKS_TYPE){a.view_form.find('#new-btn').hide();a.view_form.find('#delete-btn').hide();a.view_form.find('#up-btn').hide();a.view_form.find('#down-btn').hide();}if(f(a)===c.DETAIL_TYPE){a.view_form.find('#new-btn').hide();a.view_form.find('#delete-btn').hide();}a.view_form.find('#import-btn').hide();if((b===c.ITEMS_TYPE||b===c.TABLES_TYPE)&&a.task._manual_update&&a.task.db_options.IMPORT_SUPPORT){a.view_form.find('#import-btn').show();a.view_form.find('#import-btn').on('click',function(){ah(a);});}a.view_form.find('#delete-btn').off('click.task').on('click',function(){if(a.record_count())a.question(a.task.language.delete_record,function(){var b=i(a);if(b)a.warning(b);else{a["delete"]();a.apply();}});else a.warning('Record is not selected.');});a.view_form.find("#new-btn").off('click.task').on('click',function(){if(b===c.TASK_TYPE)h(a);else a.append_record();});a.view_form.find('#up-btn').click(function(){a.task.move_record_up(a);g(a);});a.view_form.find('#down-btn').click(function(){a.task.move_record_down(a);g(a);});}function k(b){var c=b.task.item_tree.type_id.value,d=b.task.item_types,e,f,g=450,h=560,i=b.task.item_tree;if(b.sys_id.value)b.read_only=true;else{b.read_only=false;if(b.record_count()&&b.f_table_name&&b.f_virtual_table){b.f_table_name.read_only=!b.is_new();b.f_gen_name.read_only=!b.is_new();b.f_virtual_table.read_only=!b.is_new();}if(b.f_soft_delete&&b.f_deleted_flag)b.f_soft_delete.read_only=!b.f_deleted_flag.value;}b._import_info=undefined;if(b.type_id.value===d.ITEM_TYPE||b.type_id.value===d.TABLE_TYPE){b.fields_editor=true;if(b.task.db_options.NEED_GENERATOR){e=['f_name','f_item_name','f_table_name','f_gen_name','f_primary_key','f_deleted_flag'];if(b.type_id.value===d.TABLE_TYPE)e=e.concat(['f_master_id','f_master_rec_id']);}else{e=['f_name','f_item_name','f_table_name','f_primary_key','f_deleted_flag'];if(b.type_id.value===d.TABLE_TYPE)e=e.concat(['f_master_id','f_master_rec_id']);}e=e.concat(['f_visible','f_soft_delete','f_virtual_table','f_keep_history','f_js_external']);}if(b.type_id.value===d.ITEMS_TYPE||b.type_id.value===d.TABLES_TYPE){b.fields_editor=true;e=['f_name','f_item_name','f_visible','f_primary_key','f_deleted_flag'];if(b.type_id.value===d.TABLES_TYPE)e=e.concat(['f_master_id','f_master_rec_id']);}else if(b.type_id.value===d.REPORTS_TYPE)b.fields_editor=false;if(b.fields_editor){h=1100;if(a(window).width()-50<h)h=a(window).width()-50;b.create_inputs(b.edit_form.find(".edit-body"),{fields:e,col_count:2,row_count:f});}else b.create_inputs(b.edit_form.find(".edit-body"));b.edit_options.width=h;b.edit_form.find("#cancel-btn").on('click.task',function(a){b.cancel_edit(a);return false;});b.edit_form.find("#ok-btn").on('click.task',function(){b.apply_record();});if(b.item_name==='sys_items')if(b.fields_editor){if(c===d.TASK_TYPE){g=a(window).height()-400;if(g<160)g=160;else if(g>520)g=520;if(b.id.value&&!b.server('server_group_is_empty',[b.id.value])){b.edit_form.find("#new-btn").prop("disabled",true);b.edit_form.find("#delete-btn").prop("disabled",true);p(b,true);}else{b.edit_form.find("#new-btn").prop("disabled",false);b.edit_form.find("#delete-btn").prop("disabled",false);p(b,false);}}else{g=a(window).height()-490;if(g<200)g=200;else if(g>550)g=550;if(c===d.TABLES_TYPE){g=a(window).height()-530;if(g<200)g=200;else if(g>500)g=500;}if(b.id.value)p(b,true);else p(b,false);}b.edit_table=b.sys_fields.create_table(b.edit_form.find(".edit-detail"),{height:g,sortable:true,row_callback:n});b.sys_fields.open({order_by:['f_field_name']},true);b.edit_form.find("#new-btn").on('click.task',function(){b.sys_fields.append_record();});b.edit_form.find("#edit-btn").on('click.task',function(){b.sys_fields.edit_record();});b.edit_form.find("#delete-btn").off('click.task').on('click',function(){l(b);});}else b.edit_form.find('#edit-detail-footer').hide();}function l(a){a.question(a.task.language.delete_record,function(){m(a);});}function m(a){var b=a.sys_fields.can_delete(a.sys_fields);if(b)a.warning(b);else{a.sys_fields["delete"]();a.sys_fields.apply();}}function n(a,b){var c,d=function(){var a=b.owner._import_info.fields;for(var c=0;c<a.length;c++)if(a[c].field_name.toUpperCase()===b.f_field_name.value.toUpperCase())return a[c];};if(b.owner._import_info){if(!b.f_data_type.value){c=d();if(c)a.find('td.f_data_type div').text(c.data_type);a.find('td.f_data_type').css("color","#ff9999");}else{a.find('td.f_data_type div').text(b.f_data_type.display_text);a.find('td.f_data_type').css("color","#333333");}if(!b.f_size.value){c=d();if(c&&c.size)a.find('td.f_size div').text(c.size);a.find('td.f_size').css("color","#ff9999");}else{a.find('td.f_size div').text(b.f_size.display_text);a.find('td.f_size').css("color","#333333");}}}function o(a){var b='Item Editor';if(a.type_id.value===a.task.item_types.REPORT_TYPE)b='Report Editor';else if(a.type_id.value===a.task.item_types.ITEMS_TYPE)b='Item Group Editor';else if(a.type_id.value===a.task.item_types.TABLES_TYPE)b='Table Group Editor';else if(a.type_id.value===a.task.item_types.REPORTS_TYPE)b='Report Group Editor';if(a.is_new())a.edit_form.find('h4.modal-title').html(b);else a.edit_form.find('h4.modal-title').html(b+' <span class="editor-title">'+a.f_item_name.value+'</span>');}function p(a,b){a.f_primary_key.read_only=b;a.f_deleted_flag.read_only=b;a.f_virtual_table.read_only=b;if(a.f_master_id)a.f_master_id.read_only=b;if(a.f_master_rec_id)a.f_master_rec_id.read_only=b;}function q(a){var b=a.copy({handlers:false,details:false});a.f_visible.value=true;a.parent.value=a.task.item_tree.id.value;a.task_id.value=a.task.item_tree.task_id.value;a.table_id.value=0;a.f_index.value=a.record_count();if(!a.type_id.value)a.type_id.value=f(a);b.set_where({id:a.parent.value});b.open();if(b.record_count()){a.f_primary_key.value=b.f_primary_key.value;a.f_primary_key.lookup_value=b.f_primary_key.lookup_value;a.f_deleted_flag.value=b.f_deleted_flag.value;a.f_deleted_flag.lookup_value=b.f_deleted_flag.lookup_value;a.f_master_id.value=b.f_master_id.value;a.f_master_id.lookup_value=b.f_master_id.lookup_value;a.f_master_rec_id.value=b.f_master_rec_id.value;a.f_master_rec_id.lookup_value=b.f_master_rec_id.lookup_value;}if(a.f_deleted_flag.value)a.f_soft_delete.value=true;}function r(a){var b=a.owner,c,d=b.task.item_types,e,f,g,h,i;if(a.field_name==='f_item_name'){if(!b.valid_identifier(a.value))return b.task.language.invalid_name;i=b.task.server('server_valid_item_name',[b.id.value,b.parent.value,a.value,b.type_id.value]);if(i)return i;if(b.type_id.value===d.ITEM_TYPE||b.type_id.value===d.TABLE_TYPE||b.type_id.value===d.REPORT_TYPE){f=new b.task.constructors.item();if(f[a.value]!==undefined)return b.task.language.reserved_word;}if(b.type_id.value===d.ITEMS_TYPE||b.type_id.value===d.TABLES_TYPE||b.type_id.value===d.REPORTS_TYPE){g=new b.task.constructors.group();if(g[a.value]!==undefined)return b.task.language.reserved_word;}if(b.type_id.value===d.TASK_TYPE){h=new b.task.constructors.task();if(h[a.value]!==undefined)return b.task.language.reserved_word;}if(b.type_id.value===d.DETAIL_TYPE){e=new b.task.constructors.detail();if(e[a.value]!==undefined)return b.task.language.reserved_word;}}else if(a.field_name==='f_primary_key'){if(!a.value&&!b.f_virtual_table.value&&!b.sys_id.value&&(b.type_id.value===d.ITEM_TYPE||b.type_id.value===d.TABLE_TYPE))return b.task.language.value_required;}else if(a.field_name==='f_master_id'&&!b.task._manual_update&&b.is_new()){if(!a.value&&!b.f_virtual_table.value&&b.type_id.value===d.TABLE_TYPE)return b.task.language.value_required;}else if(a.field_name==='f_master_rec_id')if(!a.value&&!b.f_virtual_table.value&&b.type_id.value===d.TABLE_TYPE)return b.task.language.value_required;}function s(a,b){var c,d,e,f=a.owner;if(f.is_new()&&f.type_id.value!=f.task.item_types.DETAIL_TYPE){if(a.field_name=='f_item_name'&&!f.f_virtual_table.value){e=f.task.server('get_new_table_name',a.value);f.f_table_name.value=e[0];if(f.task.db_options.NEED_GENERATOR)f.f_gen_name.value=e[1];}if(a.field_name==='f_name'&&!f.f_item_name.value)try{d=a.text.replace(' ','_').toLowerCase();if(t(d))f.f_item_name.value=d;}catch(g){}}if(a.field_name==='f_deleted_flag')if(a.value){f.f_soft_delete.read_only=false;f.f_soft_delete.value=true;}else{f.f_soft_delete.value=false;f.f_soft_delete.read_only=true;}if(a.field_name==='f_virtual_table')if(a.value){f.f_table_name.value=null;f.f_gen_name.value=null;}}function t(a){function b(a){return a.charCodeAt(0)>=65&&a.charCodeAt(0)<=90||a.charCodeAt(0)>=97&&a.charCodeAt(0)<=122;}function c(a){return a.charCodeAt(0)>=48&&a.charCodeAt(0)<=57;}var d,e=a.length;if(a[0]==='_'||b(a[0])){for(d=1;d<e;d++)if(!(a[d]==='_'||b(a[d])||c(a[d])))return false;return true;}return false;}function u(a){var c;clearTimeout(c);c=setTimeout(function(){b.btns_panel.find('button').prop("disabled",a.record_count()===0);if(a.record_count()&&a.f_table_name&&a.f_virtual_table){b.btns_panel.find('button.indices').prop("disabled",a.f_virtual_table.value);b.btns_panel.find('button.foreign_keys').prop("disabled",a.f_virtual_table.value);}},100);}function v(a){var b=a.sys_items,c=b.copy(),d=b.task.sys_fields.copy(),e,f=[];if(b.table_id.value===0)d.set_where({owner_rec_id__in:[b.id.value,b.parent.value]});else{c.set_where({id:b.table_id.value});c.open({fields:['id','parent']});e=c.parent.value;d.set_where({owner_rec_id__in:[b.table_id.value,e]});}d.set_order_by(['f_field_name']);d.open({fields:['id','f_field_name']});d.each(function(a){f.push([a.id.value,a.f_field_name.value]);});return f;}function w(a){var b=[['multiselect',false],['dblclick_edit',true],['row_count',0],['row_line_count',1],['expand_selected_row',0],['freeze_count',0],['sort_fields',[]],['edit_fields',[]],['summary_fields',[]]];if(a.table_id.value){}else b.splice(b.length-2,1);for(var c=0;c<b.length;c++)if(a.task.table_options[b[c][0]])b[c][1]=a.task.table_options[b[c][0]];return b;}function x(a){var b=[['form_border',true],['form_header',true],['history_button',true],['refresh_button',true],['enable_search',true],['search_field',[]],['enable_filters',true],['close_button',true],['close_on_escape',true],['width',0],['view_detail',[]],['detail_height',0]];if(a.table_id.value)return [];for(var c=0;c<b.length;c++)if(a.task.view_options[b[c][0]])b[c][1]=a.task.view_options[b[c][0]];return b;}function y(a){var b,c=[],d=[],e,f,g,h;function i(a,c){b.view_list=c;a.server('server_store_interface',[a.id.value,b]);}b=a.server('server_load_interface',[a.id.value]);c=[['id','',false],['name','Field',true]];d=[['id','',false],['name','Field',true,'70%'],['param3','Width',true]];g=b.view_list;if(g instanceof Array){f=[];for(var j=0;j<g.length;j++)f.push([g[j][0],'']);g={0:['',{},[],{},f,[]]};}h=a.task.language.viewing+' <span class="editor-title">'+a.f_item_name.value+'</span>';a.task.sys_fields_editor.fields_editor('view',a,h,c,v(a.task),d,g,i);}function z(a){return [['col_count',1],['label_size',3],['in_well',true]];}function A(a){var b=[['form_border',true],['form_header',true],['history_button',true],['close_button',true],['close_on_escape',true],['width',0],['edit_details',[]],['detail_height',0],['modeless',false]];for(var c=0;c<b.length;c++)if(a.task.edit_options[b[c][0]])b[c][1]=a.task.edit_options[b[c][0]];return b;}function B(a){var b,c=[],d=[],e,f,g,h;function i(a,c){b.edit_list=c;a.server('server_store_interface',[a.id.value,b]);}b=a.server('server_load_interface',[a.id.value]);c=[['id','',false],['name',a.task.language.caption_name,true]];d=[['id','',false],['name','Field',true,'70%'],['param3','Width',true]];g=b.edit_list;if(g instanceof Array){f=[];for(var j=0;j<g.length;j++)f.push([g[j][0],'']);g={0:['',{},[],[['',[[{},f,'']]]]]};}h=a.task.language.editing+' <span class="editor-title">'+a.f_item_name.value+'</span>';;a.task.sys_fields_editor.fields_editor('edit',a,h,c,v(a.task),d,g,i);}function C(a,b){a.task.server('server_item_info',[a.id.value,b],function(b){b.item_id=a.id.value;a.task.sys_code_editor.show_editor(a.task,b);});}function D(b){var c=a('<output>').append(a.parseHTML(b)),d={};c.find('.templates > div').each(function(){d[this.className]=null;});return d;}function E(a,b){a.task.server('server_file_info',[b],function(c){var d;if(b==='index.html')c.templates=D(c.doc);a.task.sys_code_editor.show_editor(a.task,c);});}function F(a){C(a,false);}function G(a){C(a,true);}function H(a){E(a,'index.html');}function I(a){E(a,'project.css');}function J(a,b){var c=true,d;if(!b.f_master_id.value){d=b.copy({handlers:false});d.set_where({table_id:b.id.value});d.open();if(d.rec_count&&a.id.value!==d.parent.value)c=false;}return c;}function K(a){var c=[],d=a.copy({handlers:false});d.set_where({type_id:b.item_types.TABLE_TYPE});d.open();d.each(function(b){if(J(a,b))c.push([b.id.value,b.f_item_name.value]);});return c;}function L(a){var b=[],c=a.copy({handlers:false});c.set_where({parent:a.id.value});c.open();c.each(function(a){b.push([a.table_id.value]);});return b;}function M(a){var b,c=[],d=[],e=K(a),f=L(a),g;function h(a,b){if(JSON.stringify(f)!==JSON.stringify(b)){a.server('server_update_details',[a.id.value,b]);a.task.refresh_tree(a.task);}}c=[['id','',false],['name',a.task.language.caption_name,true]];d=[['id','',false],['name',a.task.language.caption_name,true]];g=a.task.language.details+' <span class="editor-title">'+a.f_item_name.value+'</span>';;a.task.sys_fields_editor.fields_editor('details',a,g,c,e,d,f,h,undefined,false);}function N(a){var b,c=[],d=[],e,f;function g(a,c){b.order_list=c;a.server('server_store_interface',[a.id.value,b]);}b=a.server('server_load_interface',[a.id.value]);c=[['id','',false],['name',a.task.language.caption_name,true]];d=[['id','',false],['name',a.task.language.caption_name,true,'80%'],['param1',a.task.language.caption_descening,true]];f=a.task.language.order+' <span class="editor-title">'+a.f_item_name.value+'</span>';a.task.sys_fields_editor.fields_editor('order',a,f,c,v(a.task),d,b.order_list,g);}function O(a){var b,c=[],d=a.copy({handlers:false});d.set_where({type_id:a.task.item_types.REPORTS_TYPE});d.open();b=d.id.value;d.set_where({parent:b});d.open();d.each(function(a){c.push([a.id.value,a.f_name.value]);});return c;}function P(a){var b,c=[],d=[],e,f;function g(a,c){b.reports_list=c;a.server('server_store_interface',[a.id.value,b]);}b=a.server('server_load_interface',[a.id.value]);c=[['id','',false],['name',a.task.language.caption_name,true]];d=[['id','',false],['name',a.task.language.caption_name,true]];f=a.task.language.reports+' <span class="editor-title">'+a.f_item_name.value+'</span>';;a.task.sys_fields_editor.fields_editor('reports',a,f,c,O(a),d,b.reports_list,g);}function Q(a){a.task.sys_filters.set_where({owner_rec_id:a.id.value});a.task.sys_filters.set_order_by(['f_index']);a.task.sys_filters.view_options.fields=['f_name','f_filter_name','f_type','f_field','f_visible'];a.task.sys_filters.edit_options.fields=['f_field','f_name','f_filter_name','f_type','f_multi_select_all','f_placeholder','f_help','f_visible'];a.task.sys_filters.view_options.title='Filters <span class="editor-title">'+a.f_item_name.value+'</span>';a.task.sys_filters.view();}function R(a){var b=a.task.sys_indices.copy();b.foreign_index=false;b.set_where({owner_rec_id:a.id.value,f_foreign_index:false});b.view_options.title='Indices <span class="editor-title">'+a.f_item_name.value+'</span>';b.view();}function S(a){var b=a.task.sys_indices.copy();b.foreign_index=true;b.set_where({owner_rec_id:a.id.value,f_foreign_index:true});b.view_options.title='Foreign keys <span class="editor-title">'+a.f_item_name.value+'</span>';b.view();}function T(a){var b=['f_name','f_param_name','f_data_type','f_object','f_object_field','f_enable_typehead','f_multi_select','f_lookup_values','f_required','f_alignment','f_visible'];a.task.sys_report_params.set_where({owner_rec_id:a.id.value});a.task.sys_report_params.set_order_by(['f_index']);a.task.sys_report_params.view_options.fields=b;b=['f_name','f_param_name','f_data_type','f_object','f_object_field','f_enable_typehead','f_multi_select','f_multi_select_all','f_lookup_values','f_required','f_alignment','f_placeholder','f_help','f_visible'];a.task.sys_report_params.edit_options.fields=b;a.task.sys_report_params.view_options.title='Params <span class="editor-title">'+a.f_item_name.value+'</span>';a.task.sys_report_params.view();}function U(a){var b=a.task.sys_privileges;b.view_options.fields=['item_id','f_can_view','f_can_create','f_can_edit','f_can_delete'];b.view();}function V(a,b){if(b.keyCode===45&&b.ctrlKey===true){b.preventDefault();a.append_record();}else if(b.keyCode===46&&b.ctrlKey===true){b.preventDefault();a.delete_record();}}function W(a,b){if(b.keyCode===13&&b.ctrlKey===true){b.preventDefault();a.edit_form.find("#ok-btn").focus();a.apply_record();}if(b.keyCode===45&&b.ctrlKey===true){b.preventDefault();a.sys_fields.append_record();}else if(b.keyCode===46&&b.ctrlKey===true){b.preventDefault();l(a);}}function X(a){a.refresh_record();u(a);if(a.record_count()&&a.cur_record_count&&a.cur_record_count!==a.record_count())if(a.type_id.value===a.task.item_types.ITEMS_TYPE||a.type_id.value===a.task.item_types.TABLES_TYPE||a.type_id.value===a.task.item_types.REPORTS_TYPE)a.task.refresh_tree(a.task);if(a._import_info)a._import_info=undefined;a.task.refresh_task_dict(a.task);}function Y(a,b){var c=a.owner;if(b.item_name==='sys_fields')b.set_view_fields(['f_field_name','f_name']);if(b.item_name==='sys_fields')b.set_order_by(['f_field_name']);if(a.field_name==='f_primary_key'||a.field_name==='f_deleted_flag'||a.field_name==='f_master_id'||a.field_name==='f_master_rec_id'){b.set_order_by(['f_field_name']);b.set_where({owner_rec_id__in:[c.parent.value],f_data_type__in:[c.task.consts.INTEGER,c.task.consts.TEXT]});}b.on_after_open=function(a){var b=c.sys_fields.clone();a.first();while(!a.eof())if(a.id.value===c.f_primary_key.value||a.id.value===c.f_deleted_flag.value||a.id.value===c.f_master_id.value||a.id.value===c.f_master_rec_id.value)a["delete"]();else a.next();b.each(function(b){if((b.f_data_type.value===c.task.consts.INTEGER||b.f_data_type.value===c.task.consts.TEXT)&&b.id.value!==c.f_primary_key.value&&b.id.value!==c.f_deleted_flag.value&&b.id.value!==c.f_master_id.value&&b.id.value!==c.f_master_rec_id.value){a.append();a.id.value=b.id.value;a.f_field_name.value=b.f_field_name.value;a.f_db_field_name.value=b.f_db_field_name.value;a.f_name.value=b.f_name.value;a.f_data_type.value=b.f_data_type.value;a.post();}});a.first();};}function Z(a){a.cur_record_count=a.record_count();}function ab(a){a.cur_record_count=a.record_count();}function ac(a){return{'manual_update':a.task._manual_update};}function ad(a,b){var c=a.task.sys_indices,d,e,f,g,h=0,i,j;c.open({open_empty:true});if(b.length){for(var k=0;k<b.length;k++){c.append();c.f_index_name.value=b[k].index_name;c.f_unique_index.value=b[k].unique;i=[];e=true;for(var l=0;l<b[k].fields.length;l++){g=b[k].fields[l][0];d=b[k].fields[l][1];f=0;a.sys_fields.each(function(a){if(a.f_db_field_name.value.toUpperCase()===g.toUpperCase()){f=a.id.value;return false;}});if(f)i.push([f,d]);else{e=false;break;}}c.f_fields_list.value=c.server('server_dump_index_fields',[i]);if(e){h+=1;c.post();}else c.cancel();}c.apply();j='Information about '+h+' index(es) have been added.';if(b.length-h)j+=' Information about '+(b.length-h)+' index(es) could not be added.';a.warning(j);}}function ae(a,c){var d=a.data_type.toUpperCase(),e,f=a.size,g,c,h,i,j,k,l=[[b.consts.TEXT,['CHAR','TEXT']],[b.consts.DATETIME,['DATETIME']],[b.consts.DATE,['DATE']],[b.consts.FLOAT,['NUMBER']]];for(var g in c)if(c[g]===d){e=g;break;}if(!e)for(h=0;h<l.length;h++){g=l[h][0];c=l[h][1];for(i=0;i<c.length;i++)if(d.indexOf(c[i])!==-1){e=g;if(e===b.consts.TEXT){j=d.indexOf('(');k=d.indexOf(')');if(j>0&&k>0)f=parseInt(d.substring(j+1,k),10);}break;}}if(e){a.data_type=e;a.size=f;}return a;}function af(a,b){var c=b.f_table_name.value,d=a.task.server('server_import_table',c),e,f,g,h,i;if(d){e=d.fields;f=d.field_types;b.close_view_form();a.append_record();i=a.sys_fields.store_handlers();a.sys_fields.disable_controls();try{a._import_info=d;a.sys_fields.clear_handlers();a.f_name.value=c.charAt(0).toUpperCase()+c.slice(1).toLowerCase();a.f_item_name.value=c.toLowerCase();a.f_table_name.value=c;a.f_gen_name.value='';a.f_soft_delete.value=false;h=a.task.server('get_fields_next_id',e.length);for(var j=0;j<e.length;j++){e[j]=ae(e[j],f);g=e[j].field_name;a.sys_fields.append();a.sys_fields.id.value=h;h+=1;a.sys_fields.f_name.value=g;a.sys_fields.f_field_name.value=g.toLowerCase();a.sys_fields.f_db_field_name.value=g;a.sys_fields.f_data_type.value=e[j].data_type;a.sys_fields.f_size.value=e[j].size;a.sys_fields.f_alignment.value=a.sys_fields.get_alignment(a.sys_fields);if(e[j].pk){a.f_primary_key.value=a.sys_fields.id.value;a.f_primary_key.lookup_value=a.sys_fields.f_field_name.value;}a.sys_fields.post();}a.sys_fields.first();}finally{a.sys_fields.load_handlers(i);a.sys_fields.enable_controls();a.sys_fields.update_controls();}}}function ag(a){var b=a.task.sys_fields.copy({handlers:false});b.set_where({owner_rec_id:a.task.item_tree.id.value});b.open({fields:['id']});if(b.record_count()){a.warning(a.task.language.import_prohibited.replace('%s',a.task.item_tree.f_name.value));return false;}return true;}function ah(a){var b=a.copy({handlers:false});if(ag(a)){b.each_field(function(a){a.required=false;});b.log_changes=false;b.set_where({id__in:[]});b.init_view_table=function(b,c){c.on_dblclick=function(){af(a,b);};};b.on_view_form_created=function(b){b.view_form.find('.modal-footer').show();b.view_form.find('#import-btn').click(function(){af(a,b);});b.task.server('server_get_table_names',function(a){for(var c=0;c<a.length;c++){b.append();b.f_table_name.value=a[c];b.post();}b.first();});};b.view_options.template_class='import-tables-view';b.view_options.title='Import';b.view_options.fields=['f_table_name'];b.view();}}function ai(a){var b=a.sys_fields.clone(),c=a.task.item_types,d=false;if(a._import_info){b.each(function(a){if(!a.f_data_type.value)d=a.f_field_name.value+': the field type must be specified.';else if(a.f_data_type.value===a.task.consts.TEXT&&!a.f_size.value)d=a.f_field_name.value+': the field size must be specified.';if(d)return false;});if(d){a.warning(d);throw d;}if(!a.f_primary_key.value)if(!a.f_virtual_table.value&&!a.sys_id.value&&(a.type_id.value===c.ITEM_TYPE||a.type_id.value===c.TABLE_TYPE))a.warning('You must specify primary field to use this item as a lookup item.');}else if(!a.f_primary_key.value)a.f_gen_name.value=null;}this.init_fields=c;this.init_buttons=d;this.tree_changed=e;this.get_type_id=f;this.save_order=g;this.append_group=h;this.can_delete=i;this.on_view_form_created=j;this.on_edit_form_created=k;this.delete_field=l;this.do_delete_field=m;this.field_colors=n;this.on_edit_form_shown=o;this.update_sys_fields_read_only=p;this.on_after_append=q;this.on_field_validate=r;this.on_field_changed=s;this.valid_identifier=t;this.on_after_scroll=u;this.get_fields_list=v;this.view_options_list=w;this.view_form_options_list=x;this.view_setup=y;this.edit_options_list=z;this.edit_form_options_list=A;this.edit_setup=B;this.edit_code=C;this.get_templates=D;this.edit_file=E;this.edit_client=F;this.edit_server=G;this.edit_index_html=H;this.edit_project_css=I;this.valid_detail=J;this.get_detail_source_list=K;this.get_detail_dest_list=L;this.details_setup=M;this.order_setup=N;this.get_reports_list=O;this.reports_setup=P;this.filters_setup=Q;this.indices_setup=R;this.foreign_keys_setup=S;this.report_params_setup=T;this.privileges_setup=U;this.on_view_form_keydown=V;this.on_edit_form_keydown=W;this.on_after_apply=X;this.on_field_select_value=Y;this.on_before_append=Z;this.on_before_delete=ab;this.on_before_apply=ac;this.add_import_indexes=ad;this.convert_field_type=ae;this.import_table=af;this.can_import_tables=ag;this.import_tables=ah;this.on_before_post=ai;}b.events.events3=new d();function e(){function b(b){var g='70px';var h=b.task.center_panel.height()-b.task.view_panel.height();if(b.view_form.hasClass('modal')){h=460;b.view_options.width=560;b.view_form.find("#priv-panel").remove();b.view_form.find("#roles-panel").removeClass('span4').addClass('span12');b.view_form.find("#roles-footer").hide();b.view_table=b.create_table(b.view_form.find("#roles-panel .view-table"),{height:h,fields:['id','f_name'],column_width:{id:'10%'}});}else{b.view_form.find("#roles-panel #new-btn").text(b.task.language['new']).on('click.task',function(){f(b);});b.view_form.find("#roles-panel #delete-btn").text(b.task.language['delete']).on('click.task',function(){e(b);});b.view_form.find("#select-all-btn").text(b.task.language.select_all).on('click.task',function(){c(b);});b.view_form.find("#unselect-all-btn").text(b.task.language.unselect_all).on('click.task',function(){d(b);});b.set_view_fields(['f_name'],[b.task.language.roles]);b.view_table=b.create_table(b.view_form.find("#roles-panel .view-table"),{height:h,fields:['id','f_name'],word_wrap:false,sortable:false});b.sys_privileges.set_view_fields(['owner_item','item_id','f_can_view','f_can_create','f_can_edit','f_can_delete'],[b.task.language.item,b.task.language.can_view,b.task.language.can_create,b.task.language.can_edit,b.task.language.can_delete]);b.detail_table=b.sys_privileges.create_table(b.view_form.find("#priv-panel .view-table"),{height:h,word_wrap:true,column_width:{f_can_view:g,f_can_create:g,f_can_edit:g,f_can_delete:g},sortable:false,dblclick_edit:false});b.detail_table.$table.on('click','td',function(){var c=a(this),d=c.data('field_name'),e=b.sys_privileges.field_by_name(d);if(e.field_type==="boolean"){if(!b.is_changing())b.edit();if(!b.sys_privileges.is_changing())b.sys_privileges.edit();e.value=!e.value;}});}}function c(a,b){var c=a.details.sys_privileges,d=c.on_field_changed,e=c.rec_no;if(b===undefined)b=true;if(!a.is_changing())a.edit();try{if(!a.is_changing())a.edit();c.on_field_changed=undefined;c.disable_controls();c.each(function(c){c.edit();c.f_can_create.value=b;c.f_can_view.value=b;c.f_can_edit.value=b;c.f_can_delete.value=b;if(c.id.value)c.record_status=a.task.consts.RECORD_MODIFIED;else c.record_status=a.task.consts.RECORD_INSERTED;c.post();});}finally{c.on_field_changed=d;c.rec_no=e;c.enable_controls();}if(a.is_changing()){a.post();a.apply();a.edit();}c.open();}function d(a){c(a,false);}function e(a){if(a.is_changing())a.cancel();a.delete_record();}function f(a){if(a.is_changing()){a.post();a.apply();}a.append_record();}function g(a){if(a.is_changing()){a.post();a.apply();}}var h;function i(a){clearTimeout(h);h=setTimeout(function(){a.sys_privileges.open();if(a.is_browsing())a.edit();},50);}function j(a){a.server('roles_changed');a.refresh_record(function(){if(!a.sys_privileges.rec_count)a.sys_privileges.open(function(){a.edit();});});}this.on_view_form_created=b;this.select_all_clicked=c;this.unselect_all_clicked=d;this.del_role=e;this.append_role=f;this.on_before_scroll=g;this.on_after_scroll=i;this.on_after_apply=j;}b.events.events2=new e();function f(){function a(a){a.f_manual_update.value=a.task._manual_update;}function c(a){if(b.init_project&&a.f_db_type.value){a.task.server('server_create_task');a.task.on_page_loaded(a.task);}a.task.update_db_manual_mode(a.task);}function d(a,b){var c,d,e;if(b){c=a.task.server('server_get_db_options',[b]);d=c[0];e=c[1];if(e){a.warning(e);b=0;}}if(b){a.f_server.read_only=b!==6;a.f_login.read_only=!d.NEED_DATABASE_NAME;a.f_login.read_only=!d.NEED_LOGIN;a.f_password.read_only=!d.NEED_PASSWORD;a.f_encoding.read_only=!d.NEED_ENCODING;a.f_host.read_only=!d.NEED_HOST;a.f_port.read_only=!d.NEED_PORT;}else{a.f_server.read_only=true;a.f_login.read_only=true;a.f_login.read_only=true;a.f_password.read_only=true;a.f_encoding.read_only=true;a.f_host.read_only=true;a.f_port.read_only=true;}}function e(a){d(a,a.f_db_type.value);}function f(a,b){var c=a.owner,e,f,g;if(a===a.owner.f_db_type&&a.value){if(a.owner.is_changing()){a.owner.f_alias.value=null;a.owner.f_login.value=null;a.owner.f_password.value=null;a.owner.f_encoding.value=null;a.owner.f_host.value=null;a.owner.f_port.value=null;}d(c,c.f_db_type.value);}}function g(a){var c=a.task.server('server_check_connection',[a.f_db_type.value,a.f_alias.value,a.f_login.value,a.f_password.value,a.f_host.value,a.f_port.value,a.f_encoding.value,a.f_server.value]);if(c){a.warning(c);a.abort();}if(b.init_project)a.task.server('server_set_task_name',[a.f_name.value,a.f_item_name.value]);a.task._manual_update=a.f_manual_update.value;a.f_manual_update.value=false;}function h(a){}function i(a){var b=a.owner;if(a.field_name==='f_item_name'&&a.required)if(!b.task.sys_items.valid_identifier(a.value))return b.task.language.invalid_name;if(a.field_name==='f_port'&&a.value)if(isNaN(a.value))return 'The port must be an integer value.';}this.on_after_edit=a;this.on_after_apply=c;this.update_db_type=d;this.on_edit_form_created=e;this.on_field_changed=f;this.on_before_post=g;this.on_after_post=h;this.on_field_validate=i;}b.events.events9=new f();function g(){var c=require('ace/edit_session').EditSession;var d=require("ace/undomanager").UndoManager;function e(b){a("#content").show();b.tabs={};a('body').on('click','ul#task-tabs li',function(c){c.preventDefault();c.stopPropagation();g(b,a(this).attr('id'));});a('body').on('click','ul#task-tabs .close-editor-btn',function(c){c.preventDefault();c.stopPropagation();i(b,a(this).parent().parent().attr('id'));});}function f(a,b){if(a.code_editor.is(':visible')){var c=a.code_editor.find('.modal-footer'),d=a.code_editor.find("#center-box"),e=a.code_editor.find("#editor-box"),f=a.code_editor.find('#left-box'),g=a.code_editor.find('#editor-tabs'),h=a.code_editor.find('#info-grids'),i=a.code_editor.find('#editor-tabs div.info-tree'),j=a.code_editor.find('#editor-tabs div.info-tree .dbtree'),k=a.code_editor.find('ul.nav-tabs').outerHeight();if(c.length)b-=c.outerHeight(true);f.children().hide();f.hide();e.hide();d.outerHeight(b,true);e.outerHeight(d.height(),true);e.show();f.outerHeight(b,true);f.show();g.outerHeight(f.height(),true);g.show();h.outerHeight(f.height()-k,true);h.show();i.outerHeight(h.height(),true);j.outerHeight(h.height(),true);if(a.editor)a.editor.resize();}}function g(b,c){a('ul#task-tabs li').removeClass('active');a('ul#task-tabs li#'+c).addClass('active');if(c==='admin'){a('#tab-content #code-editor').hide();a('#tab-content #admin').show();}else{a('#tab-content #admin').hide();a('#tab-content #code-editor').show();}b.resize_elements(b);if(c!=='admin')l(b,c);}function h(b,c){var d=c.tag;if(b.tabs[d])g(b,d);else{a('ul#task-tabs').append('<li id="'+d+'" class="active"><a href="#code-editor" data-toggle="tab"><span> '+c.name+' </span><i class="icon-remove close-editor-btn"></i></a></li>');b.tabs[d]=c;g(b,d);}}function i(b,c){var d=a('ul#task-tabs li#'+c),e;if(d.next().length)e=d.next();else e=d.prev();g(b,c);j(b,c,function(){g(b,e.attr('id'));delete b.tabs[c];d.remove();});}function j(a,b,c){if(p(a))a.yes_no_cancel(a.language.save_changes,function(){t(a,b);c();},function(){q(a);c();});else c();}function k(b){b.editor=ace.edit("editor");b.editor.on('input',function(){a("#code-editor #error-info").text('');n(b);});b.code_editor.find('#ok-btn').click(function(){t(b,a('ul#task-tabs li.active').attr('id'));});b.code_editor.find('#find-btn').text(b.code_editor.find('#find-btn').text().replace('find_in_task',b.language.find_in_task)).click(function(){b.sys_search.find_in_task(b);});b.code_editor.on('click','#editor-tabs > .nav > li',function(){x(b,a(this));});b.code_editor.on('dblclick','.dbtree ul li',function(c){c.preventDefault();c.stopPropagation();y(b,a('ul#task-tabs li.active').attr('id'),a(this));});a(window).on('keydown.editor',function(c){if(c.ctrlKey&&c.which===83){var d=a('ul#task-tabs li.active').attr('id');if(d&&d!=='admin'){c.preventDefault();t(b,d);}}});a(window).on('keyup.editor',function(c){if(c.which===27){return;var d=a('ul#task-tabs li.active').attr('id');if(d&&d!=='admin'){c.preventDefault();c.stopPropagation();c.stopImmediatePropagation();i(b,d);}}});}function l(b,e){var f=b.tabs[e],g;if(b.editor===undefined)k(b);if(!f.session){g=new c(f.doc);g.setUndoManager(new d());if(f.ext==='py'){g.setMode("ace/mode/python");g.setOption("tabSize",4);g.setUseSoftTabs(true);}else if(f.ext==='js')g.setMode("ace/mode/javascript");else if(f.ext==='html')g.setMode("ace/mode/html");else if(f.ext==='css')g.setMode("ace/mode/css");f.session=g;u(b,e);a(b.editor).focus();}else g=f.session;b.editor.setSession(g);b.editor.$blockScrolling=Infinity;m(b,f);n(b);b.resize_elements(b);b.editor.focus();}function m(b,c){b.code_editor.find("#editor-tabs").detach();b.code_editor.find('#left-box').append(c.editor_tabs);if(c.name==='project.css')b.code_editor.find("#left-box").hide();else b.code_editor.find("#left-box").show();v(b,b.task_dict,"task");if(a('#editor-tabs li#fields').length&&c.item_id){c.fields=b.task_item_fields[c.item_id];v(b,c.fields,"fields");}x(b,a('#editor-tabs li.active'));}function n(a,b){a.code_editor.find('#ok-btn').prop("disabled",!p(a));}function o(a,b){a.code_editor.find('#error-info').text(b);}function p(a){return !a.editor.session.getUndoManager().isClean();}function q(a){a.editor.session.getUndoManager().markClean();}function r(a,b){var c=a.editor.getValue(),d,e,f,g;if(b.doc_type==="server"&&c.indexOf('\t')!==-1)c=c.split('\t').join('  ');d=a.task.server('server_save_edit',[b.rec_id,c,b.ext==='py']);if(d.error&&d.line&&d.line<a.editor.session.getLength())a.editor.gotoLine(d.line);if(!d.error){b.module=d.module_info;v(a,b.module,"module");A(a);}return d.error;}function s(a,b){var c=a.editor.getValue(),d=a.server('server_save_file',[b.name,c]),e=d.error;if(b.name==='index.html'){b.templates=a.sys_items.get_templates(c);v(a,b.templates,"templates");A(a);}}function t(a,b){var c='',d=a.tabs[b];if(d.doc_type)c=r(a,d);else c=s(a,d);if(c)o(a,c);else{o(a,'');q(a);n(a);}}function u(b,c){var d=b.tabs[c],e;b.code_editor.find("#editor-tabs").detach();e=a('<div id="editor-tabs">'+'<ul class="nav nav-tabs editor">'+'</ul>'+'<div id="info-grids">'+'</div>'+'</div>');b.code_editor.find('#left-box').append(e);z();if(d.doc_type){b.code_editor.find('#editor-tabs ul').append('<li id="module"><a href="#">Module</a></li>').append('<li id="events"><a href="#">Events</a></li>').append('<li id="task"><a href="#">Task</a></li>').append('<li id="fields"><a href="#">Fields</a></li>');v(b,d.module,"module");v(b,d.events,"events");v(b,b.task_dict,"task");v(b,d.fields,"fields");x(b,a('#editor-tabs li#module'));}else if(d.templates){b.code_editor.find('#editor-tabs ul').append('<li id="templates"><a href="#">templates</a></li>').append('<li id="task"><a href="#">Task</a></li>');v(b,d.templates,"templates");v(b,b.task_dict,"task");x(b,b.code_editor.find('#editor-tabs li#templates'));}else{b.code_editor.find('#editor-tabs ul').append('<li id="task"><a href="#">Task</a></li>');v(b,b.task_dict,"task");x(b,b.code_editor.find('#editor-tabs li#task'));}d.editor_tabs=e;}function v(b,c,d){var e=b.sys_code_editor.copy(),f=b.code_editor.find('#editor-tabs ul li#'+d),g;g=b.code_editor.find('#editor-tabs #info-grids > div.'+d);if(g.length)g.empty();else{g=a('<div id="'+d+'" class="info-tree '+d+'">');b.code_editor.find('#editor-tabs #info-grids').append(g);}g.hide();e.open({open_empty:true});w(e,c,0);e.disable_controls();try{e.create_tree(g,{id_field:'id',parent_field:'parent',text_field:'name',parent_of_root_value:0});}finally{e.enable_controls();}}function w(a,b,c){var d=[],e=0;for(var f in b)d.push(f);d=d.sort();e=c+1;if(d.length)for(var g=0;g<d.length;g++){a.append();a.id.value=e;a.parent.value=c;a.name.value=d[g];a.post();if(b[d[g]]!==null&&typeof b[d[g]]==='object')e=w(a,b[d[g]],e);e++;}return e;}function x(a,b){a.code_editor.find('#editor-tabs li').removeClass('active');b.addClass('active');A(a);}function y(a,b,c){var d=a.tabs[b],e=c.closest('.info-tree').attr('id'),f=c.find('span.tree-text:first').text(),g,h,i;if(e==='module'){a.editor.gotoLine(1);if(d.ext==='py')g='def '+f;else g='function '+f;h=B(a,g);}else if(e==='events'){a.editor.gotoLine(1);if(!B(a,f+'(')){i=d.events[f];a.editor.gotoLine(a.editor.session.getLength()+1);if(d.ext==='py')g='def '+f+'('+i+'):\n\tpass';else g='function '+f+'('+i+') {\n\n}';a.editor.insert('\n\n'+g);}}else if(e==='task'||e==='fields')a.editor.insert(f);else if(e==='templates'){a.editor.gotoLine(1);g=f;B(a,g);}a.editor.focus();}function z(){b.code_editor.find('#info-grids').height(b.code_editor.find('#left-box').innerHeight()-b.code_editor.find('ul.nav-tabs').outerHeight()-14);}function A(a){var b,c,d;b=a.code_editor.find('#editor-tabs > .nav > li.active');if(b.length){d=a.code_editor.find('#editor-tabs #info-grids').innerHeight();a.code_editor.find('#editor-tabs div.info-tree').hide();a.code_editor.find('#editor-tabs div.info-tree.'+b.attr('id')).show().height(d).find('.dbtree').height(d);c=a.code_editor.find('#editor-tabs div.info-tree.'+b.attr('id')).find('.dbtree').data('tree');if(c)c.scroll_into_view();}}function B(a,b){return a.editor.find(b,{backwards:false,wrap:false,caseSensitive:true,wholeWord:true,regExp:false});}this.init_tabs=e;this.resize=f;this.show_tab=g;this.show_editor=h;this.close_editor=i;this.close_query=j;this.init_editor=k;this.select_editor=l;this.show_info_tabs=m;this.update_buttons=n;this.update_error_message=o;this.get_modified=p;this.mark_clean=q;this.save_module=r;this.save_file=s;this.save_edit=t;this.create_info_tabs=u;this.add_tree=v;this.build_tree=w;this.info_tab_clicked=x;this.tree_node_clicked=y;this.set_info_grids_height=z;this.update_tab_height=A;this.find_text=B;}b.events.events14=new g();function h(){var b=0,c=1,d=2,e=3,f=4,g=3,h=0,i=1,j=2,k=0,l=1;function m(a,b,c,d,e,f,g,h,i,j,k){var l=this.copy();l.item=b;l.type=a;l.view_options.title=c;l.source_def=d;l.source_list=e;l.dest_def=f;l.dest_object=g;l.save_func=h;l.cancel_func=i;if(j===undefined)j=true;l.can_move=j;if(k===undefined)k=false;l.read_only=k;l.view();return l;}function n(b,d){var i,j,k;E(b);if(b.dest_object.media=undefined)if(b.type==='view')b.dest_object[d]=['',{},[],{},[]];else if(b.type==='edit')b.dest_object[d]={0:['',{},[],[['',[[{},[],'']]]]]};b.cur_media=b.dest_object[d];b.cur_media[c]=s(b,b.cur_media[c]);if(b.type==='view'){b.cur_media[e]=t(b,b.cur_media[e]);b.dest_list=b.cur_media[f];}else{k=b.cur_media[g];b.view_form.find('#field-tabs > li').remove();for(i=0;i<k.length;i++){j=a('<li><a href="#tab'+(i+1)+'">'+b.cur_media[g][i][h]+'</a></li>');j.data('tab',i);b.view_form.find('#field-tabs').append(j);}if(k.length===1&&k[0][h]==='')b.view_form.find('#field-tabs > li').hide();else{b.view_form.find('#field-tabs > li').show();b.view_form.find('#field-tabs > li').eq(0).addClass('active');}b.set_cur_tab(b,0);}z(b);}function o(b,c){var d,e=b.cur_media[g],f;b.cur_tab=e[c];p(b,b.cur_tab[i][0]);b.view_form.find('#field-bands').empty();for(d=0;d<b.cur_tab[i].length;d++){f=a('<li><a href="#band'+(d+1)+'">'+b.cur_tab[i][d][j]+'</a></li>');f.data('band',b.cur_tab[i][d]);b.view_form.find('#field-bands').append(f);}if(b.cur_tab[i].length===1&&b.cur_tab[i][0][j]==='')b.view_form.find('#field-bands > li').hide();else{b.view_form.find('#field-bands > li').show();b.view_form.find('#field-bands > li').eq(0).addClass('active');}}function p(a,b){E(a);a.cur_band=b;b[k]=t(a,b[k]);a.dest_list=a.cur_band[l];z(a);}function q(b){var c,d;if(b.type==='edit'||b.type==='view'){b.view_form.find('#section-tabs').show();b.view_form.find('#buttons').hide();b.view_form.find('#form').hide();b.view_form.on('click','#section-tabs > li > a',function(c){c.preventDefault();a('#section-tabs > li').removeClass('active');a(this).parent().addClass('active');if(a(this).attr("href")==='#layout'){b.view_form.find('#layout').show();b.view_form.find('#buttons').hide();b.view_form.find('#form').hide();}else if(a(this).attr("href")==='#buttons'){b.view_form.find('#layout').hide();b.view_form.find('#buttons').show();b.view_form.find('#form').hide();}else{b.view_form.find('#layout').hide();b.view_form.find('#buttons').hide();b.view_form.find('#form').show();}});n(b,0);b.view_form.find('#media-tabs').show();b.view_form.on('click','#media-tabs > li > a',function(c){c.preventDefault();a('#media-tabs > li').removeClass('active');a(this).parent().addClass('active');n(b,a(this).parent().data('media'));});if(b.type==='edit'){b.view_form.find('#media-tabs').show();b.view_form.find('#field-tabs').show();b.view_form.find('#bands-box').show();b.view_form.on('click','#field-tabs > li > a',function(c){c.preventDefault();a('#field-tabs > li').removeClass('active');a(this).parent().addClass('active');o(b,a(this).parent().data('tab'));});b.view_form.on('click','#field-bands > li > a',function(c){c.preventDefault();a('#field-bands > li').removeClass('active');a(this).parent().addClass('active');p(b,a(this).parent().data('band'));});b.view_form.find('#add-tab-btn').tooltip({placement:'bottom',title:'New tab',trigger:'hover'}).click(function(){r(b,'new_tab');});b.view_form.find('#edit-tab-btn').tooltip({placement:'bottom',title:'Edit tab',trigger:'hover'}).click(function(){r(b,'edit_tab');});b.view_form.find('#delete-tab-btn').tooltip({placement:'bottom',title:'Delete tab',trigger:'hover'}).click(function(){r(b,'del_tab');});b.view_form.find('#add-band-btn').tooltip({placement:'top',title:'New band',trigger:'hover'}).click(function(){r(b,'new_band');});b.view_form.find('#delete-band-btn').tooltip({placement:'top',title:'Delete band',trigger:'hover'}).click(function(){r(b,'del_band');});}}else{b.dest_list=b.dest_object;z(b);}}function r(b,c){var d,e,f;if(c==='del_tab'){if(b.cur_media[g].length===1){b.cur_media[g][0][h]='';b.view_form.find('#field-tabs > li.active').hide();}else{d=b.cur_media[g].indexOf(b.cur_tab);b.cur_media[g].splice(d,1);if(d===b.cur_media[g].length)d-=1;b.view_form.find('#field-tabs > li.active').remove();b.view_form.find('#field-tabs > li').eq(d).addClass('active');o(b,d);}}else if(c==='new_band')if(b.cur_tab[i].length===1&&b.cur_tab[i][0][j]===''){b.cur_tab[i][0][j]='Band 1';b.view_form.find('#field-bands > li > a').text('Band 1');b.view_form.find('#field-bands > li').show();}else{e=[{},[],'Band '+(b.cur_tab[i].length+1)];a('#field-bands > li').removeClass('active');b.cur_tab[i].push(e);f=a('<li class="active"><a href="#band"'+(b.cur_tab[i].length+1)+'>'+e[j]+'</a></li>');f.data('band',e);b.view_form.find('#field-bands').append(f);p(b,e);}else if(c==='del_band'){if(b.cur_tab[i].length===1){b.cur_tab[i][0][j]='';b.view_form.find('#field-bands > li.active').hide();}else{d=b.cur_tab[i].indexOf(b.cur_band);b.cur_tab[i].splice(d,1);if(d===b.cur_tab[i].length)d-=1;b.view_form.find('#field-bands > li.active').remove();b.view_form.find('#field-bands > li').eq(d).addClass('active');p(b,b.cur_tab[i][d]);}}else{var k=b.copy({handlers:false});k.open({open_empty:true});k.on_edit_form_created=function(d){d.edit_form.find('#ok-btn').off('click.task').on('click',function(){var d,e,f;if(k.name.value){if(c==='new_tab')if(b.cur_media[g].length===1&&b.cur_media[g][0][h]===''){b.cur_media[g][0][h]=k.name.value;b.view_form.find('#field-tabs > li > a').text(k.name.value);b.view_form.find('#field-tabs > li').addClass('active').show();}else{d=[k.name.value,[[{},[],'']]];b.view_form.find('#field-tabs > li').removeClass('active');b.cur_media[g].push(d);e=a('<li class="active"><a href="#tab'+(b.cur_media[g].length+1)+'">'+d[h]+'</a></li>');e.data('tab',b.cur_media[g].length-1);b.view_form.find('#field-tabs').append(e);o(b,b.cur_media[g].length-1);}else if(c==='edit_tab'){b.cur_tab[h]=k.name.value;b.view_form.find('#field-tabs > li.active a').text(k.name.value);}k.cancel_edit();}});};k.edit_options.fields=['name'];k.edit_options.width=400;k.append();if(c==='new_tab')k.edit_options.title='New tab';else if(c==='edit_tab')if(b.cur_media[g].length===1&&b.cur_media[g][0][h]==='')return;else{k.edit_options.title='Edit tab';k.name.value=b.cur_tab[h];}k.edit_record();}}function s(a,b){return t(a,b,true);}function t(a,b,c){var d,e,f,g,h,i,j=[];a._options_changing=true;try{a.on_field_get_text=function(a){if(a.value===0)return '';};if(c){if(a.type==='edit')h=a.item.edit_form_options_list(a.item);if(a.type==='view')h=a.item.view_form_options_list(a.item);e=a.view_form.find('#form-options-div');a.view_form.find('#form-options-box').show();}else{if(a.type==='edit')h=a.item.edit_options_list(a.item);if(a.type==='view')h=a.item.view_options_list(a.item);e=a.view_form.find('#options-div');a.view_form.find('#options-box').show();}h=JSON.parse(JSON.stringify(h));if(!h.length)return{};if(!a.is_changing()){a.open({open_empty:true});a.append();}g={};for(d=0;d<h.length;d++){f=h[d][1];if(b[h[d][0]]!==undefined){f=b[h[d][0]];g[h[d][0]]=f;}a[h[d][0]].value=f;j.push(h[d][0]);}b=g;a.create_inputs(e,{fields:j,in_well:false,label_width:140});a.on_field_changed=u;a.on_field_select_value=function(b,c){if(b.field_name==='edit_details'||b.field_name==='view_detail'){c.set_where({parent:a.item.id.value});c.view_options.fields=['f_item_name'];c.set_order_by(['f_item_name']);c.on_after_scroll=undefined;if(b.field_name==='view_detail'){c.view_options.title='Select detail to view';c.on_selection_changed=function(a,b,d){if(!c.sel_changing){c.sel_changing=true;try{if(a.selections.length>1)a.selections=b;}finally{c.sel_changing=false;}}};}else c.view_options.title='Select details to edit';}else{var d=[],e=a.dest.clone(),f={id__in:d};e.each(function(a){d.push(a.id.value);});if(b.field_name==='summary_fields')c.view_options.title='Select summary fields';else if(b.field_name==='sort_fields')c.view_options.title='Select fields to sort by';else{c.view_options.title='Select fields to edit';f.f_read_only=false;}c.set_where(f);c.view_options.fields=['f_field_name'];c.set_order_by(['f_field_name']);if(b.field_name==='search_field'){c.view_options.title='Select default search field';c.on_selection_changed=function(a,b,d){if(!c.sel_changing){c.sel_changing=true;try{if(a.selections.length>1)a.selections=b;}finally{c.sel_changing=false;}}};}}c.view_options.width=300;};}finally{a._options_changing=false;}return b;}function u(a){var b,d,f=a.owner,g,h,i;if(!f._options_changing){i=f.cur_media[c];if(f.type==='edit')h=f.item.edit_form_options_list(f.item);if(f.type==='view')h=f.item.view_form_options_list(f.item);for(b=0;b<h.length;b++)if(h[b][0]===a.field_name){g=true;break;}if(!g){if(f.type==='edit'){i=f.cur_band[k];h=f.item.edit_options_list(f.item);}if(f.type==='view'){i=f.cur_media[e];h=f.item.view_options_list(f.item);}}delete i[a.field_name];if(a.value instanceof Array){if(a.value.length!==0)i[a.field_name]=a.value;}else for(b=0;b<h.length;b++)if(h[b][0]===a.field_name)if(h[b][1]!==a.value)i[a.field_name]=a.value;}}function v(a){if(a.type==='edit')a.view_options.width=1080;else if(a.type==='view')a.view_options.width=960;else a.view_options.width=660;x(a);}function w(a){q(a);}function x(b){var c={},d,e;b.fields=b.copy();if(b.dest_def[1].length===4)c={'name':b.dest_def[1][3]};b.source=b.copy(),e=[];for(d=0;d<b.source_def.length;d++)if(b.source_def[d][2])e.push(b.source_def[d][0]);b.source.set_view_fields(e);b.source.open({open_empty:true});for(d=0;d<b.source_def.length;d++)if(b.source_def[d][2])b.source.field_by_name(b.source_def[d][0]).field_caption=b.source_def[d][1];b.dest=b.copy();e=[];for(d=0;d<b.dest_def.length;d++)if(b.dest_def[d][2])e.push(b.dest_def[d][0]);b.dest.set_view_fields(e);b.dest.open({open_empty:true});for(d=0;d<b.dest_def.length;d++)if(b.dest_def[d][2])b.dest.field_by_name(b.dest_def[d][0]).field_caption=b.dest_def[d][1];b.left_grid=b.dest.create_table(b.view_form.find("#left-grid"),{height:360,column_width:c,editable:true,editable_fields:['param3'],dblclick_edit:false,striped:false});b.right_grid=b.source.create_table(b.view_form.find("#right-grid"),{height:360,dblclick_edit:false,striped:false});b.left_grid.$table.keydown(function(a){var c=(a.keyCode?a.keyCode:a.which);if(c===32){a.preventDefault();D(b);}});b.right_grid.$table.keydown(function(a){var c=(a.keyCode?a.keyCode:a.which);if(c===32){a.preventDefault();C(b);}});if(!b.can_move)b.view_form.find("#vert-btns-box").hide();b.view_form.find("#up-btn").attr('tabindex',-1).click(function(){b.task.move_record_up(b.dest);});b.view_form.find("#down-btn").attr('tabindex',-1).click(function(){b.task.move_record_down(b.dest);});b.view_form.find("#left-btn").attr('tabindex',-1).click(function(){C(b);});b.view_form.find("#right-btn").attr('tabindex',-1).click(function(){D(b);});b.view_form.find("#cancel-btn").text(b.task.language.cancel).on('click.task',function(a){H(b);});b.view_form.find("#ok-btn").text(b.task.language.ok).on('click.task',function(){F(b);});if(b.read_only)b.view_form.find("button.arrow_btn").hide();b.left_grid.$table.on('click','td',function(){var c=a(this),d=c.data('field_name'),e=b.dest.field_by_name(d);if(e.field_type==="boolean"&&!b.read_only){if(!b.dest.is_changing())b.dest.edit();e.value=!e.value;b.dest.post();}});}function y(a){var b,c,d,e,f,h,j,k,m,n=[];if(a.type==='edit'){for(b=0;b<a.source_list.length;b++){f=a.source_list[b];j=false;for(c=0;c<a.cur_media[g].length;c++){k=a.cur_media[g][c];for(d=0;d<k[i].length;d++){m=k[i][d];for(e=0;e<m[l].length;e++){h=m[l][e];if(f[0]===h[0]){j=true;break;}}if(j)break;}if(j)break;}if(!j)n.push(f.slice());}return n;}else for(b=0;b<a.source_list.length;b++){f=a.source_list[b];j=false;for(c=0;c<a.dest_list.length;c++){h=a.dest_list[c];if(f[0]===h[0]){j=true;break;}}if(!j)n.push(f.slice());}return n;}function z(a){var b,c,d,e,f,g,h;a.s_list=y(a);a.d_list=[];f=[];for(b=0;b<a.dest_list.length;b++){h=a.dest_list[b];e=false;for(c=0;c<a.source_list.length;c++){g=a.source_list[c];if(g[0]===h[0]){e=true;break;}}if(e){f.push(g[1]);a.d_list.push(h.slice());}}a.source.disable_controls();try{a.source.first();while(!a.source.eof())a.source["delete"]();for(b=0;b<a.s_list.length;b++){g=a.s_list[b];a.source.append();for(d=0;d<a.source_def.length;d++)a.source.field_by_name(a.source_def[d][0]).value=g[d];a.source.post();}a.source.first();}finally{a.source.enable_controls();}a.source.update_controls();a.dest.disable_controls();try{a.dest.first();while(!a.dest.eof())a.dest["delete"]();for(b=0;b<a.d_list.length;b++){h=a.d_list[b];a.dest.append();a.dest.id.value=h[0];a.dest.name.value=f[b];for(d=2;d<a.dest_def.length;d++)a.dest.field_by_name(a.dest_def[d][0]).value=h[d-1];a.dest.post();}a.dest.first();}finally{a.dest.enable_controls();}a.dest.update_controls();}function A(a,b,c){if(b.record_count()){c.append();c.id.value=b.id.value;c.name.value=b.name.value;c.post();b["delete"]();B(a);}}function B(a){var b,c=['sort_fields','edit_fields','summary_fields','search_field'],d,e=a.dest.clone(),f,g;if(!a._options_changing)for(b=0;b<c.length;b++){d=a.field_by_name(c[b]);if(d&&d.value.length&&d.field_type==='keys'){f=d.value;g=[];e.each(function(a){if(f.indexOf(a.id.value)!==-1)g.push(a.id.value);});if(!a.is_changing())a.edit();d.value=g;}}}function C(a){A(a,a.source,a.dest);}function D(a){A(a,a.dest,a.source);}function E(a){var b=[],c=a.dest.rec_no;if(a.dest_list){a.dest.disable_controls();try{a.dest.each(function(c){var d,e=[];e.push(c.id.value);for(d=2;d<a.dest_def.length;d++)e.push(a.dest.field_by_name(a.dest_def[d][0]).value);b.push(e);});}finally{a.dest.rec_no=c;a.dest.enable_controls();}if(a.type==='edit')a.cur_band[l]=b;else if(a.type==='view')a.cur_media[f]=b;else a.dest_object=b;}}function F(a){E(a);a.save_func(a.item,a.dest_object);a.close_view_form();}function G(a){if(a.item.is_changing())if(a.cancel_func)a.cancel_func(a.item);}function H(a){a.close_view_form();}this.fields_editor=m;this.set_cur_media=n;this.set_cur_tab=o;this.set_cur_band=p;this.set_editor_type=q;this.change_ed=r;this.set_form_options=s;this.set_options=t;this.update_option=u;this.on_view_form_created=v;this.on_view_form_shown=w;this.set_layout=x;this.get_source_list=y;this.update_lists=z;this.move_hor=A;this.update_selected_fields=B;this.move_left=C;this.move_right=D;this.save_layout=E;this.save_result=F;this.on_view_form_close_query=G;this.item_cancel=H;}b.events.events15=new h();function i(){function a(a){if(a.task.init_project&&a.f_language.value){a.task.server('server_set_project_langage',[a.f_language.value]);location.reload();}else if(a._safe_mode!==a.f_safe_mode.value||a._language!==a.f_language.value){a.task.logout();location.reload();}else a.task.update_task_info(a.task);}function c(a){var c=a.edit_form.find('.edit-body'),d,e;if(a.task.init_project)a.create_inputs(c,{fields:['f_language'],in_well:false});else{a._safe_mode=a.f_safe_mode.value;a._language=a.f_language.value;a._theme=a.f_theme.value;a.edit_options.width=620;b.init_tabs(c);d=b.add_tab(c,b.language.general);e=b.add_tab(c,b.language.interface);a.create_inputs(d,{fields:['f_language','f_safe_mode','f_debugging','f_con_pool_size','f_mp_pool','f_persist_con','f_compressed_js','f_single_file_js','f_dynamic_js','f_history_item','f_timeout','f_ignore_change_ip','f_delete_reports_after','f_version'],in_well:false,label_width:240});a.create_inputs(e,{fields:['f_theme','f_small_font','f_full_width','f_forms_in_tabs'],in_well:false,label_width:240});}}function d(a){var b=a.edit_form.find('.edit-body');if(!a.task.init_project)b.css('min-height',b.height());}function e(a){if(a.field_name==='f_con_pool_size'&&a.value<1)a.value=1;}function f(a,b){if(a.field_name==='f_history_item'||a.field_name==='f_lock_item'){if(a.field_name==='f_history_item')b.set_where({sys_id:1});else if(a.field_name==='f_lock_item')b.set_where({sys_id:2});b.view_options.template_class='sys_items_system';b.view_options.fields=['f_name','f_item_name'];}}function g(a){var c;if(a.lookup_field.field_name==='f_history_item')c=b.language.create_history_item;else if(a.lookup_field.field_name==='f_lock_item')c='Create lock item';a.view_form.find('#create-btn').text(c).click(function(){h(a);});}function h(a){var b=a.task.server('create_system_item',a.lookup_field.field_name),c=b[0],d=b[1];if(d)a.warning(d);else a.warning(c,function(){location.reload();});}this.on_after_apply=a;this.on_edit_form_created=c;this.on_edit_form_shown=d;this.on_field_changed=e;this.on_field_select_value=f;this.init_lookup_form=g;this.create_system_item=h;}b.events.events11=new i();function j(){function c(a){var b=a.sys_search.copy();b.open({open_empty:true});b.set_edit_fields(['find_text','case_sensitive','whole_words']);b.append_record();}function d(a){a.edit_form.title=b.language.find;a.edit_form.find("#cancel-btn").text(b.language.close);a.edit_form.find("#ok-btn").text(b.language.find).off('click.task').on('click',function(){e(a);});}function e(c){var d,e,f,g,h=a(window).width()-50,i=a(window).height()-200,j=a('<div>');if(c.find_text.value){d=c.task.server('server_find_in_task',[c.task.sys_tasks.task_id.value,c.find_text.value,c.case_sensitive.value,c.whole_words.value]);if(d){j.append(a('<h4>Client</h4>'));g=d.client.split('\n');for(e=0;e<g.length;e++){f=a('<p style="margin: 0px;">').text(g[e]);f.css("font-family","'Courier New', Courier, monospace");j.append(f);}j.append(a('<h4>Server</h4>'));g=d.server.split('\n');for(e=0;e<g.length;e++){f=a('<p style="margin: 0px;">').text(g[e]);f.css("font-family","'Courier New', Courier, monospace");j.append(f);}b.message(j,{title:'Search result',margin:10,width:h,height:i,text_center:false,buttons:{"Close":undefined},center_buttons:false,print:true});}}}function f(a,b){if(b.keyCode===13){b.preventDefault();a.edit_form.find("#ok-btn").focus();e(a);}}this.find_in_task=c;this.on_edit_form_created=d;this.find=e;this.on_edit_form_keydown=f;}b.events.events16=new j();function k(){function a(a,b){a.view_options.width=440;b.height=400;}function b(a){return a.task.server('server_can_delete_lookup_list',a.id.value);}function c(a){a.view_form.find("#select-btn").hide();a.view_form.find('#delete-btn').off('click.task').on('click',function(){a.question(a.task.language.delete_record,function(){var c=b(a);if(c)a.warning(c);else{a["delete"]();a.apply();}});});}function d(a){var b=a.task.sys_field_lookups.copy();a.lookups=b;e(a);a.edit_form.find("#new-btn").on('click.task',function(){b.append_record();});a.edit_form.find("#edit-btn").on('click.task',function(){b.edit_record();});a.edit_form.find("#delete-btn").on('click',function(){b.delete_record();});a.edit_table=b.create_table(a.edit_form.find(".edit-detail"),{height:300,column_width:{f_value:'15%'},sortable:true});}function e(a){var b=[];a.lookups.open({open_empty:true});if(!a.is_new()){b=JSON.parse(a.f_lookup_values_text.value);for(var c=0;c<b.length;c++){a.lookups.append();a.lookups.f_value.value=b[c][0];a.lookups.f_lookup.value=b[c][1];a.lookups.post();}}}function f(a){var b=[];a.lookups.each(function(a){b.push([a.f_value.value,a.f_lookup.value]);});a.f_lookup_values_text.value=JSON.stringify(b);}this.init_view_table=a;this.can_delete=b;this.on_view_form_created=c;this.on_edit_form_created=d;this.init_lookups=e;this.on_before_post=f;}b.events.events18=new k();function l(){function a(a){a.view_options.width=400;a.view_form.find("#select-btn").click(function(){a.lookup_field.value=a.id.value;});}this.on_view_form_created=a;}b.events.events20=new l();function m(){function a(a){a.view_options.width=400;a.view_form.find("#select-btn").click(function(){a.lookup_field.value=a.id.value;});}this.on_view_form_created=a;}b.events.events21=new m();function n(){function a(a,b){var c=document.createElement('a');c.setAttribute('href','data:text/plain;charset=utf-8,'+encodeURIComponent(b));c.setAttribute('download',a);c.style.display='none';document.body.appendChild(c);c.click();document.body.removeChild(c);}function c(c){c.view_options.width=500;c.set_order_by(['f_name']);c.view_form.find('#import-btn').click(function(){b.upload('static/reports',{multiple:false,callback:function(a){c.server('import_lang',['static/reports/'+a],function(a){if(a)c.warning(a);else c.open(true);});}});});c.view_form.find('#export-btn').click(function(){var b=location.protocol+'//'+location.hostname+(location.port?':'+location.port:'');c.server('export_lang',[c.id.value,b],function(b){a(b.file_name,b.content);});});}function d(a){a.locate('id',b.sys_params.f_language.value);}function e(a){var c=a.edit_form.find('.edit-body'),d,e,f=a.f_language.value&&a.f_country.value;a.f_language.read_only=f;a.f_country.read_only=f;a.transl_table=b.sys_lang_keys_values.copy();a.edit_options.width=1000;a.create_inputs(a.edit_form.find('.edit-title'),{fields:['f_language','f_country'],col_count:2});b.init_tabs(c);d=b.add_tab(c,'Locale');e=b.add_tab(c,'Translation');a.create_inputs(d,{fields:['f_decimal_point','f_mon_decimal_point','f_mon_thousands_sep','f_currency_symbol','f_frac_digits','f_p_cs_precedes','f_n_cs_precedes','f_p_sep_by_space','f_n_sep_by_space','f_positive_sign','f_negative_sign','f_p_sign_posn','f_n_sign_posn','f_d_fmt','f_d_t_fmt'],label_width:500});d.find('input.input-text').width(120);d.find('input.input-integer').width(20);e.append('<div id="table-div">');a.transl_table.open({open_empty:true});l(a);a.transl_table.create_table(e.find("#table-div"),{fields:['f_key_str','f_eng_str','f_value'],height:520,row_line_count:0,sortable:true,editable:true,editable_fields:['f_value'],dblclick_edit:false,column_width:{f_key_str:'5%',f_eng_str:'50%',f_value:'50%'}});a.transl_table.create_inputs(e.find("#inputs-div"),{fields:['f_eng_str','f_value']});a.edit_form.find('.modal-footer #new-btn').click(function(){var b=a.transl_table.copy({handlers:false});b.init_edit_options=function(a,b){b.fields=['f_key_str'];};b.on_edit_form_created=function(b){b.edit_form.find('#ok-btn').off('click.task').on('click',function(){var c=b.f_key_str.value;b.cancel();a.server('add_key',c,function(c){if(c)a.warning(c);else{b.close_edit_form();a.transl_table.on_field_changed=null;a.transl_table.open({open_empty:true});l(a);}});});};b.open({open_empty:true});b.append_record();});a.edit_form.find('.modal-footer #delete-btn').click(function(){a.question('Delete the record?',function(){a.server('del_key',a.transl_table.f_key.value,function(b){if(b){a.transl_table.on_field_changed=null;a.transl_table.open({open_empty:true});l(a);}});});});}function f(a,b){if(b.keyCode===77&&b.ctrlKey===true){a.edit_form.find('.modal-footer #new-btn').show();a.edit_form.find('.modal-footer #delete-btn').show();}}function g(a){var c=b.sys_countries.copy(),d=b.sys_languages.copy();c.open({where:{id:a.f_country.value}});d.open({where:{id:a.f_language.value}});return a.f_language.display_text+' '+d.f_abr.value+'-'+c.f_abr.value;}function h(a){var c=b.sys_countries.copy(),d=b.sys_languages.copy(),e={};c.open({where:{id:a.f_country.value}});d.open({where:{id:a.f_language.value}});e.abr=d.f_abr.value+'-'+c.f_abr.value;e.name=d.f_name.value+' '+e.abr;e.rlt=d.f_rtl.value;return e;}function i(a){var b=false,c=a.clone();c.each(function(c){if(c.id.value&&c.f_language.value===a.f_language.value&&c.f_country.value===a.f_country.value){b=true;return false;}});return b;}function j(a){var b=null,c=a.clone();c.each(function(c){if(c.id.value&&c.f_language.value===a.f_language.value){b=c.id.value;return false;}});return b;}function k(a,b){var c,d=a.owner;if(!d._field_changed){d._field_changed=true;try{if(d.f_language.value&&d.f_country.value){if(!d.id.value)if(i(d)){d.warning('There is a language with this parameters.');a.value=null;return;}else{c=h(d);d.f_name.value=c.name;d.f_abr.value=c.abr;d.f_rtl.value=c.rtl;d.apply();d.server('add_lang',[d.id.value,d.f_language.value,d.f_country.value,c.name,c.abr,c.rtl,j(d)]);d.refresh_record();d.edit();l(d);}d.apply();d.edit();d.server('save_lang_field',[d.id.value,a.field_name,a.value],true);}}finally{d._field_changed=false;}}}function l(a){var b;if(a.f_language.value&&a.f_country.value){a.transl_table.open({open_empty:true});a.server('get_lang_translation',[1,a.id.value],function(b){a.transl_table.disable_controls();try{for(var c=0;c<b.length;c++){a.transl_table.append();a.transl_table.f_key.value=b[c][0];a.transl_table.f_key_str.value=b[c][1];a.transl_table.f_eng_str.value=b[c][2];a.transl_table.f_value.value=b[c][3];a.transl_table.post();}}finally{a.transl_table.enable_controls();a.transl_table.update_controls();}a.transl_table.on_after_scroll=function(a){if(a.rec_count&&!a.is_changing())a.edit();};a.transl_table.first();a.transl_table.f_eng_str.read_only=true;a.transl_table.on_field_changed=function(b){a.server('save_lang_translation',[a.id.value,a.transl_table.f_key.value,a.transl_table.f_value.value],function(b,c){if(c)a.warning(c);});};});}}function m(a){if(a.is_changing())a.cancel();return true;}this.save_file=a;this.on_view_form_created=c;this.on_view_form_shown=d;this.on_edit_form_created=e;this.on_edit_form_keyup=f;this.get_lang_name=g;this.get_lang_info=h;this.lang_exists=i;this.find_lang=j;this.on_field_changed=k;this.fill_table=l;this.on_edit_form_close_query=m;}b.events.events22=new n();function o(){function a(a){a.view_form.find('#up-btn').click(function(){a.task.move_record_up(a);});a.view_form.find('#down-btn').click(function(){a.task.move_record_down(a);});}function b(a){}function c(a){a.edit_form.find('textarea.f_help').attr('rows',3).height(40);d(a);}function d(a){a.f_multi_select_all.read_only=a.f_type.value!==a.task.consts.FILTER_IN&&a.f_type.value!==a.task.consts.FILTER_NOT_IN;if(a.f_multi_select_all.read_only&&a.is_changing())a.f_multi_select_all.value=false;}function e(a){a.task_id.value=a.task.sys_items.task_id.value;a.owner_id.value=0;a.f_visible.value=true;a.f_index.value=a.record_count();a.f_type.value=1;}function f(a){a.owner_rec_id.value=a.task.sys_items.id.value;a.owner.value=a.task.sys_items.ID;}function g(a,b){var c,e=a.owner;if(a.field_name==='f_field'){c=e.task.sys_fields.copy();c.set_where({id:a.value});c.open();e.f_name.value=c.f_name.value;e.f_filter_name.value=c.f_field_name.value;e.f_help.value=c.f_help.value;}d(e);}function h(a,b){var c,d=a.owner;if(a.field_name==='f_field'){c=d.copy();b.filters.owner_rec_id.value=[d.task.sys_items.id.value,d.task.sys_items.parent.value];b.filters.master_field_is_null.value=true;b.set_view_fields(['f_field_name','f_name']);b.set_order_by(['f_field_name']);}}function i(a){var b=0;a.each(function(a){a.edit();a.f_index.value=b;a.post();b++;});a.apply();}this.on_view_form_created=a;this.on_view_form_shown=b;this.on_edit_form_created=c;this.update_multi_select_all=d;this.on_after_append=e;this.on_before_post=f;this.on_field_changed=g;this.on_field_select_value=h;this.on_view_form_close_query=i;}b.events.events5=new o();function p(){function a(a){a.view_form.find("#edit-btn").text(a.task.language.view);if(a.foreign_index){a.f_index_name.field_caption='Foreign key';a.view_options.fields=['f_foreign_field','f_index_name'];a.edit_options.fields=a.view_options.fields;a.f_foreign_field.required=true;a.f_index_name.required=true;}else{a.f_index_name.field_caption='Index';if(a.task.db_options.DATABASE==='FIREBIRD')a.view_options.fields=['f_index_name','f_unique_index','descending'];else a.view_options.fields=['f_index_name','f_unique_index'];a.edit_options.fields=a.view_options.fields;a.f_foreign_field.required=false;a.view_form.find("#new-btn").off('click.task').on('click.task',function(){d(a,true);});a.view_form.find("#edit-btn").off('click.task').on('click.task',function(){d(a,false);});a.view_table.on_dblclick=function(){d(a,false);};}}function c(a,b){if(b.keyCode===45&&b.ctrlKey===true){b.preventDefault();if(a.foreign_index)a.append_record();else d(a,true);}else if(b.keyCode===46&&b.ctrlKey===true){b.preventDefault();a.delete_record();}}function d(a,b){var c,d=[],e=[],f=[],g='';function h(a,c){var d;if(b){if(!a.f_index_name.value)d=a.task.language.index_name_required;if(!c.length)d=a.task.language.index_fields_required;if(d){a.warning(d);throw d;}a.f_fields_list.value=a.server('server_dump_index_fields',[c]);a.post();try{a.apply();}catch(e){a.warning(e);throw e;}}else{a.read_only=false;a.cancel();}}function i(a){a.read_only=false;a.cancel();}function j(a){var b=a.sys_items,c=b.task.sys_fields.copy(),d,e=[];c.set_where({owner_rec_id__in:[b.id.value,b.parent.value]});c.set_order_by(['f_field_name']);c.open({fields:['id','f_field_name','f_master_field']});c.each(function(a){if(!a.f_master_field.value)e.push([a.id.value,a.f_field_name.value]);});return e;}if(b){a.append();a.read_only=false;}else if(a.record_count()>0){a.edit();a.read_only=true;f=a.server('server_load_index_fields',[a.f_fields_list.value]);}else return;d=[['id','',false],['name',a.task.language.caption_name,true]];if(a.task.db_options.DATABASE==='FIREBIRD')e=[['id','',false],['name',a.task.language.caption_name,true]];else e=[['id','',false],['name',a.task.language.caption_name,true],['param1',a.task.language.caption_descening,true]];c=a.task.sys_fields_editor.fields_editor('indices',a,g,d,j(a.task),e,f,h,i,undefined,!b);a.create_inputs(c.view_form.find('div#fields-container'));}function e(a){var b=a.task.task_name,c=a.task.sys_items.f_item_name.value;if(!a.foreign_index)a.f_index_name.value=b.toUpperCase()+'_'+c.toUpperCase()+'_'+'IDX';a.task_id.value=a.task.sys_items.task_id.value;a.owner_rec_id.value=a.task.sys_items.id.value;a.f_foreign_index.value=a.foreign_index;}function f(a,c){function d(b){var c,d,e;if(b.f_object.value&&!b.f_master_field.value){e=b.task.sys_items.field_by_id(b.f_object.value,'f_soft_delete');if(!e){c=a.owner.clone();d=true;c.each(function(a){if(a.f_foreign_field.value==b.id.value){d=false;return false;}});return d;}}}var e=b.sys_items;c.view_options.fields=['f_name','f_field_name'];c.set_where({owner_rec_id__in:[e.id.value,e.parent.value]});c.on_filter_record=d;c.filtered=true;}function g(a,b){var c=a.owner;if(a.field_name==='f_foreign_field')c.f_index_name.value='FK_'+c.task.sys_items.f_table_name.value.toUpperCase()+'_'+a.display_text.toUpperCase();}function h(a){var b=a.owner,c='',d;if(a.field_name==='f_index_name'){d=b.clone();d.each(function(d){if(b.rec_no!==d.rec_no&&a.value===d.f_index_name.value){c='There is index with this name';return false;}});if(c)return c;}}function i(a){return{'manual_update':a.task._manual_update};}this.on_view_form_created=a;this.on_view_form_keydown=c;this.edit_index=d;this.on_after_append=e;this.on_field_select_value=f;this.on_field_changed=g;this.on_field_validate=h;this.on_before_apply=i;}b.events.events10=new p();function q(){function b(b){b.view_options.width=760;b.view_form.find("#select-all-btn").text(b.task.language.select_all).on('click.task',function(){c(b);});b.view_form.find("#unselect-all-btn").text(b.task.language.unselect_all).on('click.task',function(){d(b);});b.view_table.$table.on('click','td',function(){var c=a(this),d=c.data('field_name'),e=b.field_by_name(d);if(e.field_type==="boolean"){if(!b.is_changing())b.edit();e.value=!e.value;}});}function c(a,b){var c=a.rec_no;if(b===undefined)b=true;try{a.disable_controls();a.each(function(a){a.edit();a.f_can_create.value=b;a.f_can_view.value=b;a.f_can_edit.value=b;a.f_can_delete.value=b;a.post();});}finally{a.rec_no=c;a.enable_controls();a.update_controls();}}function d(a){c(a,false);}function e(a){var b=a.copy();b.open({open_empty:true});a.first();while(!a.eof())if(a.id.value)a.next();else{b.append();a.each_field(function(a){b.field_by_name(a.field_name).value=a.value;b.id.value=null;});b.post();a["delete"]();};a.apply(function(){});b.apply(function(){});}function f(a){a.task.sys_roles.server('roles_changed');}this.on_view_form_created=b;this.select_all_clicked=c;this.unselect_all_clicked=d;this.on_view_form_close_query=e;this.on_view_form_closed=f;}b.events.events7=new q();function r(){function a(a){a.task.sys_filters.on_view_form_created(a);a.on_field_validate=a.task.sys_items.sys_fields.on_field_validate;}function b(a){a.task.sys_filters.on_view_form_close_query(a);}function c(a){a.task.sys_filters.on_before_post(a);}function d(a){a.task_id.value=a.task_id.value;a.f_data_type.read_only=false;a.f_visible.value=true;}function e(a,b){var c=a.owner;c.task.sys_items.sys_fields.on_field_changed(a,b);if(a.field_name==='f_object_field'&&b){if(!c.f_name.value)c.f_name.value=b.f_name.value;if(!c.f_param_name.value)c.f_param_name.value=b.f_field_name.value;}}function f(a,b){a.owner.task.sys_items.sys_fields.on_field_select_value(a,b);}function g(a){a.edit_form.find('textarea.f_help').attr('rows',3).height(40);}this.on_view_form_created=a;this.on_view_form_close_query=b;this.on_before_post=c;this.on_after_append=d;this.on_field_changed=e;this.on_field_select_value=f;this.on_edit_form_created=g;}b.events.events12=new r();function s(){function a(a){if(a.field_name==='f_value'&&a.value<=0)return 'Value must be greater than zero';}this.on_field_validate=a;}b.events.events17=new s();function t(){function c(b){function c(){var a=false,c;if(b.owner.id.value&&b.id.value){c=b.task.sys_indices;c.set_where({owner_rec_id:b.owner.id.value});c.open();c.each(function(c){if(c.f_foreign_index.value&&c.f_foreign_field.value===b.id.value)a=true;});}return a;}var d;b.edit_form.find('#field-edit a').click(function(b){b.preventDefault();a(this).tab('show');});b.f_field_name.read_only=b.f_field_name.value==='id'||b.f_field_name.value==='deleted'||b.f_field_name.value==='owner_id'||b.f_field_name.value==='owner_rec_id';b.f_data_type.read_only=false;b.f_size.read_only=false;b.f_object.read_only=false;b.f_object_field.read_only=false;b.f_master_field.read_only=false;b.f_lookup_values.read_only=true;k(b);if(c())b.f_object.read_only=true;if(b.task._manual_update)d=['f_name','f_field_name','f_db_field_name','f_data_type','f_size','f_default_value','f_required','f_read_only'];else d=['f_name','f_field_name','f_data_type','f_size','f_default_value','f_required','f_read_only'];b.create_inputs(b.edit_form.find("#definition"),{fields:d});b.create_inputs(b.edit_form.find("#lookups"),{fields:['f_object','f_object_field','f_object_field1','f_object_field2','f_master_field','f_enable_typehead','f_lookup_values']});b.create_inputs(b.edit_form.find("#interface"),{fields:['f_alignment','f_mask','f_placeholder','f_help']});b.edit_form.find('textarea.f_help').attr('rows',3).height(120);b.edit_form.find("#cancel-btn").text(b.task.language.cancel).on('click.task',function(a){b.cancel_edit(a);return false;});b.edit_form.find("#ok-btn").html(b.task.language.ok+'<small class="muted">&nbsp;[Ctrl+Enter]</small>').on('click.task',function(){b.apply_record();});}function d(a){var b='Field Editor';if(a.f_field_name.value)a.edit_form.find('h4.modal-title').html(b+' <span class="editor-title">'+a.f_field_name.value+'</span>');else a.edit_form.find('h4.modal-title').html(b);}function e(a){a._old_fields={};a.disable_controls();try{a.each(function(b){a._old_fields[b.id.value+'']=true;});}finally{a.first();a.enable_controls();}}function f(a){var b=true;if(a._old_fields)b=!a._old_fields[a.id.value+''];return b;}function g(a,b){var c=a.owner,d,e,f;if(b.item_name==='sys_items')b.set_view_fields(['id','f_item_name','f_name']);else if(b.item_name==='sys_fields'){b.set_order_by(['f_field_name']);b.set_view_fields(['f_field_name','f_name']);}else if(b.item_name==='sys_lookup_lists')b.set_view_fields(['f_name']);if(a===c.f_object){if(c.owner===c.task.sys_items)if(c.owner.type_id.value===c.task.item_types.TASK_TYPE)b.filters.task_id.value=c.owner.id.value;else b.filters.task_id.value=c.owner.task_id.value;b.set_order_by(['f_item_name']);b.filters.type_id.value=[c.task.item_types.ITEM_TYPE,c.task.item_types.TABLE_TYPE];b.filters.table_id.value=0;}else if(a.field_name==='f_master_field'&&c.f_object.value){e=c.owner.id.value;f=c.task.sys_items.field_by_id(e,'parent');if(f){b.filters.owner_rec_id.value=[f];b.filters.not_id.value=c.id.value;b.filters.object.value=c.f_object.value;b.filters.master_field_is_null.value=true;}else b.filters.owner_rec_id.value=[-1];b.set_fields(['id','f_name','f_field_name','f_db_field_name']);b.on_after_open=function(a){var b=c.clone();a.first();b.each(function(b){if(b.id.value!==c.id.value&&b.f_object.value===c.f_object.value&&!b.f_master_field.value){a.append();a.id.value=b.id.value;a.f_field_name.value=b.f_field_name.value;a.f_db_field_name.value=b.f_db_field_name.value;a.f_name.value=b.f_name.value;a.post();}});a.first();};}if(a.field_name==='f_object_field')if(c.f_object.value){e=c.f_object.value;f=c.task.sys_items.field_by_id(e,'parent');b.filters.owner_rec_id.value=[e,f];b.filters.master_field_is_null.value=true;b.set_order_by(['f_field_name']);}else b.filters.owner_rec_id.value=[-1];if(a.field_name==='f_object_field1'){d=c.task.sys_fields.copy();d.set_where({id:c.f_object_field.value});d.open();if(d.f_object.value){e=d.f_object.value;f=d.task.sys_items.field_by_id(e,'parent');b.filters.owner_rec_id.value=[e,f];b.filters.master_field_is_null.value=true;b.set_order_by(['f_field_name']);}else b.filters.owner_rec_id.value=[-1];}if(a.field_name==='f_object_field2'){d=c.task.sys_fields.copy();d.set_where({id:c.f_object_field1.value});d.open();if(d.f_object.value){e=d.f_object.value;f=d.task.sys_items.field_by_id(e,'parent');b.filters.owner_rec_id.value=[e,f];b.filters.master_field_is_null.value=true;b.set_order_by(['f_field_name']);}else b.filters.owner_rec_id.value=[-1];}}function h(a,b){var c='',d,e,f;if(!a.owner.valid_identifier(b))c=a.task.language.invalid_field_name;d=a.clone();d.each(function(d){if(a.rec_no!==d.rec_no&&b===d.f_field_name.value){c='There is a field with this name';return false;}});if(!c){f=new a.task.constructors.item();if(f[b]!==undefined)c=a.task.language.reserved_word;}if(!c){}return c;}function i(a){var b=a.owner,c='';if(a.field_name==='f_field_name'){c=h(b,a.value);if(c)return c;}else if(a.field_name==='f_object'){if(b.f_data_type.value===b.task.consts.KEYS&&!a.value)return 'For keys field a lookup item must be set';}else if(a.field_name==='f_object_field'){if(b.f_object.value&&!a.value)return b.task.language.object_field_required;}else if(a.field_name==='f_data_type'){if(b.f_data_type.value===0)return b.task.language.type_is_required;}else if(a.field_name==='f_size'&&b.f_data_type.value===b.task.consts.TEXT&&!a.value)return b.task.language.size_is_required;}function j(a,b){var c=a.owner,d,e,g;if(!c._field_changing){c._field_changing=true;try{if(a.field_name==='f_name')if(c.f_field_name){if(!c.f_field_name.value)try{g=a.text.split(' ').join('_').toLowerCase();if(c.owner.valid_identifier(g))c.f_field_name.value=g;}catch(h){}}else if(c.f_param_name)if(!c.f_param_name.value)try{g=a.text.split(' ').join('_').toLowerCase();if(c.task.sys_items.valid_identifier(g))c.f_param_name.value=g;}catch(h){}if((a.field_name==='f_field_name'||a.field_name==='f_name')&&(!c.task._manual_update||f(c)))if(c.f_field_name&&c.f_field_name.value)c.f_db_field_name.value=c.task.server('server_set_literal_case',c.f_field_name.value);if(a.field_name==='f_object'){c.f_object_field.value=null;c.f_object_field1.value=null;c.f_object_field2.value=null;c.f_lookup_values.value=null;c.f_master_field.value=null;if(c.f_object.value){e=c.task.server('server_get_primary_key_type',a.value);if(c.f_data_type.value===c.task.consts.KEYS)c.f_object_field.set_value(e.field_id,e.field_name);else{c.f_data_type.value=e.data_type;c.f_size.value=e.size;}}}else if(a.field_name==='f_object_field'){c.f_object_field1.value=null;c.f_object_field2.value=null;}else if(a.field_name==='f_object_field1')c.f_object_field2.value=null;else if(a.field_name==='f_lookup_values'){c.f_object.value=null;c.f_object_field.value=null;c.f_master_field.value=null;if(c.f_lookup_values.value)c.f_data_type.value=c.task.consts.INTEGER;}else if(a===c.f_data_type)if(c.f_data_type.value===c.task.consts.TEXT)c.f_size.value=100;else c.f_size.value=null;if(a===c.f_data_type||a===c.f_object||a===c.f_lookup_values)c.f_alignment.value=m(c);k(c);}finally{c._field_changing=false;}}}function k(a){if(!f(a)&&!a.owner.f_virtual_table.value&&!a.task._manual_update){a.f_data_type.read_only=!a.task.db_options.CAN_CHANGE_TYPE;a.f_size.read_only=true;if(a.f_data_type.value===a.task.consts.TEXT){a.f_size.read_only=!a.task.db_options.CAN_CHANGE_SIZE;if(a.f_object.value||a.owner.f_primary_key.value===a.id.value)a.f_size.read_only=true;}a.f_lookup_values.read_only=true;a.f_object.read_only=true;a.f_multi_select.read_only=false;a.f_object_field.read_only=!a.f_object.value;a.f_master_field.read_only=!a.f_object.value;a.f_object_field1.read_only=!a.f_object_field.value;a.f_object_field2.read_only=!a.f_object_field1.value;a.f_enable_typehead.read_only=!(a.f_object.value&&!a.f_master_field.value);a.f_default_value.read_only=a.f_master_field.value;}else{if(a.f_data_type.value)if(a.f_object.value||a.f_lookup_values.value)a.f_data_type.read_only=true;else a.f_data_type.read_only=false;else a.f_data_type.read_only=false;if(a.f_data_type.value===a.task.consts.TEXT&&!a.f_object.value)a.f_size.read_only=false;else a.f_size.read_only=true;l(a);}}function l(a,b){a.f_object.read_only=false;a.f_lookup_values.read_only=a.f_object.value;a.f_object.read_only=a.f_lookup_values.value;a.f_object_field.read_only=!a.f_object.value;a.f_object_field1.read_only=!a.f_object_field.value;a.f_object_field2.read_only=!a.f_object_field1.value;a.f_master_field.read_only=!a.f_object_field.value;a.f_multi_select.read_only=true;a.f_enable_typehead.read_only=true;if(a.f_object.value&&!a.f_master_field.value){a.f_multi_select.read_only=false;a.f_enable_typehead.read_only=false;}if(a.f_enable_typehead.value)a.f_multi_select.read_only=true;if(a.f_multi_select.value)a.f_enable_typehead.read_only=true;a.f_multi_select_all.read_only=!a.f_multi_select.value;if(a.is_changing()){if(a.f_multi_select.read_only){a.f_multi_select.value=null;a.f_multi_select_all.value=null;}if(!a.f_multi_select.value)a.f_multi_select_all.value=null;if(a.f_enable_typehead.read_only)a.f_enable_typehead.value=null;}if(a.f_data_type.value===a.task.consts.KEYS&&a.f_object.value){a.f_object_field.read_only=true;a.f_object_field1.read_only=true;a.f_object_field2.read_only=true;a.f_master_field.read_only=true;a.f_multi_select.read_only=true;a.f_lookup_values.read_only=true;a.f_enable_typehead.read_only=false;}}function m(a){var b=a.f_data_type.value,c;if(b===a.task.consts.INTEGER||b===a.task.consts.FLOAT||b===a.task.consts.CURRENCY)c=a.task.consts.ALIGN_RIGHT;else if(b===a.task.consts.DATE||b===a.task.consts.DATETIME)c=a.task.consts.ALIGN_CENTER;else c=a.task.consts.ALIGN_LEFT;if(a.f_object.value||a.f_lookup_values.value)c=a.task.consts.ALIGN_LEFT;return c;}function n(a){var c,d;if(a.f_object.value){d=a.clone();d.each(function(d){if(d.f_object.value===a.f_object.value&&d.f_master_field.value===a.id.value){c=a.format_string(b.language.cant_delete_master_field,{field1:a.f_field_name.value,field2:d.f_field_name.value});return false;}});}if(!c&&!f(a))c=a.task.sys_fields.server('server_can_delete_field',[a.id.value]);return c;}function o(a){a.f_data_type.read_only=false;}function p(a){if(a.id.value===a.owner.f_primary_key.value)a.owner.f_primary_key.value=null;else if(a.id.value===a.owner.f_deleted_flag.value)a.owner.f_deleted_flag.value=null;else if(a.id.value===a.owner.f_master_id.value)a.owner.f_master_id.value=null;else if(a.id.value===a.owner.f_master_rec_id.value)a.owner.f_master_rec_id.value=null;}function q(a){if(a.f_data_type.value!==a.task.consts.TEXT)a.f_size.value=null;a.task_id.value=a.task.item_tree.task_id.value;if(!a.id.value)a.id.value=a.task.server('get_fields_next_id');}function r(a){}function s(a){if(a.field_name==='f_size'&&a.value===0)return '';}function t(a,b){if(b.keyCode===13&&b.ctrlKey===true){b.preventDefault();a.edit_form.find("#ok-btn").focus();a.apply_record();}}this.on_edit_form_created=c;this.on_edit_form_shown=d;this.on_after_open=e;this.new_field=f;this.on_field_select_value=g;this.check_valid_field_name=h;this.on_field_validate=i;this.on_field_changed=j;this.update_fields_read_only=k;this.update_lookup_attr=l;this.get_alignment=m;this.can_delete=n;this.on_after_append=o;this.on_before_delete=p;this.on_before_post=q;this.on_before_edit=r;this.on_field_get_text=s;this.on_edit_form_keydown=t;}b.events.events6=new t();function u(){function a(a){a.view_options.width=900;}function b(a,b){var c=a.owner;c.post();c.owner.post();if(c.id.value)c.record_status=c.task.consts.RECORD_MODIFIED;else c.record_status=c.task.consts.RECORD_INSERTED;c.owner.apply();c.owner.edit();}this.on_view_form_created=a;this.on_field_changed=b;}b.events.events8=new u();})(jQuery,task);