1(function() 2{ 3 'use strict'; 4 $.ETC = $.ETC || {}; 5 if ($.ETC.SetterBuilder) return; 6 7 $.ETC.SetterBuilder = _build; 8 9 /* 10 ÐоÑÑÑоение ÑÑнкÑий ÑаÑкладки даннÑÑ Ð¸Ð· JSON 11 ÐозвÑаÑÐ°ÐµÑ Ð¾Ð±ÑÐµÐºÑ Ð´Ð»Ñ ÑÑÑановки знаÑений 12 13 Ñиповой пÑÐ¸Ð¼ÐµÑ JSON: 14 { 15 "Key" : "Model_Employee_Key", 16 "Version" : "Model_Employee_Version", 17 "DisplayText": 18 [ 19 "Model_Employee_DisplayText", 20 "Model_Employee_DisplayText_lookup.lookuptext" 21 ] 22 } 23 24 prepModel - ÑÑнкÑиÑ, вÑзÑÐ²Ð°ÐµÐ¼Ð°Ñ Ð¿ÐµÑед вÑзовом пеÑвого setterа Ð´Ð»Ñ Ð¿ÑедваÑиÑелÑной обÑабоÑки модели. 25 */ 26 function _build(targets, container, prepModel) 27 { 28 var setters = []; 29 if (prepModel) 30 setters.push(typeof(prepModel)==='string'?new Function('m', prepModel):prepModel); 31 32 if (targets) 33 { 34 var target; 35 for (var t in targets) 36 { 37 if ($.isArray(targets[t])) 38 { 39 // бÑдем клаÑÑÑ Ð¾Ð´Ð½Ð¾ знаÑение в неÑколÑко полей 40 for (var v in targets[t]) 41 { 42 v = targets[t][v]; 43 if (!v || typeof(v)!=='string') continue; 44 45 target = v.split('.'); // ÐеÑем ÑÐ»ÐµÐ¼ÐµÐ½Ñ Ð¸ пÑÑаемÑÑ Ð¾ÑделиÑÑ ID Ð¾Ñ Ð¼ÐµÑода 46 _addsetter(setters, t, target, container); 47 } 48 } else 49 { 50 //одно знаÑение - одно поле 51 target = targets[t].split('.'); // ÐеÑем ÑÐ»ÐµÐ¼ÐµÐ½Ñ Ð¸ пÑÑаемÑÑ Ð¾ÑделиÑÑ ID Ð¾Ñ Ð¼ÐµÑода 52 _addsetter(setters, t, target, container); 53 } 54 } 55 } 56 57 if(setters.length>0) 58 { 59 return function(val, changeIfEmpty) 60 { 61 var sval = val || {}, 62 cie = changeIfEmpty && true; 63 64 //заполнÑем Ð¿Ð¾Ð»Ñ 65 for (var i = 0; i < setters.length; i++) 66 { 67 setters[i](sval, cie); 68 } 69 }; 70 } else 71 { 72 return function(){/* do nothing */}; 73 } 74 } 75 76 // ÐополниÑелÑнÑе меÑÐ¾Ð´Ñ Ð´Ð»Ñ ÑпÑÐ°Ð²Ð»ÐµÐ½Ð¸Ñ Ð´Ð°Ð½Ð½Ñми из data-targets 77 var _customMethods = 78 { 79 'class': function(val) 80 { 81 if (val === undefined) 82 return this.attr('class'); 83 else 84 this.attr('class', val); 85 }, 86 'checked': function(val) 87 { 88 if (val === undefined) 89 return this.attr('checked')=='checked'; 90 //else 91 // this.attr('checked', val ? 'checked' : '' ); 92 else if (val == true) 93 this.attr('checked', 'checked'); 94 else 95 this.attr('checked', false); 96 } 97 }; 98 99 // ÐоиÑк ÑлеменÑа и 100 // Ñоздание ÑÑнкÑии ÑаÑкладки даннÑÑ Ð¸Ð· Ð¿Ð¾Ð»Ñ id в ÑÐ»ÐµÐ¼ÐµÐ½Ñ el Ñ Ð¿Ð¾Ð¼Ð¾ÑÑÑ Ð¼ÐµÑода method 101 function _addsetter(setters, t, target, container) 102 { 103 var el = (container==null || container.length==0)?$(document.getElementById(target[0])):$('#'+target[0], container); // ÐÑем ÑÐ»ÐµÐ¼ÐµÐ½Ñ Ð¿Ð¾ докÑменÑÑ 104 if(el.length==0) 105 return; 106 107 var method = target[1] || 'val'; // ÐеÑем меÑод, по-ÑмолÑÐ½Ð¸Ñ ÑÑо val 108 var cm = _customMethods[method]; 109 if(cm!=null) 110 el[method] = cm; 111 112 var valFx; 113 if (t.indexOf('.')>0) 114 { 115 t = t.split('.'); 116 valFx = function(val) 117 { 118 for (var i=0; i<t.length; i++) 119 { 120 val = val[t[i]]; 121 if (val==null) break; 122 } 123 return val; 124 }; 125 } else 126 { 127 valFx = function(val) 128 { 129 return val[t]; 130 }; 131 } 132 133 setters.push(function (val, changeIfEmpty) // Создаем ÑÑнкÑÐ¸Ñ ÑаÑкладки 134 { 135 var v = valFx(val); 136 if (v===0 || v===false || v==='') 137 el[method](v); 138 else if (v || changeIfEmpty) 139 el[method](v || ''); 140 141 el.trigger('change'); // TODO: ÐÐÐÐ ÐÐЯ СÐÐÐÐСТÐÐÐСТÐ! иниÑииÑÑем ÑобÑÑие на ÑлеменÑе во избежание невÑÐ¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ ÑкÑипÑов на нем 142 }); 143 } 144})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.