Class: WidgetList::Administration
Instance Method Summary collapse
- #add_conditional(key, conditional) ⇒ Object
- #add_pointer(key, subtract = 0) ⇒ Object
- #ajax_get_field_json(model_name) ⇒ Object
- #build_field_options(fields, selected = '') ⇒ Object
- #config_id ⇒ Object
- #escape_code(code) ⇒ Object
- #get_configuration ⇒ Object
- #normalize_configs(page_config) ⇒ Object
- #remove_field_button ⇒ Object
- #save_and_show_code ⇒ Object
- #show_interface ⇒ Object
- #translate_config_to_code ⇒ Object
Instance Method Details
#add_conditional(key, conditional) ⇒ Object
367 368 369 370 |
# File 'lib/widget_list.rb', line 367 def add_conditional(key,conditional) whitespace = 19 "'#{escape_code key}' " + "".ljust(whitespace - key.length) + " #{conditional}" end |
#add_pointer(key, subtract = 0) ⇒ Object
362 363 364 365 |
# File 'lib/widget_list.rb', line 362 def add_pointer(key,subtract=0) whitespace = 31 - subtract "['#{key}'] " + "".ljust(whitespace - key.length) + " = " end |
#ajax_get_field_json(model_name) ⇒ Object
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 |
# File 'lib/widget_list.rb', line 1019 def ajax_get_field_json(model_name) config_id, page_config = get_configuration() ac = ActionController::Base.new() @response = {} fields = {} flags = {} misc = {} fields_hidden = {} all_fields = {} fields_function = {} = {} = {} group_by = {} drill_downs = {} if @isEditing model = page_config['view'].constantize.new model.attributes.keys.each { |field| all_fields[field] = field.gsub(/_/,' _').camelize } fields,fields_hidden,fields_function,,,group_by,drill_downs,flags,misc = normalize_configs(page_config) else controller = ($_REQUEST.key?('desiredController') ? $_REQUEST['desiredController'] : $_REQUEST['controller'] ) if $_REQUEST.key?('ajax') model = model_name.constantize model.columns.each { |field| fields[field.name] = field.name.gsub(/_/,' _').camelize all_fields[field.name] = field.name.gsub(/_/,' _').camelize fields_function[field.name] = 'CNT(' + field.name + ') or NVL(' + field.name + ') or TO_DATE(' + field.name + ') etc...' } ['Add New ' + model_name] = {} ['Add New ' + model_name]['url'] = '/' + controller + '/add/' ['Add New ' + model_name]['class'] = 'info' end ['Edit'] = {} ['Delete'] = {} ['Delete']['class'] = 'danger' ['Delete']['url'] = '/' + controller + '/delete/id/' ['Edit']['url'] = '/' + controller + '/edit/id/' ['Edit']['class'] = 'info' if $_REQUEST.key?('ajax') group_by[''] = 'All ' + model_name + 's' group_by['field_name'] = 'This will group by field_name and show Count' ['Delete']['url'] = '/' + controller + '/delete/' + fields.keys.first + '/' ['Edit']['url'] = '/' + controller + '/edit/' + fields.keys.first + '/' end end @response['fields'] = '' @response['fields_hidden'] = '' @response['fields_function'] = '' @response['buttons'] = '' @response['group_by'] = '' @response['footer_buttons'] = '' @response['drill_downs'] = '' fields.each { |field,description| @fieldFill = {} @fieldFill['<!--SUBJECT-->'] = 'fields' @fieldFill['<!--FIELD_VALUE-->'] = field @fieldFill['<!--FIELD_DESC-->'] = description @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () + WidgetList::Widgets::('Hide', {'onclick' => "MoveField(this)", 'innerClass' => "danger" }, true ) + WidgetList::Widgets::('Function', {'onclick' => "AddFunction(this)", 'innerClass' => "success" }, true ) + WidgetList::Widgets::('Options', {'onclick' => "ShowOptions(this)", 'innerClass' => "info" }, true ) @fieldFill['<!--FIELD-->'] = 'Field' @fieldFill['<!--DESC-->'] = 'Desc' @fieldFill['<!--DISABLED-->'] = '' @fieldFill['<!--TR_STYLE-->'] = '' if misc.key?('width') && misc['width'].key?(field) && !misc['width'][field].nil? width = misc['width'][field] else width = '' end if misc.key?('link') && misc['link'].key?(field) && !misc['link'][field].nil? link = misc['link'][field] else link = '' end if misc.key?('title') && misc['title'].key?(field) && !misc['title'][field].nil? title = misc['title'][field] else title = '' end @fieldFillRow2 = {} @fieldFillRow2['<!--REMOVE_FIELD_BUTTON-->'] = 'Link To: <br/><br/><input type="text" style="width:350px" class="misc_links" onblur="jQuery(this).attr(\'value\',jQuery(this).val().trim());" name="misc[link][]" id="misc[link][]" value="' + link + '"/>' + WidgetList::Widgets::('?', {'onclick' => "alert('Please use /my_page/field_name/field_name/ and it will be linked and replaced with the column value.')", 'innerClass' => "default" }, true ) @fieldFillRow2['<!--FIELD_VALUE-->'] = width @fieldFillRow2['<!--FIELD_DESC-->'] = title @fieldFillRow2['<!--SUBJECT-->'] = 'misc' @fieldFillRow2['<!--FIELD-->'] = 'Column Width<br/><br/>' @fieldFillRow2['<!--DESC-->'] = 'Header Title Popup<br/><br/>' @fieldFillRow2['<!--DISABLED-->'] = '' @fieldFillRow2['<!--TR_STYLE-->'] = (link.empty? && title.empty? && width.empty?) ? 'display:none' : '' @fieldFillRow2['<!--TR1_STYLE-->'] = 'padding-left:100px' @fieldFill['<!--EXTRA-->'] = WidgetList::Utils::fill(@fieldFillRow2 , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) if flags.key?('searchable') && flags['searchable'].key?(field) && !flags['searchable'][field].nil? searchable = flags['searchable'][field] else searchable = (!@isEditing) ? 'checked' : '' end if flags.key?('summarize') && flags['summarize'].key?(field) && !flags['summarize'][field].nil? summarize = flags['summarize'][field] else summarize = '' end if flags.key?('sortable') && flags['sortable'].key?(field) && !flags['sortable'][field].nil? sortable = flags['sortable'][field] else sortable = (!@isEditing) ? 'checked' : '' end @fieldFillRow3 = {} @fieldFillRow3['<!--1_DESC-->'] = 'Searchable?<br/><br/>' @fieldFillRow3['<!--1_KEY-->'] = 'searchable' @fieldFillRow3['<!--1_VALUE-->'] = searchable @fieldFillRow3['<!--2_DESC-->'] = 'Summarize Totals?<br/><br/>' @fieldFillRow3['<!--2_KEY-->'] = 'summarize' @fieldFillRow3['<!--2_HELP-->'] = 'If this is a numeric column, the widget_list will add a record at the bottom of all your results adding up every value' @fieldFillRow3['<!--2_VALUE-->'] = summarize @fieldFillRow3['<!--3_DESC-->'] = 'Sortable?' @fieldFillRow3['<!--3_KEY-->'] = 'sortable' @fieldFillRow3['<!--3_VALUE-->'] = sortable @fieldFillRow3['<!--SUBJECT-->'] = 'flags' @fieldFillRow3['<!--CHECKBOX_STYLE-->'] = ((@isEditing && searchable == 'checked' && summarize.empty? && sortable == 'checked') || !@isEditing) ? 'display:none' : '' @fieldFill['<!--EXTRA-->'] += WidgetList::Utils::fill(@fieldFillRow3 , ac.render_to_string(:partial => 'widget_list/administration/checkbox_row') ) @response['fields'] += WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) } fields_hidden.each { |field| @fieldFill = {} @fieldFill['<!--SUBJECT-->'] = 'fields_hidden' @fieldFill['<!--FIELD_VALUE-->'] = field[1] @fieldFill['<!--FIELD_DESC-->'] = '' @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = ()+ WidgetList::Widgets::('Show', {'onclick' => "ShowField(this)", 'innerClass' => "success" }, true ) @fieldFill['<!--DESC-->'] = 'Desc' @fieldFill['<!--FIELD-->'] = 'Field' @fieldFill['<!--DISABLED-->'] = 'disabled' @fieldFill['<!--TR_STYLE-->'] = '' @response['fields_hidden'] += WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) } group_by.each { |field,description| @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--FIELD_VALUE-->'] = field @fieldFill['<!--FIELD_DESC-->'] = description @fieldFill['<!--SUBJECT-->'] = 'group_by' @fieldFill['<!--FIELD-->'] = 'Field' @fieldFill['<!--DESC-->'] = 'Desc' @fieldFill['<!--DISABLED-->'] = '' @fieldFill['<!--ONBLUR1-->'] = 'InvalidField(this)' @fieldFill['<!--TR_STYLE-->'] = '' @response['group_by'] += WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) } fields_function.each { |field,description| @fieldFill = {} @fieldFill['<!--SUBJECT-->'] = 'fields_function' @fieldFill['<!--FIELD_VALUE-->'] = field @fieldFill['<!--FIELD_DESC-->'] = description @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--DESC-->'] = 'Database Function' @fieldFill['<!--FIELD-->'] = 'Field' @fieldFill['<!--DISABLED-->'] = '' @fieldFill['<!--TR_STYLE-->'] = '' @response['fields_function'] += WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) } .each { |field| @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--BUTTON_TEXT-->'] = field[0] @fieldFill['<!--BUTTON_URL-->'] = field[1]['url'] @fieldFill['<!--BUTTON_CLASS-->'] = field[1]['class'] @fieldFill['<!--ONBLUR3-->'] = 'GoodClass(this)' @fieldFill['<!--TEXT_DESC-->'] = 'Text' @fieldFill['<!--TEXT_KEY-->'] = 'text' @fieldFill['<!--TEXT_HELP-->'] = 'The Button Text' @fieldFill['<!--URL_DESC-->'] = 'URL' @fieldFill['<!--URL_KEY-->'] = 'url' @fieldFill['<!--URL_HELP->'] = 'URLs include a RESTful path where you will pass controller/field_name/field_name/ where those will be replaced' @fieldFill['<!--COLOR_DESC-->'] = 'Color' @fieldFill['<!--COLOR_KEY-->'] = 'class' @fieldFill['<!--COLOR_HELP-->'] = 'primary=(blue) info=(light-blue) success=(green) danger=(red) disabled=(light grey) default=(grey)' @fieldFill['<!--SUBJECT-->'] = 'buttons' @response['buttons'] += WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/button_row') ) } drill_downs.each { |field| @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--BUTTON_TEXT-->'] = field[0] @fieldFill['<!--BUTTON_URL-->'] = field[1]['data_to_pass_from_view'] @fieldFill['<!--BUTTON_CLASS-->'] = field[1]['column_to_show'] @fieldFill['<!--ONBLUR2-->'] = 'ReplaceColumnsToLinked(this)' @fieldFill['<!--ONBLUR3-->'] = 'ReplaceColumnsToLinked(this)' @fieldFill['<!--TEXT_DESC-->'] = 'Internal Filter Name (:drill_down_name)<br/>' @fieldFill['<!--TEXT_KEY-->'] = 'drill_down_name' @fieldFill['<!--TEXT_HELP-->'] = ':drill_down_name is a parameter of build_drill_down that is what is passed and returned from get_filter_and_drilldown when you handle the request after clicked' @fieldFill['<!--URL_DESC-->'] = 'Data To Pass From View (:data_to_pass_from_view)<br/>' @fieldFill['<!--URL_KEY-->'] = 'data_to_pass_from_view' @fieldFill['<!--URL_HELP->'] = ':data_to_pass_from_view is the internal/hidden value that is inserted into a hidden <script> id block and passed when clicked' @fieldFill['<!--COLOR_DESC-->'] = 'Column to Show (:column_to_show)<br/>' @fieldFill['<!--COLOR_KEY-->'] = 'column_to_show' @fieldFill['<!--COLOR_HELP-->'] = ':column_to_show should either be the column or possibly a formatted column like CONCAT or COUNT' @fieldFill['<!--SUBJECT-->'] = 'drill_downs' @response['drill_downs'] += WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/button_row') ) } .each { |field| @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--BUTTON_TEXT-->'] = field[0] @fieldFill['<!--BUTTON_URL-->'] = field[1]['url'] @fieldFill['<!--BUTTON_CLASS-->'] = field[1]['class'] @fieldFill['<!--ONBLUR3-->'] = 'GoodClass(this)' @fieldFill['<!--TEXT_DESC-->'] = 'Text' @fieldFill['<!--TEXT_KEY-->'] = 'text' @fieldFill['<!--TEXT_HELP-->'] = 'The Button Text' @fieldFill['<!--URL_DESC-->'] = 'URL' @fieldFill['<!--URL_KEY-->'] = 'url' @fieldFill['<!--URL_HELP->'] = 'The URL' @fieldFill['<!--COLOR_DESC-->'] = 'Color' @fieldFill['<!--COLOR_KEY-->'] = 'class' @fieldFill['<!--COLOR_HELP-->'] = 'primary=(blue) info=(light-blue) success=(green) danger=(red) disabled=(light grey) default=(grey)' @fieldFill['<!--SUBJECT-->'] = 'footer_buttons' @response['footer_buttons'] += WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/button_row') ) } if $_REQUEST.key?('ajax') || @isEditing @response['all_fields'] = all_fields @response['checked_fields'] = (all_fields, page_config.key?('checkboxField') ? page_config['checkboxField'] : '') end return @response.to_json end |
#build_field_options(fields, selected = '') ⇒ Object
919 920 921 922 923 924 925 |
# File 'lib/widget_list.rb', line 919 def (fields,selected='') = '' fields.each { |field,description| += "<option value='#{field}' #{((selected == field) ? 'selected' : '')}>#{description}</option>" } return end |
#config_id ⇒ Object
1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 |
# File 'lib/widget_list.rb', line 1290 def config_id() config_id = '' if $_REQUEST.key?('restore') config_id = $_REQUEST['restore'] else config_id += $_REQUEST['controller'] if $_REQUEST.key?('controller') config_id += $_REQUEST['action'] if $_REQUEST.key?('action') config_id += '|' + $_REQUEST['desiredController'] if $_REQUEST.key?('desiredController') config_id += '-' + $_REQUEST['desiredAction'] if $_REQUEST.key?('desiredAction') end return config_id end |
#escape_code(code) ⇒ Object
372 373 374 375 376 377 378 379 |
# File 'lib/widget_list.rb', line 372 def escape_code(code) if $_REQUEST.key?('iframe') #It is so weird, during output return, you need an extra slash to populate the code properly, but during rendering this is needed code.gsub(/'/,"\\\\'") else code.gsub(/'/,"\\\\\\\\'") end end |
#get_configuration ⇒ Object
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 |
# File 'lib/widget_list.rb', line 883 def get_configuration() config_id = config_id() @isEditing = false config_file = Rails.root.join("config", "widget-list-administration.json") config_file_all = Rails.root.join("config", "widget-list-administration-all.json") if config_file.file? && ($_REQUEST.key?('iframe') || $_REQUEST.key?('name')) configuration = JSON.parse(File.new(Rails.root.join("config", "widget-list-administration.json")).read) elsif $_REQUEST.key?('restore') configuration = JSON.parse(File.new(Rails.root.join("config", "widget-list-administration-all.json")).read) else configuration = {} end if configuration.key?(config_id) if config_file_all.file? configuration_all = JSON.parse(File.new(Rails.root.join("config", "widget-list-administration-all.json")).read) if configuration_all.key?(config_id) @isEditing = true end end page_config = configuration[config_id] ['useSort','showHidden','fieldFunctionOn','rowButtonsOn','drillDownsOn','showSearch','showExport','useRansack','ransackAdvancedForm','useGrouping','footerOn','checkboxEnabled'].each { |item| unless page_config.key?(item) page_config[item] = "0" end } else page_config = {} end return [config_id,page_config] end |
#normalize_configs(page_config) ⇒ Object
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
# File 'lib/widget_list.rb', line 927 def normalize_configs(page_config) fields = {} misc = {} misc['width'] = {} misc['title'] = {} misc['link'] = {} flags = {} flags['searchable']= {} flags['summarize'] = {} flags['sortable'] = {} fields_hidden = {} fields_function = {} = {} = {} group_by = {} drill_downs = {} if page_config.key?('fields') page_config['fields']['key'].each_with_index { |v,k| fields[v] = page_config['fields']['description'][k.to_i] if page_config.key?('misc') && page_config['misc'].key?('key') misc['width'][v] = page_config['misc']['key'][k.to_i] end if page_config.key?('misc') && page_config['misc'].key?('description') misc['title'][v] = page_config['misc']['description'][k.to_i] end if page_config.key?('misc') && page_config['misc'].key?('link') misc['link'][v] = page_config['misc']['link'][k.to_i] end if page_config.key?('flags') && page_config['flags'].key?('searchable') flags['searchable'][v] = page_config['flags']['searchable'][k.to_i] end if page_config.key?('flags') && page_config['flags'].key?('summarize') flags['summarize'][v] = page_config['flags']['summarize'][k.to_i] end if page_config.key?('flags') && page_config['flags'].key?('sortable') flags['sortable'][v] = page_config['flags']['sortable'][k.to_i] end } end if page_config.key?('fields_hidden') page_config['fields_hidden']['key'].each { |v| fields_hidden[v] = v } end if page_config.key?('fields_function') page_config['fields_function']['key'].each_with_index { |v,k| fields_function[v] = page_config['fields_function']['description'][k.to_i] } end if page_config.key?('group_by') page_config['group_by']['key'].each_with_index { |v,k| group_by[v] = page_config['group_by']['description'][k.to_i] } end if page_config.key?('buttons') page_config['buttons']['text'].each_with_index { |v,k| [v] = {} [v]['url'] = page_config['buttons']['url'][k.to_i] [v]['class'] = page_config['buttons']['class'][k.to_i] } end if page_config.key?('footer_buttons') page_config['footer_buttons']['text'].each_with_index { |v,k| [v] = {} [v]['url'] = page_config['footer_buttons']['url'][k.to_i] [v]['class'] = page_config['footer_buttons']['class'][k.to_i] } end if page_config.key?('drill_downs') page_config['drill_downs']['drill_down_name'].each_with_index { |v,k| drill_downs[v] = {} drill_downs[v]['data_to_pass_from_view'] = page_config['drill_downs']['data_to_pass_from_view'][k.to_i] drill_downs[v]['column_to_show'] = page_config['drill_downs']['column_to_show'][k.to_i] } end return [fields,fields_hidden,fields_function,,,group_by,drill_downs,flags,misc] end |
#remove_field_button ⇒ Object
1286 1287 1288 |
# File 'lib/widget_list.rb', line 1286 def () WidgetList::Widgets::('Remove', {'onclick' => "RemoveField(this)", 'innerClass' => "danger" }, true ) end |
#save_and_show_code ⇒ Object
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 |
# File 'lib/widget_list.rb', line 1303 def save_and_show_code() ac = ActionController::Base.new() config_id = config_id() config_file = Rails.root.join("config", "widget-list-administration.json") if config_file.file? configuration = JSON.parse(File.new(Rails.root.join("config", "widget-list-administration.json")).read) else configuration = {} end configuration[config_id] = $_REQUEST time = Time.new configuration[config_id]['savedOn'] = time.year.to_s + '-' + time.month.to_s.rjust(2, "0") + '-' + time.day.to_s.rjust(2, "0") File.open(Rails.root.join("config", "widget-list-administration.json"), "w") do |file| file.puts configuration.to_json end if !$_REQUEST.key?('iframe') && !$_REQUEST.key?('ajax') config_file_all = Rails.root.join("config", "widget-list-administration-all.json") if config_file_all.file? configuration_all = JSON.parse(File.new(Rails.root.join("config", "widget-list-administration-all.json")).read) else configuration_all = {} end configuration_all[config_id] = $_REQUEST configuration_all[config_id]['savedOn'] = time.year.to_s + '-' + time.month.to_s.rjust(2, "0") + '-' + time.day.to_s.rjust(2, "0") File.open(Rails.root.join("config", "widget-list-administration-all.json"), "w") do |file| file.puts configuration_all.to_json end end @fill = {} unless $_REQUEST.key?('ajax') @fill['<!--CODE-->'] = translate_config_to_code() end return WidgetList::Utils::fill(@fill ,ac.render_to_string(:partial => 'widget_list/administration/output_save') ) unless $_REQUEST.key?('ajax') return @fill.to_json end |
#show_interface ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/widget_list.rb', line 30 def show_interface() config_file = Rails.root.join("config", "widget-list-administration.json") config_file_all = Rails.root.join("config", "widget-list-administration-all.json") if config_file.file? && !$_REQUEST.key?('ajax') && !$_REQUEST.key?('name') File.delete(Rails.root.join("config", "widget-list-administration.json")) end ac = ActionController::Base.new() default_config = WidgetList::List::get_defaults() config_id, page_config = get_configuration() page_json = JSON.parse(ajax_get_field_json(page_config['view'])) #Loop models models = Dir[ Rails.root.join("app", "models").to_s + '**/*'].reject {|fn| File.directory?(fn) } if !models.empty? = '<option value="">Select a Model</option>' + models.collect { |model| model_name = model.split('/').last.to_s.camelize.gsub(/.rb/,'') "<option value='#{model_name}' #{((@isEditing && page_config['view'] == model_name) ? 'selected' : '')}>#{model_name}</option>" }.sort.uniq.join('') else = '<option value="">No Models Found in ' + Rails.root.join("app", "models").to_s + '</option>' end #Groupings #default_grouping : editing_grouping @fill = {} # # Writing most of this interface while drunk trancing/coding out on ah.fm. # This administration form should help people new to widget_list to easily stub out new implementations # # # INIT PROMPT # if config_file_all.file? && !$_REQUEST.key?('restore') @fill['<!--BUTTON_CSS-->'] = 'style="display:none"' @fill['<!--START_CSS-->'] = 'style="display:none"' = '' json = JSON.parse(File.new(Rails.root.join("config", "widget-list-administration-all.json")).read) json.keys.each { |val| void, controller_action = val.split('|') controller, action = controller_action.split('-') += '<option value="' + val + '">' + (json[val].key?('savedOn') ? "(on #{json[val]['savedOn']}) - " : '') + controller + '/' + action + ' => Model used is "' + json[val]['view'] + '"</option>' } @fill['<!--EDIT_OR_ADD_NEW-->'] = WidgetList::Utils::fill({ '<!--NEW-->' => WidgetList::Widgets::('New', { 'onclick' => "ClickTab('.start','ShowStart',true);jQuery('#sections').fadeIn('slow');" , 'innerClass' => "primary" } ), '<!--EDIT-->' => WidgetList::Widgets::('Edit', { 'onclick' => "isSubmitting = true; document.location = document.location + '?restore=' + escape(jQuery('#edit_widget_list').val());" , 'innerClass' => "primary" } ), '<!--ITEMS-->' => '<select name="edit_widget_list" id="edit_widget_list">' + + '</select>', } ,' <tr class="init"> <td> <h3>Start a New Widget List <!--NEW--></h3> </td> <td> <h3>Edit Existing: <!--ITEMS--> <!--EDIT--></h3> </td> <td>   </td> </tr>') else @fill['<!--BUTTON_CSS-->'] = '' @fill['<!--START_CSS-->'] = '' end # # BASE # @fill['<!--POST_URL-->'] = $_SERVER['SCRIPT_NAME'] + $_SERVER['PATH_INFO'] @fill['<!--BUTTONS-->'] = WidgetList::Widgets::('Step One - Start ->', {'id' => 'start' , 'onclick' => "ShowStart();" , 'innerClass' => "primary" } ) + WidgetList::Widgets::('Step Two - Fields ->', {'id' => 'fields' , 'onclick' => "ShowFields();" , 'innerClass' => "primary disabled" } ) + WidgetList::Widgets::('Step Three - Rows ->', {'id' => 'rows' , 'onclick' => "ShowRows();" , 'innerClass' => "primary disabled" } ) + WidgetList::Widgets::('Step Four - Search ->', {'id' => 'search' , 'onclick' => "ShowSearch();" , 'innerClass' => "primary disabled" } ) + WidgetList::Widgets::('Step Four - Footer Actions ->', {'id' => 'footer' , 'onclick' => "ShowFooter();" , 'innerClass' => "primary disabled" } ) + WidgetList::Widgets::('Step Five - Misc & Submit ->', {'id' => 'misc_submit', 'onclick' => "ShowSubmit();" , 'innerClass' => "success disabled" } ) # # START # @fill['<!--TITLE-->'] = 'Stub Out A New WidgetList Implementation' @fill['<!--CONTROLLER_VALUE-->'] = (!@isEditing) ? $_REQUEST['controller'] : page_config['desiredController'] @fill['<!--ACTION_VALUE-->'] = (!@isEditing) ? $_REQUEST['action'] : page_config['desiredAction'] @fill['<!--NAME_VALUE-->'] = (!@isEditing) ? config_id : page_config['name'] @fill['<!--VIEW_OPTIONS-->'] = @fill['<!--TITLE_VALUE-->'] = (!@isEditing) ? '' : page_config['title'] @fill['<!--DESC_VALUE-->'] = (!@isEditing) ? '' : page_config['listDescription'] @fill['<!--PRIMARY_CHECKED-->'] = (!@isEditing) ? 'checked' : (page_config['primaryDatabase'] == "1") ? 'checked' : '' # # FIELD LEVEL # @fill['<!--NO_DATA_VALUE-->'] = (!@isEditing) ? '' : page_config['noDataMessage'] @fill['<!--SORTING_CHECKED-->'] = (!@isEditing) ? 'checked' : (page_config['useSort'] == "1") ? 'checked' : '' @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () + WidgetList::Widgets::('Hide', {'onclick' => "MoveField(this)", 'innerClass' => "danger" }, true ) + WidgetList::Widgets::('Function', {'onclick' => "AddFunction(this)", 'innerClass' => "success" }, true ) + WidgetList::Widgets::('Options', {'onclick' => "ShowOptions(this)", 'innerClass' => "info" }, true ) @fieldFill['<!--FIELD_VALUE-->'] = '' @fieldFill['<!--FIELD_DESC-->'] = '' @fieldFill['<!--SUBJECT-->'] = 'fields' @fieldFill['<!--FIELD-->'] = 'Field' @fieldFill['<!--DESC-->'] = 'Desc' @fieldFill['<!--DISABLED-->'] = '' @fieldFill['<!--TR_STYLE-->'] = '' @fieldFillRow2 = {} @fieldFillRow2['<!--REMOVE_FIELD_BUTTON-->'] = 'Link To: <br/><br/><input type="text" style="width:350px" class="misc_links" onblur="jQuery(this).attr(\'value\',jQuery(this).val().trim());" name="misc[link][]" id="misc[link][]" value=""/>' + WidgetList::Widgets::('?', {'onclick' => "alert('Please use /my_page/field_name/field_name/ and it will be linked and replaced with the column value.')", 'innerClass' => "default" }, true ) @fieldFillRow2['<!--FIELD_VALUE-->'] = '' @fieldFillRow2['<!--FIELD_DESC-->'] = '' @fieldFillRow2['<!--SUBJECT-->'] = 'misc' @fieldFillRow2['<!--FIELD-->'] = 'Column Width<br/><br/>' @fieldFillRow2['<!--DESC-->'] = 'Header Title Popup<br/><br/>' @fieldFillRow2['<!--DISABLED-->'] = '' @fieldFillRow2['<!--TR_STYLE-->'] = 'display:none' @fieldFillRow2['<!--TR1_STYLE-->'] = 'padding-left:100px' @fieldFill['<!--EXTRA-->'] = WidgetList::Utils::fill(@fieldFillRow2 , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) @fieldFillRow3 = {} @fieldFillRow3['<!--1_DESC-->'] = 'Searchable?<br/><br/>' @fieldFillRow3['<!--1_KEY-->'] = 'searchable' @fieldFillRow3['<!--1_VALUE-->'] = 'checked' @fieldFillRow3['<!--2_DESC-->'] = 'Summarize Totals?<br/><br/>' @fieldFillRow3['<!--2_KEY-->'] = 'summarize' @fieldFillRow3['<!--2_HELP-->'] = 'If this is a numeric column, the widget_list will add a record at the bottom of all your results adding up every value' @fieldFillRow3['<!--2_VALUE-->'] = '' @fieldFillRow3['<!--3_DESC-->'] = 'Sortable?' @fieldFillRow3['<!--3_KEY-->'] = 'sortable' @fieldFillRow3['<!--3_VALUE-->'] = 'checked' @fieldFillRow3['<!--SUBJECT-->'] = 'flags' @fieldFillRow3['<!--CHECKBOX_STYLE-->'] = 'display:none;' @fieldFill['<!--EXTRA-->'] += WidgetList::Utils::fill(@fieldFillRow3 , ac.render_to_string(:partial => 'widget_list/administration/checkbox_row') ) #Fill all three rows now for default template @fill['<!--FIELD_TEMPLATE-->'] = WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) @fill['<!--ADD_FIELD_BUTTON-->'] = WidgetList::Widgets::('Add Field', {'onclick' => "AddField();", 'innerClass' => "success" } ) @fill['<!--ALL_FIELDS-->'] = (!@isEditing) ? '' : page_json['fields'] @fill['<!--SHOW_HIDDEN_CHECKED-->'] = (!@isEditing) ? '' : (page_config['showHidden'] == "1") ? 'checked' : '' @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () + WidgetList::Widgets::('Show', {'onclick' => "ShowField(this)", 'innerClass' => "success" }, true ) @fieldFill['<!--FIELD_VALUE-->'] = '' @fieldFill['<!--FIELD_DESC-->'] = '' @fieldFill['<!--SUBJECT-->'] = 'fields_hidden' @fieldFill['<!--FIELD-->'] = 'Field' @fieldFill['<!--DESC-->'] = 'Desc' @fieldFill['<!--DISABLED-->'] = 'disabled' @fieldFill['<!--TR_STYLE-->'] = '' @fill['<!--HIDDEN_FIELD_TEMPLATE-->'] = WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) @fill['<!--ADD_HIDDEN_FIELD_BUTTON-->'] = WidgetList::Widgets::('Add Hidden Field', {'onclick' => "AddHiddenField();", 'innerClass' => "success" } ) @fill['<!--ALL_HIDDEN_FIELDS-->'] = (!@isEditing) ? '' : page_json['fields_hidden'] @fill['<!--SHOW_FUNCTION_CHECKED-->'] = (!@isEditing) ? '' : (page_config['fieldFunctionOn'] == "1") ? 'checked' : '' @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--FIELD_VALUE-->'] = '' @fieldFill['<!--FIELD_DESC-->'] = '' @fieldFill['<!--SUBJECT-->'] = 'fields_function' @fieldFill['<!--FIELD-->'] = 'Field' @fieldFill['<!--DESC-->'] = 'Database Function' @fieldFill['<!--DISABLED-->'] = '' @fieldFill['<!--TR_STYLE-->'] = '' @fill['<!--FIELD_FUNCTION_TEMPLATE-->'] = WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) @fill['<!--ADD_FIELD_FUNCTION_BUTTON-->'] = WidgetList::Widgets::('Add Function', {'onclick' => "AddFieldFunction();", 'innerClass' => "success" } ) @fill['<!--ALL_FIELD_FUNCTIONS-->'] = (!@isEditing) ? '' : page_json['fields_function'] # # ROW LEVEL # @fill['<!--ROW_LIMIT_VALUE-->'] = (!@isEditing) ? default_config['rowLimit'] : page_config['rowLimit'] @fill['<!--BUTTON_NAME_VALUE-->'] = (!@isEditing) ? 'Actions' : page_config['rowButtonsName'] @fill['<!--BUTTONS_ON_CHECKED-->'] = (!@isEditing) ? '' : (page_config['rowButtonsOn'] == "1") ? 'checked' : '' @fill['<!--DRILL_DOWN_CHECKED-->'] = (!@isEditing) ? '' : (page_config['drillDownsOn'] == "1") ? 'checked' : '' @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--BUTTON_TEXT-->'] = 'Button Text' @fieldFill['<!--BUTTON_URL-->'] = (!@isEditing) ? '/' : '/' + page_config['desiredController'] + '/' @fieldFill['<!--BUTTON_CLASS-->'] = 'info' @fieldFill['<!--ONBLUR3-->'] = 'GoodClass(this)' @fieldFill['<!--TEXT_DESC-->'] = 'Text' @fieldFill['<!--TEXT_KEY-->'] = 'text' @fieldFill['<!--TEXT_HELP-->'] = 'The Button Text' @fieldFill['<!--URL_DESC-->'] = 'URL' @fieldFill['<!--URL_KEY-->'] = 'url' @fieldFill['<!--URL_HELP->'] = 'URLs include a RESTful path where you will pass controller/field_name/field_name/ where those will be replaced' @fieldFill['<!--COLOR_DESC-->'] = 'Color' @fieldFill['<!--COLOR_KEY-->'] = 'class' @fieldFill['<!--COLOR_HELP-->'] = 'primary=(blue) info=(light-blue) success=(green) danger=(red) disabled=(light grey) default=(grey)' @fieldFill['<!--SUBJECT-->'] = 'buttons' @fill['<!--THE_BUTTON_TEMPLATE-->'] = WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/button_row') ) @fill['<!--ADD_THE_BUTTON_BUTTON-->'] = WidgetList::Widgets::('Add Button To Each Row', {'onclick' => "AddButton();", 'innerClass' => "info" } ) @fill['<!--ALL_BUTTONS-->'] = page_json['buttons'] @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--BUTTON_TEXT-->'] = 'filter_col_name' @fieldFill['<!--BUTTON_URL-->'] = 'col_name' @fieldFill['<!--BUTTON_CLASS-->'] = 'col_name' @fieldFill['<!--ONBLUR2-->'] = 'ReplaceColumnsToLinked(this)' @fieldFill['<!--ONBLUR3-->'] = 'ReplaceColumnsToLinked(this)' @fieldFill['<!--TEXT_DESC-->'] = 'Internal Filter Name (:drill_down_name)<br/>' @fieldFill['<!--TEXT_KEY-->'] = 'drill_down_name' @fieldFill['<!--TEXT_HELP-->'] = ':drill_down_name is a parameter of build_drill_down that is what is passed and returned from get_filter_and_drilldown when you handle the request after clicked' @fieldFill['<!--URL_DESC-->'] = 'Data To Pass From View (:data_to_pass_from_view)<br/>' @fieldFill['<!--URL_KEY-->'] = 'data_to_pass_from_view' @fieldFill['<!--URL_HELP->'] = ':data_to_pass_from_view is the internal/hidden value that is inserted into a hidden <script> id block and passed when clicked' @fieldFill['<!--COLOR_DESC-->'] = 'Column to Show (:column_to_show)<br/>' @fieldFill['<!--COLOR_KEY-->'] = 'column_to_show' @fieldFill['<!--COLOR_HELP-->'] = ':column_to_show should either be the column or possibly a formatted column like CONCAT or COUNT' @fieldFill['<!--SUBJECT-->'] = 'drill_downs' @fill['<!--THE_DRILL_DOWN_TEMPLATE-->'] = WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/button_row') ) @fill['<!--ADD_DRILL_DOWN_BUTTON-->'] = WidgetList::Widgets::('Add New Drill Down', {'onclick' => "AddDrillDown();", 'innerClass' => "success" } ) @fill['<!--ALL_DRILL_DOWNS-->'] = page_json['drill_downs'] # # SEARCH # @fill['<!--SHOW_SEARCH_CHECKED-->'] = (!@isEditing) ? 'checked' : (page_config['showSearch'] == "1") ? 'checked' : '' @fill['<!--SHOW_EXPORT_CHECKED-->'] = (!@isEditing) ? 'checked' : (page_config['showExport'] == "1") ? 'checked' : '' @fill['<!--EXPORT_VALUE-->'] = (!@isEditing) ? default_config['exportButtonTitle'] : page_config['exportButtonTitle'] @fill['<!--USE_RANSACK-->'] = (!@isEditing) ? ($is_mongo) ? '' : 'checked' : (page_config['useRansack'] == "1") ? 'checked' : '' @fill['<!--USE_RANSACK_ADV-->'] = (!@isEditing) ? '' : (page_config['ransackAdvancedForm'] == "1") ? 'checked' : '' @fill['<!--USE_GROUPING-->'] = (!@isEditing) ? '' : (page_config['useGrouping'] == "1") ? 'checked' : '' @fill['<!--SEARCH_TITLE-->'] = (!@isEditing) ? default_config['searchTitle'] : page_config['searchTitle'] @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--FIELD_VALUE-->'] = 'column_name' @fieldFill['<!--FIELD_DESC-->'] = 'User Desc' @fieldFill['<!--SUBJECT-->'] = 'group_by' @fieldFill['<!--FIELD-->'] = 'Field' @fieldFill['<!--DESC-->'] = 'Desc' @fieldFill['<!--DISABLED-->'] = '' @fieldFill['<!--ONBLUR1-->'] = 'InvalidField(this)' @fieldFill['<!--TR_STYLE-->'] = '' @fill['<!--DEFAULT_GROUPING-->'] = WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/field_row') ) @fill['<!--ADD_GROUP_BY_BUTTON-->'] = WidgetList::Widgets::('Add New Group By', {'onclick' => "AddGroupBy();", 'innerClass' => "success" } ) @fill['<!--GROUPING_ITEMS-->'] = (!@isEditing) ? '' : page_json['group_by'] # # FOOTER # @fieldFill = {} @fieldFill['<!--REMOVE_FIELD_BUTTON-->'] = () @fieldFill['<!--BUTTON_TEXT-->'] = 'Button Text' @fieldFill['<!--BUTTON_URL-->'] = (!@isEditing) ? '/' : '/' + page_config['desiredController'] + '/your_action' @fieldFill['<!--BUTTON_CLASS-->'] = 'info' @fieldFill['<!--TEXT_DESC-->'] = 'Text' @fieldFill['<!--TEXT_KEY-->'] = 'text' @fieldFill['<!--TEXT_HELP-->'] = 'The Button Text' @fieldFill['<!--URL_DESC-->'] = 'URL' @fieldFill['<!--URL_KEY-->'] = 'url' @fieldFill['<!--URL_HELP->'] = 'URLs include a RESTful path where you will pass controller/field_name/field_name/ where those will be replaced' @fieldFill['<!--COLOR_DESC-->'] = 'Color' @fieldFill['<!--COLOR_KEY-->'] = 'class' @fieldFill['<!--COLOR_HELP-->'] = 'primary=(blue) info=(light-blue) success=(green) danger=(red) disabled=(light grey) default=(grey)' @fieldFill['<!--SUBJECT-->'] = 'footer_buttons' @fieldFill['<!--ONBLUR3-->'] = 'GoodClass(this)' @fill['<!--FOOTER_BUTTON_TEMPLATE-->'] = WidgetList::Utils::fill(@fieldFill , ac.render_to_string(:partial => 'widget_list/administration/button_row') ) @fill['<!--ADD_THE_FOOTER_BUTTON-->'] = WidgetList::Widgets::('Add Footer Button', {'onclick' => "AddFooterButton();", 'innerClass' => "success" } ) @fill['<!--ALL_FOOTER_BUTTONS-->'] = page_json['footer_buttons'] @fill['<!--FOOTER_CHECKED-->'] = (!@isEditing) ? '' : (page_config['footerOn'] == "1") ? 'checked' : '' @fill['<!--PAGINATION_CHECKED-->'] = (!@isEditing) ? 'checked' : (page_config['showPagination'] == "1") ? 'checked' : '' # # MISC & SUBMIT # @fill['<!--SHOW_CHECKBOX_CHECKED-->'] = (!@isEditing) ? '' : (page_config['checkboxEnabled'] == "1") ? 'checked' : '' @fill['<!--CHECKBOX_SELECTED_FIELDS-->'] = (!@isEditing) ? '' : (page_json['all_fields'], page_config['checkboxField']) @fill['<!--SUBMIT_WIDGET_LIST-->'] = WidgetList::Widgets::('Submit', {'onclick' => "Submit();" , 'innerClass' => "success" } ) # # HELP BUTTONS # @help = {} @help['<!--TITLE_HELP_BUTTON-->'] = "The title list_params will show above the list similar to the title of this page to stub out an implementation of the list." @help['<!--RANSACK_HELP_BUTTON-->'] = "Ransack gem will provide multiple column filtering abilities in the advanced drop down arrow form" @help['<!--SEARCH_TITLE_BUTTON-->'] = "This is the grey description of the wild card search" @help['<!--HIDDEN_HELP_BUTTON-->'] = "Hidden fields are not shown, but you can use the record values inside of important tags passed from buttons and drill downs" @help['<!--CHECK_HELP_BUTTON-->'] = "This value is supposed to be the primary key to identify the row" @help['<!--ACTION_HELP_BUTTON-->'] = "Internal use only reserved for future use. Not really important as of yet" @help['<!--NAME_HELP_BUTTON-->'] = "The name of the controller drives most session level storage and javascript pointers and IDs of a list" @help['<!--ROW_HELP_BUTTON-->'] = "10,20,50,100,500,1000 are supported" @help['<!--CONTROLLER_HELP_BUTTON-->'] = "Controller is used to generate button URLs internally in this utility and as a way to restore configurations for future editing and code re-generation" @help['<!--DRILL_DOWN_HELP_BUTTON-->'] = "Link drill downs allow you to build a link around a field value, in which allows you to select which column value to pass to a drill down. It allows you to CONCAT or run a query for the display of the column and it then handles the filtering of the data" @help['<!--FUNC_HELP_BUTTON-->'] = "A fieldFunction is a wrapper to call functions around columns that exist or possibly adding new fields that dont exist. It is good for formatting data after the where clause." @help['<!--GROUP_BY_HELP_BUTTON-->'] = "Enter a field name to group by and a description to show to the user. If you leave the field name blank it will NOT group by the field, but will show all records" @help['<!--BUTTON_HELP_BUTTON-->'] = "For each record. Add several buttons which will pass tags which are the record values to another page or javascript function" @help['<!--ADV_RANSACK_HELP_BUTTON-->'] = "By default, widget_list will build the advanced form for you when this option is unchecked. By checking, the code builder will place the advanced form inside your controller so you can add additional filtering options you will have to handle on your own" @help.each { |k,v| @fill[k] = WidgetList::Widgets::('?', {'onclick' => "alert('" + v + "')", 'innerClass' => "default" }, true ) } return WidgetList::Utils::fill(@fill , ac.render_to_string(:partial => 'widget_list/administration/output') ) end |
#translate_config_to_code ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 |
# File 'lib/widget_list.rb', line 381 def translate_config_to_code() config_id, page_config = get_configuration() fields,fields_hidden,fields_function,,,group_by,drill_downs,flags,misc = normalize_configs(page_config) drill_down_code = '' case_statements = '' case_statements2 = '' view_code = '' export_code = '' visible_field_code = '' hidden_field_code = '' variable_code = '' checkbox_code = '' = '' grouping_code = '' grouping_code2 = '' search_out = '' field_function_code = '' database_type = WidgetList::List.get_db_type(page_config['primaryDatabase'] == '1' ? true : false) using_grouping = (page_config['useGrouping'] == '1' && page_config['showSearch'] == '1' && !group_by.empty?) #------------ DRILL DOWNS ------------ if page_config['drillDownsOn'] == "1" && !drill_downs.empty? search_out += " # # Search Fields Removed # list_parms['searchFieldsOut'] = {}" drill_downs.each { |field| search_out += " list_parms['searchFieldsOut']#{add_pointer(field[1]['column_to_show'],9)} true" column_to_show = "'#{field[1]['column_to_show'].gsub(/_linked/,'')}'" if using_grouping if database_type == 'oracle' column_to_show = "groupByFilter == 'none' ? '#{escape_code field[1]['column_to_show'].gsub(/_linked/,'')}' : 'MAX(#{escape_code field[1]['column_to_show'].gsub(/_linked/,'')})'" end end field_function_code += " list_parms['fieldFunction']#{add_pointer(field[1]['column_to_show'],7)} WidgetList::List::build_drill_down( :list_id => list_parms['name'], :drill_down_name => '#{escape_code field[0]}', :data_to_pass_from_view => #{column_to_show}, :column_to_show => #{column_to_show}, :column_alias => '#{escape_code field[1]['column_to_show']}', :primary_database => #{page_config['primaryDatabase'] == '1' ? 'true' : 'false'} )" if $is_mongo code = "filterValue" else code = "#{page_config['view']}.sanitize(filterValue)" end case_statements += <<-EOD when '#{field[0]}' list_parms['filter'] << " #{field[1]['column_to_show'].gsub(/_linked/,'')} = ? " list_parms['bindVars'] << #{code} list_parms['listDescription'] = drillDownBackLink + ' Filtered by #{escape_code field[1]['column_to_show'].gsub(/_linked/,'').camelize} (' + filterValue + ')' EOD } drill_down_code = <<-EOD # # Handle Dynamic Filters # drillDown, filterValue = WidgetList::List::get_filter_and_drilldown(list_parms['name']) drillDownBackLink = WidgetList::List::drill_down_back(list_parms['name']) case drillDown#{case_statements} else list_parms['listDescription'] = '#{escape_code page_config['listDescription']}' end EOD else drill_down_code = " list_parms['listDescription'] = '#{escape_code page_config['listDescription']}' " end searchables = flags['searchable'].select {|i| flags['searchable'][i] == '' } unless searchables.empty? if search_out.empty? search_out += " # # Search Fields Removed # list_parms['searchFieldsOut'] = {}" end searchables.each { |val| field_name = val[0] search_out += " list_parms['searchFieldsOut']#{add_pointer(field_name,9)} true" } end summarizables = flags['summarize'].select {|i| flags['summarize'][i] == 'checked' } unless summarizables.empty? search_out += " # # Total Columns # " summarizables.each { |val| field_name = val[0] search_out += " list_parms['totalRow']#{add_pointer(field_name,2)} true" } end sortables = flags['sortable'].select {|i| flags['sortable'][i] == '' } unless sortables.empty? search_out += " # # Remove Sort Links # " sortables.each { |val| field_name = val[0] search_out += " list_parms['columnNoSort']#{add_pointer(field_name,6)} true" } end popupTitles = misc['title'].select {|i| misc['title'][i] != '' } unless popupTitles.empty? search_out += " # # Popup Titles # " popupTitles.each { |val| field_name = val[0] description = val[1] search_out += " list_parms['columnPopupTitle']#{add_pointer(field_name,10)} '#{escape_code description}'" } end widths = misc['width'].select {|i| misc['width'][i] != '' } unless widths.empty? search_out += " # # Column Widths # " widths.each { |val| field_name = val[0] pixels = val[1] add_config = true unless pixels.include?('px') if pixels.to_i == 0 add_config = false end pixels += 'px' end search_out += " list_parms['columnWidth']#{add_pointer(field_name,5)} '#{escape_code pixels}'" if add_config == true } end links = misc['link'].select {|i| misc['link'][i] != '' } unless links.empty? search_out += " # # Column Links # " links.each { |val| field_name = val[0] page_name = val[1] search_out += " list_parms['links']#{add_pointer(field_name,-1)} { 'page' => '#{escape_code page_name}', 'tags' => {'all' => 'all'}} list_parms['columnStyle']#{add_pointer(field_name,5)} 'color:blue;'" } end if page_config['rowButtonsOn'] == '1' variable_code += " button_column_name = '#{escape_code page_config['rowButtonsName']}'" end #------------ VIEW ------------ if page_config['useRansack'] == '1' && page_config['showSearch'] == '1' && $is_mongo == false view_code = " list_parms#{add_pointer('ransackSearch',-10)} #{page_config['view']}.search(#{($_REQUEST.key?('iframe')) ? '$_REQUEST' : 'params'}[:q]) list_parms#{add_pointer('view',-10)} list_parms['ransackSearch'].result " if page_config['ransackAdvancedForm'] == '1' view_code += " list_parms['listSearchForm'] = WidgetList::Utils::fill( { '<!--BUTTON_SEARCH-->' => WidgetList::Widgets::widget_button('Search', WidgetList::List::build_search_button_click(list_parms)), '<!--BUTTON_CLOSE-->' => \"HideAdvancedSearch(this)\" } , ' <!-- Customize your form as well as keep RANSACK tag --> <div id=\"advanced-search-container\"> <div class=\"widget-search-drilldown-close\" onclick=\"<!--BUTTON_CLOSE-->\">X</div> <ul class=\"advanced-search-container-inline\" id=\"search_columns\"> <li> <!--RANSACK--> </li> </ul> <br/> <div style=\"text-align:right;width:100%;height:30px;\" class=\"advanced-search-container-buttons\"><!--BUTTON_RESET--><!--BUTTON_SEARCH--></div> </div> ' " end else view_code = " list_parms#{add_pointer('view',-10)} #{page_config['view']} " end #------------ EXPORT ------------ if page_config['showExport'] == '1' && page_config['showSearch'] == '1' export_code += "list_parms['showExport'] = #{page_config['showExport'] == '1' ? 'true' : 'false'} list_parms['exportButtonTitle'] = '#{escape_code page_config['exportButtonTitle']}'" end if page_config['showSearch'] == '1' export_code += " list_parms['searchTitle'] = '#{escape_code page_config['searchTitle']}'" end #------------ VISIBLE FIELDS ------------ if page_config['checkboxEnabled'] == '1' checkbox_code += " list_parms = WidgetList::List.checkbox_helper(list_parms,'#{page_config['checkboxField']}') " if using_grouping visible_field_code += " list_parms['fields']#{add_pointer('checkbox')} #{add_conditional('checkbox_header',"if groupByFilter == 'none'")}" else visible_field_code += " list_parms['fields']#{add_pointer('checkbox')} 'checkbox_header'" end end fields.each { |field,description| conditional = '' if using_grouping conditional = ' if groupByFilter == \'none\'' if group_by.key?(field) || group_by.key?(field.gsub(/_linked/,'')) conditional = " if groupByFilter == 'none' || groupByFilter == 'group_#{escape_code group_by[field.gsub(/_linked/,'')].gsub(/ /,'_').downcase}'" end end visible_field_code += " list_parms['fields']#{add_pointer(field)} #{add_conditional(description,conditional)}" } #------------ GROUPING ------------ if using_grouping variable_code += " groupByDesc = '' # Initialize a variable you can use in listDescription to show what the current grouping selection is groupByFilter = 'none' # This variable should be used to control business logic based on the grouping and is a short hand key rather than using what is returned from get_group_by_selection " visible_field_code += " list_parms['fields']#{add_pointer('cnt')} #{add_conditional('Count'," if groupByFilter != 'none'")} " if database_type == 'oracle' count = 'TO_CHAR(COUNT(1))' else count = 'COUNT(1)' end field_function_code += " list_parms['fieldFunction']#{add_pointer('cnt',7)} #{add_conditional(count," if groupByFilter != 'none'")}" descriptions = [] group_by.each { |field,description| descriptions << "'" + escape_code(description) + "'" desc = '' filter = '' unless field.empty? desc = " (Grouped By #{escape_code field.camelize})" filter = "group_#{description.gsub(/ /,'_').downcase}" else filter = 'none' end case_statements2 += <<-EOD when '#{escape_code description}' list_parms['groupBy'] = '#{escape_code field}' groupByFilter = '#{escape_code filter}' groupByDesc = '#{escape_code desc}' EOD } grouping_code = <<-EOD # # Group By # groupBy = WidgetList::List::get_group_by_selection(list_parms) case groupBy#{case_statements2} else list_parms['groupBy'] = '' end EOD grouping_code += " list_parms['groupByItems'] = " + '[' + descriptions.join(', ') + ']' grouping_code2 = " # # Prevent Oracle grouping errors # list_parms = WidgetList::List.group_by_max_each_field(list_parms,groupByFilter) " if database_type == 'oracle' end #------------ BUTTONS ------------ if page_config['rowButtonsOn'] == '1' visible_field_code += " list_parms['fields'][button_column_name.downcase] = button_column_name.capitalize" visible_field_code += " if groupByFilter == 'none'" if using_grouping += " # # Buttons # mini_buttons = {} " .each { |field| += " mini_buttons['button_#{escape_code field[0].downcase}'] = {'page' => '#{escape_code field[1]['url']}', 'text' => '#{escape_code field[0]}', 'function' => 'Redirect', 'innerClass' => '#{escape_code field[1]['class']}', 'tags' => {'all'=>'all'} } " } += " list_parms['buttons'] = {button_column_name.downcase => mini_buttons} " end #------------ FOOTER ------------ if page_config['footerOn'] == '1' && !.empty? btns = [] .each {|field| btns << " WidgetList::Widgets::widget_button('#{escape_code field[0]}', {'page' => '#{escape_code field[1]['url']}','innerClass' => '#{escape_code field[1]['class']}'})" } += " list_parms['customFooter'] = " + btns.join(' + ') end #------------ FIELD FUNCTIONS ------------ if page_config['fieldFunctionOn'] == '1' && !fields_function.empty? fields_function.each { |field,command| field_function_code += " list_parms['fieldFunction']#{add_pointer(field,7)} '#{escape_code command}'" } end if page_config['showHidden'] == '1' fields_hidden.each { |field| hidden_field_code += " list_parms['fieldsHidden'] << '#{escape_code field[1]}'" } end if page_config['rowButtonsOn'] == '1' field_function_code += " list_parms['fieldFunction'][button_column_name.downcase] = \"''\"" end if page_config['checkboxEnabled'] == '1' field_function_code += " list_parms['fieldFunction']#{add_pointer('checkbox',7)} \"''\"" end <<-EOD begin #{variable_code} list_parms = WidgetList::List::init_config() list_parms['name'] = '#{escape_code page_config['name']}' list_parms['noDataMessage'] = '#{escape_code page_config['noDataMessage']}' list_parms['rowLimit'] = #{page_config['rowLimit']} list_parms['title'] = '#{escape_code page_config['title']}' list_parms['useSort'] = #{page_config['useSort'] == '1' ? 'true' : 'false'} list_parms['showPagination'] = #{page_config['showPagination'] == '1' ? 'true' : 'false'} list_parms['database'] = '#{page_config['primaryDatabase'] == '1' ? 'primary' : 'secondary'}' #{export_code} #{drill_down_code} #{grouping_code} # # Fields # #{visible_field_code} #{hidden_field_code} #{field_function_code} #{search_out} #{grouping_code2} # # Model # #{view_code} #{checkbox_code} #{} # # Render List # output_type, output = WidgetList::List.build_list(list_parms) case output_type when 'html' @output = output when 'json' return render :inline => output when 'export' send_data(output, :filename => list_parms['name'] + '.csv') return end rescue Exception => e # # Rescue Errors # Rails.logger.info e.to_s + "\\n\\n" + $!.backtrace.join("\\n\\n") if Rails.env == 'development' list_parms['errors'] << '<br/><br/><strong style="color:maroon;">(Ruby Exception - Still attempted to render list with given config ' + list_parms.inspect + ') Exception ==> ' + e.to_s + "<br/><br/>Backtrace:<br/><br/>" + $!.backtrace.join("<br/><br/>") + "</strong>" end output_type, output = WidgetList::List.build_list(list_parms) case output_type when 'html' @output = output when 'json' return render :inline => output when 'export' send_data(output, :filename => list_parms['name'] + '.csv') return end end EOD end |