Skip to content

Instantly share code, notes, and snippets.

@saw
Created April 13, 2010 20:15
Show Gist options
  • Save saw/365033 to your computer and use it in GitHub Desktop.
Save saw/365033 to your computer and use it in GitHub Desktop.
YModules["myshortcutmenus"] = {
init:function(api){
//store the api
this.api = api;
this.Y = api.getService('yui');
},
//called when the view is ready in the dom
onviewload:function(v){
//var moduleId = this.api.getId();
this.api.broadcast('myshortcutsapi', this.api);
var view = this.api.getViewNode(v); //get view node
this.view = view;
if (document.getElementById("myshortcut_add_box_id") != null) {
var myshortcut_add = view.query('#myshortcut_add_box_id');
myshortcut_add.on('click', this.Y.bind(this.myShortcutAddOperation, this));
}
if (document.getElementById("myshortcut_add_below") != null) {
var myshortcut_add = view.query('#myshortcut_add_below');
myshortcut_add.on('click', this.Y.bind(this.myShortcutAddOperation, this));
}
if (document.getElementById("myshortcut_edit_box_id") != null) {
var myshortcut_edit = view.query('#myshortcut_edit_box_id');
myshortcut_edit.on('click', this.Y.bind(this.myShortcutEditOperation, this));
}
if (document.getElementById("myshortcuts_carousel") != null) {
var myshortcut_carousel = view.query('#myshortcuts_carousel');
myshortcut_carousel.on('click', this.Y.bind(this.carouselBoxOperation, this));
}
return true;
},
myShortcutEditOperation:function(e){
document.getElementById('pa-shortcut-add').style.display = 'none';
document.getElementById('u_2588582-collapsed').style.display = 'none';
document.getElementById('yui_3_0_0-2-12670746299261446').style.display = 'block';
document.getElementById('pa-right-shadow-id').style.width = '645px';
document.getElementById('it_over').style.display = 'block';
},
myShortcutAddOperation:function(e){
document.getElementById('shortcut_add_message_box').innerHTML = '';
document.getElementById('pa-shortcut-add').style.display = 'block';
document.getElementById('u_2588582-collapsed').style.display = 'none';
document.getElementById('yui_3_0_0-2-12670746299261446').style.display = 'none';
document.getElementById('pa-right-shadow-id').style.width = '645px';
document.getElementById('it_over').style.display = 'block';
},
carouselBoxOperation:function(e){
e.preventDefault();
var myshortcut_button_id = e.target.get("id");
var itemId = myshortcut_button_id.split("myshortcut_column_button_id_");
if (typeof(itemId[1]) != "undefined") {
itemId = itemId[1];
}
var carousel_li_children = document.getElementById('myshortcuts_carousel').getElementsByTagName('li');
var carousel_li_selected = "myshortcut_column_li_id_"+itemId;
for ( var i = 0; i < carousel_li_children.length; i++ ) {
var childId = carousel_li_children[i].id;
var myshortcut_carousel_li = this.view.query('#'+childId);
if (childId != carousel_li_selected) {
myshortcut_carousel_li.removeClass('y-bg-hilite');
myshortcut_carousel_li.removeClass('selected');
myshortcut_carousel_li.addClass('y-ln-1');
myshortcut_carousel_li.addClass('y-fp-pg-grad');
}
else {
myshortcut_carousel_li.removeClass('y-ln-1');
myshortcut_carousel_li.removeClass('y-fp-pg-grad');
myshortcut_carousel_li.addClass('y-bg-hilite');
myshortcut_carousel_li.addClass('selected');
}
}
var carousel_children = document.getElementById('myshortcuts_carousel').getElementsByTagName('button');
for ( var i = 0; i < carousel_children.length; i++ ) {
var childId = carousel_children[i].id;
if (childId != myshortcut_button_id) {
var myshortcut_carousel_button = this.view.query('#'+childId);
myshortcut_carousel_button.removeClass('y-txt-5');
myshortcut_carousel_button.addClass('y-link-1');
}
else {
e.target.addClass('y-txt-5');
e.target.removeClass('y-link-1');
}
}
var id = myshortcut_button_id.split("myshortcut_column_button_id_");
if (typeof(id[1]) != "undefined") {
//var main_shortcut_div =
var children = document.getElementById('u_2588582-apps-promolist').getElementsByTagName('div');
for ( var i = 0; i < children.length; i++ ) {
var childId = children[i].id;
if (children[i].id != '') {
childId = childId.split("menu_shortcut_list_");
childId = childId[1];
if (typeof(childId) != "undefined") {
if (childId == id[1]) {
document.getElementById(children[i].id).style.display = 'block';
}
else {
document.getElementById(children[i].id).style.display = 'none';
}
}
}
}
}
}
};
YModules["myshortcutedit"] = {
init:function(api){
//store the api
this.api = api;
//api.listen('myshortcutaddapi');
api.listen('myshortcutsapi');
this.Y = api.getService('yui');
api.getService('moduletestplatform').registerModule(this, api);
},
//called when the view is ready in the dom
onviewload:function(v){
//var moduleTestApi = this.api.getModuleApi("myshortcut_add");
//alert(moduleTestApi);
this.makeReadyForReorder(); //Make the edit window for reordering
this.api.broadcast('myshortcuteditapi', this.api);
var view = this.api.getViewNode(v); //get view node
this.view = view;
var msgs = view.query('#shortcut_edit_message_box');
this.msgs = msgs;
this.msgs.set('innerHTML', '');
var editbutton = view.query('form');
editbutton.on('click', this.Y.bind(this.editBoxOperation, this));
var editSubmitButton = view.query('#edit_submit_button_id');
editSubmitButton.on('click', this.Y.bind(this.submitEditBox, this));
var editBoxClose = view.query('#pa-edit-btn-done');
editBoxClose.on('click', this.Y.bind(this.paEditBoxClose, this));
var editCancelButton = view.query('#edit_cancel_button_id');
editCancelButton.on('click', this.Y.bind(this.cancelEditBox, this));
/*if (document.getElementById('set_current_operation').value == 'edit') {
this.myShortcutEditOperation();
}*/
return true;
},
onmessage:function(name, callerType, data){
if (name == 'myshortcutaddapi') {
this.myshortcutaddapi = data;
}
else {
this.myshortcutsapi = data;
}
},
doRefresh:function(e){
this.api.refreshView("dalidefault");
},
makeReadyForReorder: function () {
var rows=30,cols=3,i,j;
for (i=1;i<cols+1;i=i+1) {
new YAHOO.util.DDTarget("edit_shortcut_ul_id_"+i);
}
for (j=1;j<rows+1;j=j+1) {
new YAHOO.example.DDList("shortcut_edit_" + j);
}
},
saveReorderedList: function() {
var reorderStatus = document.getElementById('reordered_status').value;
if (reorderStatus == 'yes') {
var Dom = YAHOO.util.Dom;
var ul1=Dom.get("edit_shortcut_ul_id_1"), ul2=Dom.get("edit_shortcut_ul_id_2"), ul3=Dom.get("edit_shortcut_ul_id_3");
var orderwiseShortcutIds = this.parseList(ul1);
var orderId2 = this.parseList(ul2);
var orderId3 = this.parseList(ul3);
if (orderId2 != '') {
orderwiseShortcutIds += "," + orderId2;
}
if (orderId3 != '') {
orderwiseShortcutIds += "," + orderId3;
}
this.saveReorderedData(orderwiseShortcutIds);
document.getElementById('reordered_status').value = 'no';
return true;
}
return false;
},
saveReorderedData: function(orderwiseShortcutIds) {
var gby_user = document.getElementById('backyard_user').value;
var req = {
url:'http://newlook.yahoo.com/tools/g/pref/prefService.php',
method:'GET',
batchable:id,
data:"action=resort&user_id="+gby_user+"&shlist="+orderwiseShortcutIds
};
var cb = {
success:function(o) {
var response = o.responseText;
responseError = response.search(/errorMessage/i);
if (responseError > 0) {
alert("Reorder operation failed");
}
else {
this.myshortcutsapi.refreshView("dalidefault");
}
},
failure:function(o){
alert("Reorder operation failed");
}
};
cb.scope = this;
//cb.argument = id;
var id = this.api.makeRequest(req, cb);
this.lastRequest = id;
},
parseList: function(ul) {
var items = ul.getElementsByTagName("li");
var out = '', undo_button_id, shortcutId;
var undo_status = true;
for (j=0;j<items.length;j++) {
shortcutId = items[j].getAttribute("name");
if (shortcutId != null && shortcutId != 0) {
undo_button_id = "undoid_"+shortcutId;
undo_status = true;
if (document.getElementById(undo_button_id) != null) {
var undo_status_style = document.getElementById(undo_button_id).style.display;
if (undo_status_style != 'block') {
undo_status = false;
}
}
if (undo_status != 'false') {
if (out != '') {
out += ",";
}
out += shortcutId;
}
}
}
return out;
},
paEditBoxClose:function(v){
//this.myshortcutaddapi.refreshView("dalidefault");
//this.saveReorderedList();
document.getElementById('pa-shortcut-add').style.display = 'none';
document.getElementById('u_2588582-collapsed').style.display = 'block';
document.getElementById('yui_3_0_0-2-12670746299261446').style.display = 'none';
document.getElementById('it_over').style.display = 'none';
document.getElementById('pa-right-shadow-id').style.width = '195px';
this.api.refreshView("dalidefault");
},
editBoxOperation:function(e){
e.preventDefault();
var myshortcut_button_id = e.target.get("id");
var checkOperationId = myshortcut_button_id.split("deleteid_");
if (typeof(checkOperationId[1]) != "undefined") {
myshortcut_button_id = checkOperationId[1];
this.deleteMyshortcut(e, myshortcut_button_id);
}
else {
checkOperationId = myshortcut_button_id.split("undoid_");
if (typeof(checkOperationId[1]) != "undefined") {
myshortcut_button_id = checkOperationId[1];
this.undoOperation(e, myshortcut_button_id);
}
else {
var a_tag_id = 'shortcut_edit_a_'+myshortcut_button_id;
var a_tag_url = document.getElementById(a_tag_id).href;
var a_div_id = 'shortcut_edit_div_'+myshortcut_button_id;
var a_tag_label = document.getElementById(a_div_id).innerHTML;
document.getElementById('my_shortcut_edit_form_id').value = myshortcut_button_id;
document.getElementById('my_shortcut_edit_form_label').value = a_tag_label;
document.getElementById('my_shortcut_edit_form_url').value = a_tag_url;
document.getElementById('my_shortcut_edit_box_form').style.display = 'block';
}
}
},
submitEditBox:function(e){
e.preventDefault();
var url_data = this.view.query('#my_shortcut_edit_form_url').get('value').toString();
var label = this.view.query('#my_shortcut_edit_form_label').get('value').toString();
var id = this.view.query('#my_shortcut_edit_form_id').get('value').toString();
if (this.isValidEditUrl(url_data) == false) {
this.successMessage("InvalidURL");
}
else {
this.editMyshortcut(id, label, url_data);
}
},
isValidEditUrl:function(url) {
var v = new RegExp();
v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
if (!v.test(url)) {
return false;
}
return true;
},
cancelEditBox:function(e){
e.preventDefault();
document.getElementById('my_shortcut_edit_box_form').style.display = 'none';
},
editMyshortcut:function(id, label, url_data){
var gby_user = document.getElementById('backyard_user').value;
var req = {
url:'http://newlook.yahoo.com/tools/g/pref/prefService.php',
method:'GET',
batchable:id,
data:"action=edit&user_id="+gby_user+"&url="+url_data+"&desc="+label+"&shortcut_id="+id
};
var cb = {
success:function(o){
var response = o.responseText;
//responseError = response.substr(0,5);
responseError = response.search(/errorMessage/i);
if (responseError > 0) {
this.successMessage("Invalid");
}
else {
//document.getElementById('set_current_operation').value = 'edit';//Dummy variable to check the operation after module refresh
this.myshortcutsapi.refreshView("dalidefault");
//this.api.refreshView("dalidefault");
this.operationAfterEditBoxSubmit();
}
},
failure:function(o){
alert("Fails");
this.operationAfterEditBoxSubmit();
}
};
cb.scope = this;
cb.argument = id;
var id = this.api.makeRequest(req, cb);
this.lastRequest = id;
},
operationAfterEditBoxSubmit:function(){
/* Start -> Update from edit form values to edit box links */
var myshortcut_button_id = document.getElementById('my_shortcut_edit_form_id').value;
var a_tag_label = document.getElementById('my_shortcut_edit_form_label').value;
var a_tag_url = document.getElementById('my_shortcut_edit_form_url').value;
var a_tag_id = 'shortcut_edit_a_'+myshortcut_button_id;
var temp_tag_label = a_tag_label;
document.getElementById(a_tag_id).href = a_tag_url;
var a_div_id = 'shortcut_edit_div_'+myshortcut_button_id;
document.getElementById(a_div_id).innerHTML = temp_tag_label;
var a_span_id = 'shortcut_span_div_'+myshortcut_button_id;
var short_label = a_tag_label.substr(0,15);
document.getElementById(a_span_id).innerHTML = short_label;
/* Ends -> Update from edit form values to edit box links */
document.getElementById('my_shortcut_edit_box_form').style.display = 'none';
document.getElementById('yui_3_0_0-2-12670746299261446').style.display = 'block';
//document.getElementById('pa-right-shadow-id').style.width = '645px'
//document.getElementById('it_over').style.display = 'none';
document.getElementById('do_refresh_edit_view').value = 1; //Edit box changed and need a view refresh
},
undoAfterDelete:function(shortcut_id){
var delete_button_id = "deleteid_"+shortcut_id;
var undo_button_id = "undoid_"+shortcut_id;
var edit_button = document.getElementById(shortcut_id);
if (edit_button) {
document.getElementById(shortcut_id).style.display = 'none';
}
document.getElementById(delete_button_id).style.display = 'none';
document.getElementById(undo_button_id).style.display = 'block';
document.getElementById('do_refresh_edit_view').value = 1; //Edit box changed and need a view refresh
},
setupAfterUndo:function(shortcut_id){
var delete_button_id = "deleteid_"+shortcut_id;
var undo_button_id = "undoid_"+shortcut_id;
var edit_button = document.getElementById(shortcut_id);
if (edit_button != null) {
document.getElementById(shortcut_id).style.display = 'block';
}
document.getElementById(delete_button_id).style.display = 'block';
document.getElementById(undo_button_id).style.display = 'none';
document.getElementById('do_refresh_edit_view').value = 1; //Edit box changed and need a view refresh
},
deleteMyshortcut:function(e, id){
e.preventDefault();
var gby_user = document.getElementById('backyard_user').value;
var req = {
url:'http://newlook.yahoo.com/tools/g/pref/prefService.php',
method:'GET',
batchable:true,
data:"action=unsubscribe&shortcut_id="+id+"&user_id="+gby_user
};
var cb = {
success:function(o){
//this.api.refreshView("dalidefault");
this.undoAfterDelete(o.argument);
this.myshortcutsapi.refreshView("dalidefault");
//this.operationAfterEditBoxSubmit();
},
failure:function(o){
alert("Fails");
this.operationAfterEditBoxSubmit();
}
};
cb.scope = this;
cb.argument = id;
var id = this.api.makeRequest(req, cb);
this.lastRequest = id;
},
undoOperation:function(e, id){
e.preventDefault();
var gby_user = document.getElementById('backyard_user').value;
var req = {
url:'http://newlook.yahoo.com/tools/g/pref/prefService.php',
method:'GET',
batchable:true,
data:"action=subscribe&shortcut_id="+id+"&user_id="+gby_user
};
var cb = {
success:function(o){
this.setupAfterUndo(o.argument);
this.myshortcutsapi.refreshView("dalidefault");
},
failure:function(o){
alert("Fails");
this.operationAfterEditBoxSubmit();
}
};
cb.scope = this;
cb.argument = id;
var id = this.api.makeRequest(req, cb);
this.lastRequest = id;
},
successMessage:function(messageType){
var message = '';
if (messageType == "Invalid") {
message = "<font color='red'>This is a Invalid Entry</font>";
}
else if (messageType == "InvalidURL") {
message = "<font color='red'>Enter Valid URL</font>";
}
var quote = this.msgs.create('<p style="background-color:#FCEFC7;outline-color:#FFCC33; padding:5px;">'+message+'</p>');
this.msgs.set('innerHTML', '');
this.msgs.appendChild(quote);
}
};
YModules["patop"] = {
init:function(api){
//store the api
this.api = api;
this.Y = api.getService('yui');
api.listen('myshortcuteditapi');
api.listen('myshortcutaddapi');
},
onviewload:function(v){
var view = this.api.getViewNode(v); //get view node
//this.api.broadcast('paboxclosebuttonapi', 'this.api');
var myshortcut_top_cancel= view.query('#pa_top_cancel');
myshortcut_top_cancel.on('click', this.Y.bind(this.paOperations, this));
return true;
},
onmessage:function(name, callerType, data){
if (name == 'myshortcuteditapi') {
this.myshortcuteditapi = data;
}
else {
this.myshortcutaddapi = data;
}
},
paOperations:function(v){
//this.myshortcuteditapi.saveReorderedList();
var do_need_edit_view_refresh = document.getElementById('do_refresh_edit_view').value;
var is_edit_view_open = document.getElementById('yui_3_0_0-2-12670746299261446').style.display;
if (do_need_edit_view_refresh == 1 && is_edit_view_open == 'block') {
//If edit box is going to close, then refresh that view
this.myshortcuteditapi.refreshView("dalidefault");
this.myshortcutaddapi.refreshView("dalidefault");
document.getElementById('do_refresh_edit_view').value = 0; //Edit box view is refreshed
}
document.getElementById('pa-shortcut-add').style.display = 'none';
document.getElementById('u_2588582-collapsed').style.display = 'block';
document.getElementById('yui_3_0_0-2-12670746299261446').style.display = 'none';
document.getElementById('it_over').style.display = 'none';
document.getElementById('pa-right-shadow-id').style.width = '195px';
}
};
YModules["myshortcutadd"] = {
init:function(api){
//store the api
this.api = api;
api.listen('myshortcutsapi');
api.listen('myshortcuteditapi');
},
onmessage:function(name, callerType, data){
if (name == 'myshortcuteditapi') {
this.myshortcuteditapi = data;
}
else {
this.myshortcutsapi = data;
}
},
onviewload:function(v){
this.invokeImageIconCarousel();
var view = this.api.getViewNode(v);
this.view = view;
var Y = this.api.getService('yui');
this.api.broadcast('myshortcutaddapi', this.api);
var msgs = view.query('.shortcut_add_message_box');
this.msgs = msgs;
var addForm = view.query('#my_shortcut_add');
addForm.on('submit', Y.bind(this.handleSub, this));
var galleryForm = view.query('#shortcut_gallery');
galleryForm.on('click', Y.bind(this.addGalleryOperation, this));
var galleryClose = view.query('#pa-btn-done');
galleryClose.on('click', Y.bind(this.paBoxClose, this));
},
invokeImageIconCarousel:function(){
(function () {
// Get the image link from within its (parent) container.
function getImage(parent) {
var el = parent.firstChild;
while (el) { // walk through till as long as there's an element
if (el.nodeName.toUpperCase() == "IMG") { // found an image
// flickr uses "_s" suffix for small, and "_m" for big
// images respectively
return el.src.replace(/_s\.jpg$/, "_m.jpg");
}
el = el.nextSibling;
}
return "";
}
YAHOO.util.Event.onDOMReady(function (ev) {
var spotlight = YAHOO.util.Dom.get("spotlight_image_icons"),
carousel = new YAHOO.widget.Carousel("container_image_icons");
carousel.on("itemSelected", function (index) {
// item has the reference to the Carousel's item
var item = carousel.getElementForItem(index);
if (item) {
spotlight.innerHTML = "<img id='image_icon_id' src=\""+getImage(item)+"\">";
}
});
carousel.set("scrollIncrement", 8);
carousel.set("numVisible" , 8);
carousel.set("numPages" , 1);
carousel.render(); // get ready for rendering the widget
carousel.show(); // display the widget
});
})();
},
handleSub:function(e){
e.preventDefault();
var view = this.view;
var url_data = view.query('#u_2588582-pa-auto-url').get('value').toString();
var label = view.query('#u_2588582-pa-auto-label').get('value').toString();
var image_icon_url = view.query('#image_icon_id').get('src').toString();
var image_icon = image_icon_url.split("http://");
image_icon_url = image_icon[1];
image_icon = image_icon_url.split("/");
image_icon = image_icon[image_icon.length - 1];
if (this.isValidUrl(url_data) == false) {
this.successMessage("Invalid");
document.getElementById('u_2588582-pa-auto-url').value = 'Enter a URL';
return false;
}
this.messageTitle = label;
var totalListItems = this.validateListAccodation();
if (totalListItems < 10) {
this.addMyshortcut(label, url_data, image_icon);
}
else {
alert("Sorry, we were unable to save your changes \n You will need to remove a shortcut from your list before you can add another.");
}
return true;
},
isValidUrl:function(url) {
var v = new RegExp();
v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
if (!v.test(url)) {
return false;
}
return true;
},
paBoxClose:function(v){
document.getElementById('pa-shortcut-add').style.display = 'none';
document.getElementById('u_2588582-collapsed').style.display = 'block';
document.getElementById('yui_3_0_0-2-12670746299261446').style.display = 'none';
document.getElementById('it_over').style.display = 'none';
document.getElementById('pa-right-shadow-id').style.width = '195px';
},
addGalleryOperation:function(e) {
e.preventDefault();
var myshortcut_button_id = e.target.get("id");
var checkOperationId = myshortcut_button_id.split("shortcut_gallery_delete_id_");
if (typeof(checkOperationId[1]) != "undefined") {
myshortcut_button_id = checkOperationId[1];
this.unSubscribeMyshortcut(e, myshortcut_button_id);
}
else {
checkOperationId = myshortcut_button_id.split("shortcut_gallery_add_id_");
if (typeof(checkOperationId[1]) != "undefined") {
myshortcut_button_id = checkOperationId[1];
var totalListItems = this.validateListAccodation();
if (totalListItems < 10) {
this.subscribeMyshortcut(e, myshortcut_button_id);
}
else {
alert("Sorry, we were unable to save your changes \n You will need to remove a shortcut from your list before you can add another.");
}
}
}
},
validateListAccodation:function() {
var Dom = YAHOO.util.Dom;
var ul = Dom.get("edit_shortcut_ul_id_3"), getCountOfList = 0;
if (ul == null) {
return getCountOfList;
}
var items = ul.getElementsByTagName("li");
var undo_button_id, shortcutId;
for (i = 0; i < items.length;i = i + 1) {
shortcutId = items[i].getAttribute("name");
if (shortcutId != 0) {
undo_button_id = "undoid_"+shortcutId;
if (document.getElementById(undo_button_id).style.display != 'block') {
getCountOfList++;
}
}
}
return getCountOfList;
},
addMyshortcut:function(label, url_data, image_icon){
var gby_user = document.getElementById('backyard_user').value;
var req = {
url:'http://newlook.yahoo.com/tools/g/pref/prefService.php',
method:'GET',
batchable: true,
data:"action=add&user_id="+gby_user+"&url="+url_data+"&desc="+label+"&icon="+image_icon+"&type=U"
};
var cb = {
success:function(o){
var s = o.argument;
var response = o.responseText;
responseError = response.substr(0,5);
if (responseError == 'Error') {
this.successMessage("Duplicate");
}
else {
this.successMessage("Success");
this.myshortcuteditapi.refreshView("dalidefault");
this.myshortcutsapi.refreshView("dalidefault");
}
},
failure:function(o){
this.successMessage("Fails");
}
};
var q = label;
cb.scope = this;
var id = this.api.makeRequest(req, cb);
this.lastRequest = id;
},
unSubscribeMyshortcut:function(e, id){
e.preventDefault();
var gby_user = document.getElementById('backyard_user').value;
var req = {
url:'http://newlook.yahoo.com/tools/g/pref/prefService.php',
method:'GET',
batchable:true,
data:"action=unsubscribe&shortcut_id="+id+"&user_id="+gby_user
};
var cb = {
success:function(o){
this.changeGalleryStatus(o.argument, 'subscribe');
this.myshortcuteditapi.refreshView("dalidefault");
this.myshortcutsapi.refreshView("dalidefault");
},
failure:function(o){
alert("Fails");
}
};
cb.scope = this;
cb.argument = id;
var id = this.api.makeRequest(req, cb);
this.lastRequest = id;
},
subscribeMyshortcut:function(e, id){
e.preventDefault();
var gby_user = document.getElementById('backyard_user').value;
var req = {
url:'http://newlook.yahoo.com/tools/g/pref/prefService.php',
method:'GET',
batchable:true,
data:"action=subscribe&shortcut_id="+id+"&user_id="+gby_user
};
var cb = {
success:function(o){
this.changeGalleryStatus(o.argument, 'unsubscribe');
this.myshortcuteditapi.refreshView("dalidefault");
this.myshortcutsapi.refreshView("dalidefault");
},
failure:function(o){
alert("Fails");
}
};
cb.scope = this;
cb.argument = id;
var id = this.api.makeRequest(req, cb);
this.lastRequest = id;
},
changeGalleryStatus:function(id, type) {
var gallery_div_id = "shortcut_gallery_div_id_"+id;
var gallery_div = this.view.query('#'+gallery_div_id);
if (type == 'subscribe') {
var add_gallery_button_id = "shortcut_gallery_add_id_"+id;
var newChild = gallery_div.create('<a class="pa-add pa-add-app-btn small" href="#"> <b class="y-glbl-universal-grad"> <em class="y-glbl-universal" id="'+add_gallery_button_id+'"> Add <span class="hide-offscreen">'+add_gallery_button_id+'</span> </em></b></a>');
gallery_div.set('innerHTML', '');
gallery_div.appendChild(newChild);
}
else if(type == 'unsubscribe') {
var delete_button_id = "shortcut_gallery_delete_id_"+id;
var newChild = gallery_div.create('<a class="y-glbl-universal small pa-add-app-remove pa-remove" href="#" id='+delete_button_id+'>Remove <span class="hide-offscreen">'+delete_button_id+'</span> </a>');
gallery_div.set('innerHTML', '');
gallery_div.appendChild(newChild);
}
},
successMessage:function(messageType){
var message = '';
if (messageType == "Success") {
message = "<font color='#000000'>"+this.messageTitle+" has been successfully added to your shortcuts</font>";
}
else if (messageType == "Invalid") {
message = "<font color='red'>Please enter a valid URL</font>";
}
else if (messageType == "Duplicate") {
message = "<font color='red'>This is a Duplicate Entry</font>";
}
else {
message = "<font color='red'>"+this.messageTitle+" has Failed to add in your shortcuts</font>";
}
var quote = this.msgs.create('<p style="background-color:#FCEFC7;outline-color:#FFCC33; padding:5px;">'+message+'</p>');
this.msgs.set('innerHTML', '');
this.msgs.appendChild(quote);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment