@@ -147,6 +147,9 @@ function Events1() { // demo
147
147
}
148
148
149
149
function on_edit_form_created ( item ) {
150
+
151
+ task . lock_record ( item ) ;
152
+
150
153
item . edit_options . inputs_container_class = 'edit-body' ;
151
154
item . edit_options . detail_container_class = 'edit-detail' ;
152
155
@@ -278,6 +281,65 @@ function Events1() { // demo
278
281
item . view_form . find ( "#report-btn" ) . hide ( ) ;
279
282
}
280
283
}
284
+
285
+ function lock_record ( item , repeated ) {
286
+ if ( ! item . master && item . is_edited ( ) && task . user_info . user_id ) {
287
+ var item = item ,
288
+ locks = task . record_locks . copy ( ) ,
289
+ on_before_apply = item . on_before_apply ,
290
+ on_edit_form_closed = item . on_edit_form_closed ;
291
+
292
+ locks . set_where ( { item_id : item . ID , item_rec_id : item . id . value } ) ;
293
+ locks . open ( ) ;
294
+ if ( locks . rec_count ) {
295
+ locks . edit ( )
296
+ }
297
+ else {
298
+ locks . append ( ) ;
299
+ }
300
+ locks . item_id . value = item . ID ;
301
+ locks . item_rec_id . value = item . id . value ;
302
+ locks . user_id . value = task . user_info . user_id ;
303
+ locks . user_name . value = task . user_info . user_name ;
304
+ locks . lock_date . value = new Date ( ) ;
305
+ locks . post ( ) ;
306
+ locks . apply ( ) ;
307
+
308
+ if ( ! repeated ) {
309
+ item . on_before_apply = function ( locked_item ) {
310
+ var mess ;
311
+ locks . set_where ( { item_id : locked_item . ID , item_rec_id : locked_item . id . value } ) ;
312
+ locks . open ( ) ;
313
+ if ( locks . user_id . value !== task . user_info . user_id ) {
314
+ mess = 'Saving is prohibited. The record is edited by the user ' +
315
+ locks . user_name . value + '.'
316
+ item . question ( mess + ' Continue editing?' ,
317
+ function ( ) {
318
+ locked_item . _applying = false ;
319
+ if ( ! locked_item . is_edited ( ) ) {
320
+ locked_item . edit ( ) ;
321
+ }
322
+ lock_record ( locked_item , true ) ;
323
+ } ,
324
+ function ( ) {
325
+ item . cancel_edit ( ) ;
326
+ }
327
+ ) ;
328
+ throw mess ;
329
+ }
330
+ } ;
331
+
332
+ item . on_edit_form_closed = function ( locked_item ) {
333
+ if ( on_before_apply ) {
334
+ locked_item . on_before_apply = on_before_apply ;
335
+ }
336
+ if ( on_edit_form_closed ) {
337
+ on_edit_form_closed ( locked_item ) ;
338
+ }
339
+ }
340
+ } ;
341
+ }
342
+ }
281
343
this . on_page_loaded = on_page_loaded ;
282
344
this . on_view_form_created = on_view_form_created ;
283
345
this . on_view_form_shown = on_view_form_shown ;
@@ -290,6 +352,7 @@ function Events1() { // demo
290
352
this . on_view_form_keyup = on_view_form_keyup ;
291
353
this . on_edit_form_keyup = on_edit_form_keyup ;
292
354
this . create_print_btns = create_print_btns ;
355
+ this . lock_record = lock_record ;
293
356
}
294
357
295
358
task . events . events1 = new Events1 ( ) ;
@@ -321,9 +384,16 @@ function Events10() { // demo.catalogs.customers
321
384
task . customers_report . customers . value = item . selections ;
322
385
task . customers_report . print ( false ) ;
323
386
}
387
+
388
+ function on_edit_form_created ( item ) {
389
+ if ( task . user_info . user_id === 1 ) {
390
+ item . photo . read_only = false ;
391
+ }
392
+ }
324
393
this . on_view_form_created = on_view_form_created ;
325
394
this . send_email = send_email ;
326
395
this . print = print ;
396
+ this . on_edit_form_created = on_edit_form_created ;
327
397
}
328
398
329
399
task . events . events10 = new Events10 ( ) ;
@@ -466,7 +536,6 @@ function Events16() { // demo.journals.invoices
466
536
} ) ;
467
537
}
468
538
469
-
470
539
// function on_edit_form_created(item) {
471
540
// item.read_only = item.id.value % 2 === 1;
472
541
// }
@@ -505,11 +574,18 @@ function Events16() { // demo.journals.invoices
505
574
// // item.view_form.find("#edit-btn").prop("disabled", !item.view_options.can_edit);
506
575
// }
507
576
// }
577
+
578
+
579
+
580
+ function on_before_apply ( item ) {
581
+
582
+ }
508
583
this . on_field_get_text = on_field_get_text ;
509
584
this . on_field_get_html = on_field_get_html ;
510
585
this . on_field_changed = on_field_changed ;
511
586
this . on_detail_changed = on_detail_changed ;
512
587
this . on_before_post = on_before_post ;
588
+ this . on_before_apply = on_before_apply ;
513
589
}
514
590
515
591
task . events . events16 = new Events16 ( ) ;
0 commit comments