def get_action_html(my): search_key = SearchKey.get_by_sobject(my.sobjects[0], use_id=True) search_type = my.sobjects[0].get_base_search_type() div = DivWdg(css='centered') # construct the bvr element_names = my.element_names[:] for element_name in my.skipped_element_names: element_names.remove(element_name) bvr = { 'type': 'click_up', 'mode': my.mode, 'element_names': element_names, 'search_key': search_key, 'input_prefix': my.input_prefix, 'view': my.view } if my.mode == 'insert': bvr['refresh'] = 'true' # for adding parent relationship in EditCmd if my.parent_key: bvr['parent_key'] = my.parent_key hidden_div = DivWdg() hidden_div.add_style("display: none") div.add(hidden_div) hidden = TextAreaWdg("__data__") hidden_div.add(hidden) hidden.set_value( jsondumps(bvr) ) show_action = my.kwargs.get("show_action") if show_action in [False, 'false']: return div div.add_styles('height: 35px; margin-top: 5px;') div.add_named_listener('close_EditWdg', ''' var popup = spt.popup.get_popup( $('edit_popup') ); if (popup != null) { spt.popup.destroy(popup); } ''') # custom callbacks cbjs_cancel = my.kwargs.get('cbjs_cancel') if not cbjs_cancel: cbjs_cancel = ''' spt.named_events.fire_event('preclose_edit_popup', {}); spt.named_events.fire_event('close_EditWdg', {}) ''' # custom callbacks cbjs_insert_path = my.kwargs.get('cbjs_%s_path' % my.mode) cbjs_insert = None if cbjs_insert_path: script_obj = CustomScript.get_by_path(cbjs_insert_path) if script_obj: cbjs_insert = script_obj.get_value("script") # get it inline if not cbjs_insert: cbjs_insert = my.kwargs.get('cbjs_%s' % my.mode) # use a default if not cbjs_insert: mode_label = my.mode.capitalize() cbjs_insert = ''' spt.app_busy.show("%sing items", ""); spt.edit.edit_form_cbk(evt, bvr); spt.app_busy.hide(); '''%mode_label save_event = my.kwargs.get('save_event') if not save_event: save_event = div.get_unique_event("save") bvr['save_event'] = save_event bvr['named_event'] = 'edit_pressed' bvr['cbjs_action'] = cbjs_insert ok_btn_label = my.mode.capitalize() if ok_btn_label == 'Edit': ok_btn_label = 'Save' if ok_btn_label == 'Insert': ok_btn_label = 'Add' if my.kwargs.get('ok_btn_label'): ok_btn_label = my.kwargs.get('ok_btn_label') ok_btn_tip = ok_btn_label if my.kwargs.get('ok_btn_tip'): ok_btn_tip = my.kwargs.get('ok_btn_tip') cancel_btn_label = 'Cancel' if my.kwargs.get('cancel_btn_label'): cancel_btn_label = my.kwargs.get('cancel_btn_label') cancel_btn_tip = cancel_btn_label if my.kwargs.get('cancel_btn_tip'): cancel_btn_tip = my.kwargs.get('cancel_btn_tip') # create the buttons insert_button = ActionButtonWdg(title=ok_btn_label, tip=ok_btn_tip) insert_button.add_behavior(bvr) cancel_button = ActionButtonWdg(title=cancel_btn_label, tip=cancel_btn_tip) cancel_button.add_behavior({ 'type': 'click_up', 'cbjs_action': cbjs_cancel }) table = Table() table.add_style("margin-left: auto") table.add_style("margin-right: auto") table.add_style("margin-top: 15px") table.add_style("margin-bottom: 15px") table.add_row() table.add_cell(insert_button) table.add_cell(cancel_button) div.add(table) #div.add(SpanWdg(edit, css='med')) #div.add(SpanWdg(edit_close, css='med')) #div.add(SpanWdg(cancel, css='med')) return div
def get_action_html(my): search_key = SearchKey.get_by_sobject(my.sobjects[0]) search_type = my.sobjects[0].get_base_search_type() div = DivWdg(css='centered') div.add_behavior( { 'type': 'load', 'cbjs_action': my.get_onload_js() } ) div.add_styles('height: 35px; margin-top: 10px;') div.add_named_listener('close_EditWdg', ''' var popup = bvr.src_el.getParent( ".spt_popup" ); if (popup) spt.popup.close(popup); ''') # custom callbacks cbjs_cancel = my.kwargs.get('cbjs_cancel') if not cbjs_cancel: cbjs_cancel = ''' spt.named_events.fire_event('preclose_edit_popup', {}); spt.named_events.fire_event('close_EditWdg', {}) ''' # custom callbacks cbjs_insert_path = my.kwargs.get('cbjs_%s_path' % my.mode) cbjs_insert = None if cbjs_insert_path: script_obj = CustomScript.get_by_path(cbjs_insert_path) cbjs_insert = script_obj.get_value("script") cbjs_insert = cbjs_insert.replace("'", '"') # get it inline if not cbjs_insert: cbjs_insert = my.kwargs.get('cbjs_%s' % my.mode) # use a default if not cbjs_insert: cbjs_insert = ''' spt.edit.edit_form_cbk(evt, bvr); ''' element_names = my.element_names[:] for element_name in my.skipped_element_names: element_names.remove(element_name) # Must not have postaction which closes the EditWdg before upload finishes from tactic.ui.widget import TextBtnWdg, TextBtnSetWdg bvr = { 'cbjs_action': cbjs_insert, 'named_event': 'close_EditWdg', 'element_names': element_names, 'search_key': search_key, 'input_prefix': my.input_prefix, 'view': my.view } keys = WebContainer.get_web().get_form_keys() for key in keys: bvr[key] = WebContainer.get_web().get_form_value(key) label = my.mode if label == 'edit': label = 'save' buttons_list = [ { 'label': label.capitalize(), 'tip': label.capitalize(), 'bvr': bvr }, { 'label': 'Cancel', 'tip': 'Cancel', 'bvr': { 'cbjs_action': cbjs_cancel } } ] buttons = TextBtnSetWdg( align="center", buttons=buttons_list, spacing=10, size='large', side_padding=4 ) div.add(buttons) return div
def add_layout_behaviors(my, layout_wdg): border_color = layout_wdg.get_color('border', modifier=20) layout_wdg.add_behavior( { 'type': 'smart_drag', 'bvr_match_class': 'spt_tile_checkbox', 'drag_el': 'drag_ghost_copy', 'use_copy': 'true', 'use_delta': 'true', 'border_color': border_color, 'dx': 10, 'dy': 10, 'drop_code': 'DROP_ROW', 'accepted_search_type' : my.search_type, # don't use cbjs_pre_motion_setup as it assumes the drag el 'copy_styles': 'z-index: 1000; opacity: 0.7; border: solid 1px %s; text-align: left; padding: 10px; width: 0px; background: %s' \ % (layout_wdg.get_color("border"), layout_wdg.get_color("background")), 'cbjs_setup': ''' if(spt.drop) {spt.drop.sobject_drop_setup( evt, bvr );} ''', "cbjs_motion": ''' spt.mouse._smart_default_drag_motion(evt, bvr, mouse_411); var target_el = spt.get_event_target(evt); target_el = spt.mouse.check_parent(target_el, bvr.drop_code); if (target_el) { var orig_border_color = target_el.getStyle('border-color'); var orig_border_style = target_el.getStyle('border-style'); target_el.setStyle('border','dashed 2px ' + bvr.border_color); if (!target_el.getAttribute('orig_border_color')) { target_el.setAttribute('orig_border_color', orig_border_color); target_el.setAttribute('orig_border_style', orig_border_style); } } ''', "cbjs_action": ''' if (spt.drop) { spt.drop.sobject_drop_action(evt, bvr); } ''' } ) detail_element_names = my.kwargs.get("detail_element_names") layout_wdg.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_tile_detail', 'detail_element_names': detail_element_names, 'cbjs_action': ''' spt.tab.set_main_body_tab(); var top = bvr.src_el.getParent(".spt_tile_top"); var search_key = top.getAttribute("spt_search_key"); var name = top.getAttribute("spt_name"); var search_code = top.getAttribute("spt_search_code"); var class_name = 'tactic.ui.tools.SObjectDetailWdg'; var kwargs = { search_key: search_key, tab_element_names: bvr.detail_element_names }; spt.tab.add_new(search_code, name, class_name, kwargs); ''' } ) mode = my.kwargs.get("expand_mode") if not mode: mode = "gallery" gallery_width = my.kwargs.get("gallery_width") if not gallery_width: gallery_width = '' if mode == "view": layout_wdg.add_relay_behavior( { 'type': 'click', 'bvr_match_class': 'spt_tile_content', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_tile_top"); var search_key = top.getAttribute("spt_search_key"); var server = TacticServerStub.get(); var snapshot = server.get_snapshot(search_key, {context: "", process:"publish",include_web_paths_dict:true}); if (snapshot.__search_key__) { window.open(snapshot.__web_paths_dict__.main); } else { var snapshot = server.get_snapshot(search_key, {context: "",include_web_paths_dict:true}); if (snapshot.__search_key__) { window.open(snapshot.__web_paths_dict__.main); } else { alert("WARNING: No file for this asset"); } } ''' } ) elif mode == "detail": tab_element_names = my.kwargs.get("tab_element_names") layout_wdg.add_relay_behavior( { 'type': 'click', 'bvr_match_class': 'spt_tile_content', 'tab_element_names': tab_element_names, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_tile_top"); var search_key = top.getAttribute("spt_search_key"); spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.tools.SObjectDetailWdg'; var kwargs = { search_key: search_key, tab_element_names: bvr.tab_element_names, }; spt.tab.add_new(search_key, "Detail []", class_name, kwargs); ''' } ) elif mode == "gallery": gallery_div = DivWdg() layout_wdg.add( gallery_div ) gallery_div.add_class("spt_tile_gallery") layout_wdg.add_relay_behavior( { 'type': 'click', 'width': gallery_width, 'bvr_match_class': 'spt_tile_content', 'cbjs_action': ''' var layout = bvr.src_el.getParent(".spt_layout"); var tile_tops = layout.getElements(".spt_tile_top"); var search_keys = []; for (var i = 0; i < tile_tops.length; i++) { var tile_top = tile_tops[i]; var search_key = tile_top.getAttribute("spt_search_key_v2"); search_keys.push(search_key); } var tile_top = bvr.src_el.getParent(".spt_tile_top"); var search_key = tile_top.getAttribute("spt_search_key_v2"); var class_name = 'tactic.ui.widget.gallery_wdg.GalleryWdg'; var kwargs = { search_keys: search_keys, search_key: search_key, }; if (bvr.width) kwargs['width'] = bvr.width; var gallery_el = layout.getElement(".spt_tile_gallery"); spt.panel.load(gallery_el, class_name, kwargs); ''' } ) elif mode == "custom": script_path = my.kwargs.get("script_path") script = None if script_path: script_obj = CustomScript.get_by_path(script_path) script = script_obj.get_value("script") if not script: script = my.kwargs.get("script") if not script: script = ''' alert("Script path [%s] not implemented"); ''' % script_path layout_wdg.add_relay_behavior( { 'type': 'click', 'bvr_match_class': 'spt_tile_content', 'cbjs_action': script } ) bg1 = layout_wdg.get_color("background3") bg2 = layout_wdg.get_color("background3", 5) layout_wdg.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_tile_top', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "0.8"); var el = bvr.src_el.getElement(".spt_tile_title"); if (el) el.setStyle("background", "%s"); ''' % bg2 } ) layout_wdg.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_tile_top', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); var el = bvr.src_el.getElement(".spt_tile_title"); if (el) el.setStyle("background", "%s"); ''' % bg1 } ) process = my.kwargs.get("process") if not process: process = "publish" if my.parent_key: search_type = None else: search_type = my.search_type border_color = layout_wdg.get_color('border', modifier=20) layout_wdg.add_behavior( { 'type': 'load', 'search_type': search_type, 'search_key': my.parent_key, 'process': process, 'border_color': border_color, 'cbjs_action': ''' spt.thumb = {}; spt.thumb.background_enter = function(evt, el) { evt.preventDefault(); el.setStyle('border','2px dashed ' + bvr.border_color); } spt.thumb.background_leave = function(evt, el) { evt.preventDefault(); el.setStyle('border','none'); } spt.thumb.background_drop = function(evt, el) { //evt.stopPropagation(); //evt.preventDefault(); el.setStyle('border','none'); var top = $(el); var server = TacticServerStub.get(); evt.dataTransfer.dropEffect = 'copy'; var files = evt.dataTransfer.files; evt.stopPropagation(); evt.preventDefault(); var filenames = []; for (var i = 0; i < files.length; i++) { var file = files[i]; filenames.push(file.name); } var yes = function() { spt.app_busy.show("Attaching file"); for (var i = 0; i < files.length; i++) { var size = files[i].size; var file = files[i]; var filename = file.name; var search_key; var data = { name: filename } if (bvr.search_key) { search_key = bvr.search_key } else { var search_type = bvr.search_type; var item = server.insert(search_type, data); search_key = item.__search_key__; } var context = bvr.process + "/" + filename; var upload_file_kwargs = { files: [files[i]], upload_complete: function() { var server = TacticServerStub.get(); var kwargs = {mode: 'uploaded'}; server.simple_checkin( search_key, context, filename, kwargs); var layout = el.getParent(".spt_layout"); spt.table.set_layout(layout); spt.table.run_search(); } }; spt.html5upload.upload_file(upload_file_kwargs); // just support one file at the moment break; } spt.app_busy.hide(); } spt.confirm('Check in [' + filenames[0] + '] for a new item?', yes) } spt.thumb.noop_enter = function(evt, el) { evt.preventDefault(); el.setStyle('border','2px dashed ' + bvr.border_color); } spt.thumb.noop_leave = function(evt, el) { evt.preventDefault(); el.setStyle('border','none'); } spt.thumb.noop = function(evt, el) { evt.dataTransfer.dropEffect = 'copy'; var files = evt.dataTransfer.files; evt.stopPropagation(); evt.preventDefault(); el.setStyle('border','none'); var top = $(el); var thumb_el = top.getElement(".spt_thumb_top"); var filenames = []; for (var i = 0; i < files.length; i++) { var file = files[i]; filenames.push(file.name); } var search_key = top.getAttribute("spt_search_key"); var yes = function() { for (var i = 0; i < files.length; i++) { var size = files[i].size; var file = files[i]; setTimeout( function() { var loadingImage = loadImage( file, function (img) { thumb_el.innerHTML = ""; thumb_el.appendChild(img); }, {maxWidth: 240, canvas: true, contain: true} ); }, 0 ); var filename = file.name; var context = "publish" + "/" + filename; var upload_file_kwargs = { files: files, upload_complete: function() { var server = TacticServerStub.get(); var kwargs = {mode: 'uploaded'}; server.simple_checkin( search_key, context, filename, kwargs); } }; spt.html5upload.upload_file(upload_file_kwargs); } spt.notify.show_message("Check-in completed for " + search_key); } spt.confirm('Check in [' + filenames + '] for '+ search_key + '?', yes) } ''' } ) border = layout_wdg.get_color("border") layout_wdg.add_relay_behavior( { 'type': 'mouseup', 'border': border, 'bvr_match_class': 'spt_tile_select', 'cbjs_action': ''' if (evt.shift == true) { spt.table.set_table(bvr.src_el); var row = bvr.src_el.getParent(".spt_table_row"); var rows = spt.table.get_all_rows(true); var last_selected = spt.table.last_selected_row; var last_index = -1; var cur_index = -1; for (var i = 0; i < rows.length; i++) { if (rows[i] == last_selected) { last_index = i; } if (rows[i] == row) { cur_index = i; } if (cur_index != -1 && last_index != -1) { break; } } var start_index; var end_index; if (last_index < cur_index) { start_index = last_index; end_index = cur_index; } else { start_index = cur_index; end_index = last_index; } var select = last_selected.hasClass("spt_table_selected"); for (var i = start_index; i < end_index+1; i++) { var row = rows[i]; var checkbox = row.getElement(".spt_tile_checkbox"); if (select) { checkbox.checked = true; row.removeClass("spt_table_selected"); spt.table.select_row(row); row.setStyle("box-shadow", "0px 0px 15px #FF0"); } else { checkbox.checked = false; row.addClass("spt_table_selected"); spt.table.unselect_row(row); row.setStyle("box-shadow", "0px 0px 15px rgba(0,0,0,0.5)"); } } } else { var row = bvr.src_el.getParent(".spt_table_row"); var checkbox = bvr.src_el.getElement(".spt_tile_checkbox"); if (checkbox.checked == true) { checkbox.checked = false; row.removeClass("spt_table_selected"); spt.table.unselect_row(row); row.setStyle("box-shadow", "0px 0px 15px rgba(0,0,0,0.5)"); } else { checkbox.checked = true; row.addClass("spt_table_selected"); spt.table.select_row(row); row.setStyle("box-shadow", "0px 0px 15px #FF0"); } } ''' } ) layout_wdg.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_tile_checkbox', 'cbjs_action': ''' if (bvr.src_el.checked) { bvr.src_el.checked = false; } else { bvr.src_el.checked = true; } evt.stopPropagation(); ''' } )
def add_layout_behaviors(my, layout_wdg): border_color = layout_wdg.get_color('border', modifier=20) layout_wdg.add_behavior( { 'type': 'smart_drag', 'bvr_match_class': 'spt_tile_checkbox', 'drag_el': 'drag_ghost_copy', 'use_copy': 'true', 'use_delta': 'true', 'border_color': border_color, 'dx': 10, 'dy': 10, 'drop_code': 'DROP_ROW', # don't use cbjs_pre_motion_setup as it assumes the drag el 'copy_styles': 'z-index: 1000; opacity: 0.7; border: solid 1px %s; text-align: left; padding: 10px; width: 0px; background: %s' \ % (layout_wdg.get_color("border"), layout_wdg.get_color("background")), 'cbjs_setup': ''' if(spt.drop) {spt.drop.sobject_drop_setup( evt, bvr );} ''', "cbjs_motion": ''' spt.mouse._smart_default_drag_motion(evt, bvr, mouse_411); var target_el = spt.get_event_target(evt); target_el = spt.mouse.check_parent(target_el, bvr.drop_code); if (target_el) { var orig_border_color = target_el.getStyle('border-color'); var orig_border_style = target_el.getStyle('border-style'); target_el.setStyle('border','dashed 2px ' + bvr.border_color); if (!target_el.getAttribute('orig_border_color')) { target_el.setAttribute('orig_border_color', orig_border_color); target_el.setAttribute('orig_border_style', orig_border_style); } } ''', "cbjs_action": ''' if (spt.drop) { spt.drop.sobject_drop_action(evt, bvr); } ''' } ) detail_element_names = my.kwargs.get("detail_element_names") layout_wdg.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_tile_detail', 'detail_element_names': detail_element_names, 'cbjs_action': ''' spt.tab.set_main_body_tab(); var top = bvr.src_el.getParent(".spt_tile_top"); var search_key = top.getAttribute("spt_search_key"); var name = top.getAttribute("spt_name"); var search_code = top.getAttribute("spt_search_code"); var class_name = 'tactic.ui.tools.SObjectDetailWdg'; var kwargs = { search_key: search_key, tab_element_names: bvr.detail_element_names }; spt.tab.add_new(search_code, name, class_name, kwargs); ''' } ) mode = my.kwargs.get("expand_mode") if not mode: mode = "gallery" gallery_width = my.kwargs.get("gallery_width") if not gallery_width: gallery_width = '' if mode == "view": layout_wdg.add_relay_behavior( { 'type': 'click', 'bvr_match_class': 'spt_tile_content', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_tile_top"); var search_key = top.getAttribute("spt_search_key"); var server = TacticServerStub.get(); var snapshot = server.get_snapshot(search_key, {context: "", process:"publish",include_web_paths_dict:true}); if (snapshot.__search_key__) { window.open(snapshot.__web_paths_dict__.main); } else { var snapshot = server.get_snapshot(search_key, {context: "",include_web_paths_dict:true}); if (snapshot.__search_key__) { window.open(snapshot.__web_paths_dict__.main); } else { alert("WARNING: No file for this asset"); } } ''' } ) elif mode == "detail": tab_element_names = my.kwargs.get("tab_element_names") layout_wdg.add_relay_behavior( { 'type': 'click', 'bvr_match_class': 'spt_tile_content', 'tab_element_names': tab_element_names, 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_tile_top"); var search_key = top.getAttribute("spt_search_key"); spt.tab.set_main_body_tab(); var class_name = 'tactic.ui.tools.SObjectDetailWdg'; var kwargs = { search_key: search_key, tab_element_names: bvr.tab_element_names, }; spt.tab.add_new(search_key, "Detail []", class_name, kwargs); ''' } ) elif mode == "gallery": gallery_div = DivWdg() layout_wdg.add( gallery_div ) gallery_div.add_class("spt_tile_gallery") layout_wdg.add_relay_behavior( { 'type': 'click', 'width': gallery_width, 'bvr_match_class': 'spt_tile_content', 'cbjs_action': ''' var layout = bvr.src_el.getParent(".spt_layout"); var tile_tops = layout.getElements(".spt_tile_top"); var search_keys = []; for (var i = 0; i < tile_tops.length; i++) { var tile_top = tile_tops[i]; var search_key = tile_top.getAttribute("spt_search_key_v2"); search_keys.push(search_key); } var tile_top = bvr.src_el.getParent(".spt_tile_top"); var search_key = tile_top.getAttribute("spt_search_key_v2"); var class_name = 'tactic.ui.widget.gallery_wdg.GalleryWdg'; var kwargs = { search_keys: search_keys, search_key: search_key, }; if (bvr.width) kwargs['width'] = bvr.width; var gallery_el = layout.getElement(".spt_tile_gallery"); spt.panel.load(gallery_el, class_name, kwargs); ''' } ) elif mode == "custom": script_path = my.kwargs.get("script_path") script = None if script_path: script_obj = CustomScript.get_by_path(script_path) script = script_obj.get_value("script") if not script: script = my.kwargs.get("script") if not script: script = ''' alert("Script path [%s] not implemented"); ''' % script_path layout_wdg.add_relay_behavior( { 'type': 'click', 'bvr_match_class': 'spt_tile_content', 'cbjs_action': script } ) bg1 = layout_wdg.get_color("background3") bg2 = layout_wdg.get_color("background3", 5) layout_wdg.add_relay_behavior( { 'type': 'mouseover', 'bvr_match_class': 'spt_tile_top', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "0.8"); var el = bvr.src_el.getElement(".spt_tile_title"); if (el) el.setStyle("background", "%s"); ''' % bg2 } ) layout_wdg.add_relay_behavior( { 'type': 'mouseout', 'bvr_match_class': 'spt_tile_top', 'cbjs_action': ''' bvr.src_el.setStyle("opacity", "1.0"); var el = bvr.src_el.getElement(".spt_tile_title"); if (el) el.setStyle("background", "%s"); ''' % bg1 } ) process = my.kwargs.get("process") if not process: process = "publish" if my.parent_key: search_type = None else: search_type = my.search_type layout_wdg.add_behavior( { 'type': 'load', 'search_type': search_type, 'search_key': my.parent_key, 'process': process, 'cbjs_action': ''' spt.thumb = {}; spt.thumb.background_drop = function(evt, el) { evt.stopPropagation(); evt.preventDefault(); var top = $(el); var server = TacticServerStub.get(); evt.dataTransfer.dropEffect = 'copy'; var files = evt.dataTransfer.files; evt.stopPropagation(); evt.preventDefault(); spt.app_busy.show("Attaching file"); for (var i = 0; i < files.length; i++) { var size = files[i].size; var file = files[i]; var filename = file.name; var search_key; var data = { name: filename } if (bvr.search_key) { search_key = bvr.search_key } else { var search_type = bvr.search_type; var item = server.insert(search_type, data); search_key = item.__search_key__; } var context = bvr.process + "/" + filename; var upload_file_kwargs = { files: [files[i]], upload_complete: function() { var server = TacticServerStub.get(); var kwargs = {mode: 'uploaded'}; server.simple_checkin( search_key, context, filename, kwargs); var layout = el.getParent(".spt_layout"); spt.table.set_layout(layout); spt.table.run_search(); } }; spt.html5upload.upload_file(upload_file_kwargs); // just support one file at the moment break; } spt.app_busy.hide(); } spt.thumb.noop = function(evt, el) { evt.dataTransfer.dropEffect = 'copy'; var files = evt.dataTransfer.files; evt.stopPropagation(); evt.preventDefault(); var top = $(el); var thumb_el = top.getElement(".spt_thumb_top"); for (var i = 0; i < files.length; i++) { var size = files[i].size; var file = files[i]; setTimeout( function() { var loadingImage = loadImage( file, function (img) { thumb_el.innerHTML = ""; thumb_el.appendChild(img); }, {maxWidth: 240, canvas: true, contain: true} ); }, 0 ); var search_key = top.getAttribute("spt_search_key"); var filename = file.name; var context = "publish" + "/" + filename; var upload_file_kwargs = { files: files, upload_complete: function() { var server = TacticServerStub.get(); var kwargs = {mode: 'uploaded'}; server.simple_checkin( search_key, context, filename, kwargs); } }; spt.html5upload.upload_file(upload_file_kwargs); } } ''' } ) border = layout_wdg.get_color("border") layout_wdg.add_relay_behavior( { 'type': 'mouseup', 'border': border, 'bvr_match_class': 'spt_tile_select', 'cbjs_action': ''' if (evt.shift == true) { spt.table.set_table(bvr.src_el); var row = bvr.src_el.getParent(".spt_table_row"); var rows = spt.table.get_all_rows(true); var last_selected = spt.table.last_selected_row; var last_index = -1; var cur_index = -1; for (var i = 0; i < rows.length; i++) { if (rows[i] == last_selected) { last_index = i; } if (rows[i] == row) { cur_index = i; } if (cur_index != -1 && last_index != -1) { break; } } var start_index; var end_index; if (last_index < cur_index) { start_index = last_index; end_index = cur_index; } else { start_index = cur_index; end_index = last_index; } var select = last_selected.hasClass("spt_table_selected"); for (var i = start_index; i < end_index+1; i++) { var row = rows[i]; var checkbox = row.getElement(".spt_tile_checkbox"); if (select) { checkbox.checked = true; row.removeClass("spt_table_selected"); spt.table.select_row(row); row.setStyle("box-shadow", "0px 0px 15px #FF0"); } else { checkbox.checked = false; row.addClass("spt_table_selected"); spt.table.unselect_row(row); row.setStyle("box-shadow", "0px 0px 15px rgba(0,0,0,0.5)"); } } } else { var row = bvr.src_el.getParent(".spt_table_row"); var checkbox = bvr.src_el.getElement(".spt_tile_checkbox"); if (checkbox.checked == true) { checkbox.checked = false; row.removeClass("spt_table_selected"); spt.table.unselect_row(row); row.setStyle("box-shadow", "0px 0px 15px rgba(0,0,0,0.5)"); } else { checkbox.checked = true; row.addClass("spt_table_selected"); spt.table.select_row(row); row.setStyle("box-shadow", "0px 0px 15px #FF0"); } } ''' } ) layout_wdg.add_relay_behavior( { 'type': 'mouseup', 'bvr_match_class': 'spt_tile_checkbox', 'cbjs_action': ''' if (bvr.src_el.checked) { bvr.src_el.checked = false; } else { bvr.src_el.checked = true; } evt.stopPropagation(); ''' } )